diff options
author | Luke Karrys <luke@lukekarrys.com> | 2022-04-14 00:24:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 00:24:17 +0300 |
commit | b5701cc2ad82fbc7a8bde47756afa874b916871a (patch) | |
tree | e1e151158edc5ef6b6f46173c38ffec3c195f832 /.github | |
parent | ac9c2a64a5826cd6bac54a91cdcc6c3455185b1f (diff) |
chore: consolidate and refactor benchmark workflows (#4715)
Diffstat (limited to '.github')
-rw-r--r-- | .github/workflows/benchmark-comment.yml | 87 | ||||
-rw-r--r-- | .github/workflows/benchmark.yml | 101 |
2 files changed, 62 insertions, 126 deletions
diff --git a/.github/workflows/benchmark-comment.yml b/.github/workflows/benchmark-comment.yml deleted file mode 100644 index 285b29384..000000000 --- a/.github/workflows/benchmark-comment.yml +++ /dev/null @@ -1,87 +0,0 @@ ---- -name: Benchmark CLI - Comment - -on: - issue_comment: - types: [created, edited] - -jobs: - comment-handler: - name: Trigger Benchmarks - - runs-on: ubuntu-latest - - steps: - - name: Handle Incoming Comment - env: - DISPATCH_REPO: "benchmarks" - DISPATCH_OWNER: "npm" - EVENT_NAME: ${{ github.event_name }} - OWNER: ${{ github.event.repository.owner.login }} - REPO: ${{ github.event.repository.name }} - ISSUE_NUMBER: ${{ github.event.issue.number }} - COMMENT_NODE_ID: ${{ github.event.comment.node_id }} - COMMENT_ACTIONABLE: ${{ startsWith(github.event.comment.body, 'test this please ✅') }} - AUTH_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }} - run: | - # Comment Handler - - # Creates an exit early condition if there are errors - # Exit early if `jq` is not present - set -e - jq --version - - # Figure out if comment came from pull-request or issue - IS_PR=$(curl -s https://api.github.com/repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER} | jq -cr '.pull_request.url') - - if [ "${IS_PR}" != "null" ]; then - echo "Comment from pull/${ISSUE_NUMBER}." - - # It is a pull-request; check comment body for correct phrase - if [ "${COMMENT_ACTIONABLE}" == "true" ]; then - # Fetch pull-request information - PR_DATA=$(curl -s "${IS_PR}") - PR_OWNER=$(echo "${PR_DATA}" | jq '.head.repo.owner.login') - PR_REPO=$(echo "${PR_DATA}" | jq '.head.repo.name') - - # dispatch request for benchmarks - echo "Dispatching request..." - curl \ - -s \ - -X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${AUTH_TOKEN}" \ - -d \ - ' - { - "event_type": "'"${EVENT_NAME} ${PR_OWNER}/${PR_REPO}#${ISSUE_NUMBER}"'", - "client_payload": { - "pr_id": "'"${ISSUE_NUMBER}"'", - "repo": "'"${PR_REPO}"'", - "owner": "'"${PR_OWNER}"'" - } - }' - - # Create reaction on comment to confirm dispatch was sent - curl \ - -s \ - -X POST https://api.github.com/graphql \ - -H "Content-Type: application/json" \ - -H "Authorization: token ${AUTH_TOKEN}" \ - -d \ - ' - { - "query": "mutation($inputData:AddReactionInput!) { addReaction(input:$inputData) { reaction { content } } }", - "variables": { - "inputData": { - "subjectId": "'"${COMMENT_NODE_ID}"'", - "content": "ROCKET" - } - } - }' - else - echo "Comment not actionable." - fi - else - echo "Comment not from pull-request." - fi diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b9da2ddfd..c97619e1e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,52 +1,75 @@ ---- -name: Benchmark Suite +name: Benchmark - CLI on: pull_request: branches: - - "**" + - '*' + issue_comment: + types: + - created + - edited jobs: - build: - name: Trigger Benchmarks - + pull-request: runs-on: ubuntu-latest - steps: - - name: Handle Incoming Pull-Request + - name: Incoming Pull Request + if: | + secrets.NPM_BENCHMARKS_TOKEN && ( + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && github.event.issue.pull_request && + startsWith(github.event.comment.body, 'test this please ✅'))) env: - DISPATCH_REPO: "benchmarks" - DISPATCH_OWNER: "npm" - EVENT_NAME: ${{ github.event_name }} - REPO: ${{ github.event.repository.name }} - PR_NUMBER: ${{ github.event.pull_request.number }} - PR_OWNER: ${{ github.event.pull_request.head.repo.owner.login }} - AUTH_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }} + # gh cli uses these env vars for owner/repo/token + GH_REPO: "npm/benchmarks" + GITHUB_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }} run: | - # Dispatch Handler - - dispatch_request () { - echo "Dispatching request..." - curl \ - -s \ - -X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${AUTH_TOKEN}" \ - -d \ - ' - { - "event_type": "'"${EVENT_NAME} ${PR_OWNER}/${REPO}#${PR_NUMBER}"'", - "client_payload": { - "pr_id": "'"${PR_NUMBER}"'", - "repo": "'"${REPO}"'", - "owner": "'"${PR_OWNER}"'" - } - }' - } + EVENT_NAME="${{ github.event_name }}" + OWNER="${{ github.event.repository.owner.login }}" + REPO="${{ github.event.repository.name }}" - if [ "${AUTH_TOKEN}" != "" ]; then - # Dispatch request for benchmarks - dispatch_request + if [[ "$EVENT_NAME" == "pull_request" ]]; then + PR="${{ github.event.pull_request.number }}" else - echo "NO AUTH - FORK PULL REQUEST" + PR="${{ github.event.issue.number }}" fi + + EVENT="${EVENT_NAME} ${OWNER}/${REPO}#${PR}" + echo '{ + "event_type": "'"$EVENT"'", + "client_payload": { + "pr_id": "'"$PR"'", + "repo": "'"$REPO"'", + "owner": "'"$OWNER"'" + } + }' | gh api repos/{owner}/{repo}/dispatches --input - + + comment: + runs-on: ubuntu-latest + steps: + - name: Incoming Comment + if: | + secrets.NPM_BENCHMARKS_TOKEN && + github.event_name == 'issue_comment' && + github.event.issue.pull_request && + startsWith(github.event.comment.body, 'test this please ✅') + env: + # gh cli uses this env var as the token + GITHUB_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }} + run: | + COMMENT_NODE_ID="${{ github.event.comment.node_id }}" + QUERY='mutation ($inputData:AddReactionInput!) { + addReaction (input:$inputData) { + reaction { content } + } + }' + echo '{ + "query": "'${QUERY}'", + "variables": { + "inputData": { + "subjectId": "'"${COMMENT_NODE_ID}"'", + "content": "ROCKET" + } + } + }' | gh api graphql --input - + |