-
Notifications
You must be signed in to change notification settings - Fork 2.9k
100 lines (92 loc) · 3.19 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Benchmark - CLI
on:
pull_request:
branches:
- '*'
paths:
- lib/**
issue_comment:
types:
- created
- edited
jobs:
pull-request:
runs-on: ubuntu-latest
steps:
- name: Incoming Pull Request
if: |
github.event_name == 'pull_request' || (
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.issue.state == 'open' &&
startsWith(github.event.comment.body, '@npm-robot benchmark this')
)
env:
# gh cli uses these env vars for owner/repo/token
GH_REPO: "npm/benchmarks"
GITHUB_TOKEN: ${{ secrets.BENCHMARKS_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
PR="${{ github.event.pull_request.number }}"
else
PR="${{ github.event.issue.number }}"
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
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: |
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.NPM_BENCHMARKS_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 -