Skip to content

Commit 0c00d9c

Browse files
committed
chore: fix variable name in benchmark trigger
1 parent db34bba commit 0c00d9c

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

.github/workflows/benchmark.yml

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,58 @@ jobs:
2727
# gh cli uses these env vars for owner/repo/token
2828
GH_REPO: "npm/benchmarks"
2929
GITHUB_TOKEN: ${{ secrets.BENCHMARK_DISPATCH_TOKEN }}
30-
run: |
31-
EVENT_NAME="${{ github.event_name }}"
32-
OWNER="${{ github.event.repository.owner.login }}"
33-
REPO="${{ github.event.repository.name }}"
34-
PR=""
35-
36-
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
41-
PR="${{ github.event.pull_request.number }}"
42-
else
43-
PR="${{ github.event.issue.number }}"
44-
SENDER="${{ github.event.comment.user.login }}"
45-
ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission')
46-
47-
if [[ "$ROLE" != "admin" ]]; then
48-
echo "${SENDER} is ${ROLE}, not an admin, exiting"
49-
exit 0
50-
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-
}
30+
uses: actions/github-script@v6
31+
with:
32+
script: |
33+
const {
34+
payload,
35+
eventName,
36+
repo: { owner, repo },
37+
issue: { number },
38+
} = context
39+
40+
if (eventName === 'pull_request' && !process.env.GITHUB_TOKEN) {
41+
console.log('No GITHUB_TOKEN - from fork pull request, exiting')
42+
return
43+
}
44+
45+
if (eventName === 'issue_comment') {
46+
const res = await github.rest.repos.getCollaboratorPermissionLevel({
47+
owner,
48+
repo,
49+
username: payload.comment.user.login,
50+
})
51+
if (res.data.permission !== 'admin') {
52+
console.log(`Commenter is not an admin, exiting`)
53+
return
6754
}
68-
}' | gh api graphql --input -
69-
fi
70-
71-
EVENT="${EVENT_NAME} ${OWNER}/${REPO}#${PR}"
72-
echo '{
73-
"event_type": "'"$EVENT"'",
74-
"client_payload": {
75-
"pr_id": "'"$PR"'",
76-
"repo": "'"$REPO"'",
77-
"owner": "'"$OWNER"'"
55+
56+
// add emoji to comment if user is an admin to signal benchmark is running
57+
await github.rest.reactions.createForIssueComment({
58+
owner,
59+
repo,
60+
comment_id: payload.comment.node_id,
61+
content: 'rocket',
62+
})
7863
}
79-
}' | gh api repos/{owner}/{repo}/dispatches --input -
64+
65+
const pullRequest = payload.pull_request || await github.rest.pulls.get({
66+
owner,
67+
repo,
68+
pull_number: number,
69+
}).then(r => r.data)
70+
71+
const matchesRelease = pullRequest.base.ref.match(/^release\/v(\d+)$/)
72+
const targetSpec = matchesRelease ? matchesRelease[1] : 'latest'
73+
74+
await github.rest.repos.createDispatchEvent({
75+
owner,
76+
repo,
77+
event_type: `"${eventName} ${owner}/${repo}#${number}"`,
78+
client_payload: {
79+
owner,
80+
repo,
81+
pr_id: number,
82+
target_spec: targetSpec,
83+
},
84+
})

0 commit comments

Comments
 (0)