Skip to content

Commit

Permalink
chore: merge benchmark action to single job (#4970)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored Jun 1, 2022
1 parent d60cfbc commit 0c2d2e0
Showing 1 changed file with 26 additions and 47 deletions.
73 changes: 26 additions & 47 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- edited

jobs:
pull-request:
trigger-benchmark:
runs-on: ubuntu-latest
steps:
- name: Incoming Pull Request
Expand All @@ -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}"
Expand All @@ -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 -

0 comments on commit 0c2d2e0

Please sign in to comment.