1212 - edited
1313
1414jobs :
15- pull-request :
15+ trigger-benchmark :
1616 runs-on : ubuntu-latest
1717 steps :
1818 - name : Incoming Pull Request
@@ -21,33 +21,51 @@ jobs:
2121 github.event_name == 'issue_comment' &&
2222 github.event.issue.pull_request &&
2323 github.event.issue.state == 'open' &&
24- startsWith(github.event.comment.body, '@npm-robot benchmark this')
24+ startsWith(github.event.comment.body, '@npm-cli-bot benchmark this')
2525 )
2626 env :
2727 # gh cli uses these env vars for owner/repo/token
2828 GH_REPO : " npm/benchmarks"
2929 GITHUB_TOKEN : ${{ secrets.BENCHMARK_DISPATCH_TOKEN }}
3030 run : |
31- if [[ "$GITHUB_TOKEN" == "" ]]; then
32- echo "No auth - from fork pull request, exiting"
33- exit 0
34- fi
35-
3631 EVENT_NAME="${{ github.event_name }}"
3732 OWNER="${{ github.event.repository.owner.login }}"
3833 REPO="${{ github.event.repository.name }}"
3934 PR=""
4035
4136 if [[ "$EVENT_NAME" == "pull_request" ]]; then
37+ if [[ "$GITHUB_TOKEN" == "" ]]; then
38+ echo "No auth - from fork pull request, exiting"
39+ exit 0
40+ fi
4241 PR="${{ github.event.pull_request.number }}"
4342 else
4443 PR="${{ github.event.issue.number }}"
45- SENDER="${{ github.event.issue.sender .login }}"
44+ SENDER="${{ github.event.comment.user .login }}"
4645 ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission')
46+
4747 if [[ "$ROLE" != "admin" ]]; then
4848 echo "${SENDER} is ${ROLE}, not an admin, exiting"
4949 exit 0
5050 fi
51+
52+ # add emoji to comment if user is an admin to signal
53+ # benchmark is running
54+ COMMENT_NODE_ID="${{ github.event.comment.node_id }}"
55+ QUERY='mutation ($inputData:AddReactionInput!) {
56+ addReaction (input:$inputData) {
57+ reaction { content }
58+ }
59+ }'
60+ echo '{
61+ "query": "'${QUERY}'",
62+ "variables": {
63+ "inputData": {
64+ "subjectId": "'"${COMMENT_NODE_ID}"'",
65+ "content": "ROCKET"
66+ }
67+ }
68+ }' | gh api graphql --input -
5169 fi
5270
5371 EVENT="${EVENT_NAME} ${OWNER}/${REPO}#${PR}"
5977 "owner": "'"$OWNER"'"
6078 }
6179 }' | gh api repos/{owner}/{repo}/dispatches --input -
62-
63- comment :
64- runs-on : ubuntu-latest
65- steps :
66- - name : Incoming Comment
67- if : |
68- github.event_name == 'issue_comment' &&
69- github.event.issue.pull_request &&
70- github.event.issue.state == 'open' &&
71- startsWith(github.event.comment.body, '@npm-cli-bot benchmark this')
72- env :
73- # gh cli uses this env var as the token
74- GITHUB_TOKEN : ${{ secrets.BENCHMARK_DISPATCH_TOKEN }}
75- run : |
76- OWNER="${{ github.event.repository.owner.login }}"
77- REPO="${{ github.event.repository.name }}"
78- SENDER="${{ github.event.issue.sender.login }}"
79- ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission')
80- if [[ "$ROLE" != "admin"]]; then
81- echo "${SENDER} is ${ROLE}, not an admin, exiting"
82- exit 0
83- fi
84-
85- COMMENT_NODE_ID="${{ github.event.comment.node_id }}"
86- QUERY='mutation ($inputData:AddReactionInput!) {
87- addReaction (input:$inputData) {
88- reaction { content }
89- }
90- }'
91- echo '{
92- "query": "'${QUERY}'",
93- "variables": {
94- "inputData": {
95- "subjectId": "'"${COMMENT_NODE_ID}"'",
96- "content": "ROCKET"
97- }
98- }
99- }' | gh api graphql --input -
100-
0 commit comments