From 0c2d2e084fa7119147957b09f7e7a06a05b70781 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 1 Jun 2022 12:41:43 -0700 Subject: [PATCH] chore: merge benchmark action to single job (#4970) --- .github/workflows/benchmark.yml | 73 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 7dcba88d9052b..018eeae7e4974 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -12,7 +12,7 @@ on: - edited jobs: - pull-request: + trigger-benchmark: runs-on: ubuntu-latest steps: - name: Incoming Pull Request @@ -21,33 +21,51 @@ jobs: github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.issue.state == 'open' && - startsWith(github.event.comment.body, '@npm-robot benchmark this') + startsWith(github.event.comment.body, '@npm-cli-bot benchmark this') ) env: # gh cli uses these env vars for owner/repo/token GH_REPO: "npm/benchmarks" GITHUB_TOKEN: ${{ secrets.BENCHMARK_DISPATCH_TOKEN }} run: | - if [[ "$GITHUB_TOKEN" == "" ]]; then - echo "No auth - from fork pull request, exiting" - exit 0 - fi - EVENT_NAME="${{ github.event_name }}" OWNER="${{ github.event.repository.owner.login }}" REPO="${{ github.event.repository.name }}" PR="" if [[ "$EVENT_NAME" == "pull_request" ]]; then + if [[ "$GITHUB_TOKEN" == "" ]]; then + echo "No auth - from fork pull request, exiting" + exit 0 + fi PR="${{ github.event.pull_request.number }}" else PR="${{ github.event.issue.number }}" - SENDER="${{ github.event.issue.sender.login }}" + SENDER="${{ github.event.comment.user.login }}" ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission') + if [[ "$ROLE" != "admin" ]]; then echo "${SENDER} is ${ROLE}, not an admin, exiting" exit 0 fi + + # add emoji to comment if user is an admin to signal + # benchmark is running + 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 - fi EVENT="${EVENT_NAME} ${OWNER}/${REPO}#${PR}" @@ -59,42 +77,3 @@ jobs: "owner": "'"$OWNER"'" } }' | gh api repos/{owner}/{repo}/dispatches --input - - - comment: - runs-on: ubuntu-latest - steps: - - name: Incoming Comment - if: | - github.event_name == 'issue_comment' && - github.event.issue.pull_request && - github.event.issue.state == 'open' && - startsWith(github.event.comment.body, '@npm-cli-bot benchmark this') - env: - # gh cli uses this env var as the token - GITHUB_TOKEN: ${{ secrets.BENCHMARK_DISPATCH_TOKEN }} - run: | - OWNER="${{ github.event.repository.owner.login }}" - REPO="${{ github.event.repository.name }}" - SENDER="${{ github.event.issue.sender.login }}" - ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission') - if [[ "$ROLE" != "admin"]]; then - echo "${SENDER} is ${ROLE}, not an admin, exiting" - exit 0 - fi - - 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 - -