forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (61 loc) · 2.1 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
---
name: Benchmark Suite
on:
push:
branches:
- "latest"
pull_request:
branches:
- "**"
jobs:
build:
name: Trigger Benchmarks
runs-on: ubuntu-latest
steps:
- name: Handle Incoming Pull-Request
env:
DISPATCH_REPO: "benchmarks"
DISPATCH_OWNER: "npm"
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
REPO: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_OWNER: ${{ github.event.pull_request.head.repo.owner.login }}
PR_COMMITS_URL: ${{ github.event.pull_request.commits_url }}
PR_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
AUTH_TOKEN: ${{ secrets.NPM_DEPLOY_USER_PAT }}
run: |
# Dispatch Handler
dispatch_request () {
echo "Dispatching request..."
REF_SHA=$1
curl \
-s \
-X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${AUTH_TOKEN}" \
-d \
'
{
"event_type": "'"${EVENT_NAME}"'",
"client_payload": {
"pr_id": "'"${PR_NUMBER}"'",
"repo": "'"${REPO}"'",
"owner": "'"${PR_OWNER}"'",
"commit_sha": "'"${REF_SHA}"'"
}
}'
}
if [ "${AUTH_TOKEN}" != "" ]; then
if [ "${EVENT_ACTION}" == "opened" ]; then
# Fetch the head commit sha, since it doesn't exist in the body of this event
COMMIT_SHA=$(curl -s "${PR_COMMITS_URL}" | jq -r '.[0].sha')
# Dispatch request for benchmarks
dispatch_request "${COMMIT_SHA}"
else
# Dispatch request for benchmarks
dispatch_request "${PR_COMMIT_SHA}"
fi
else
echo "NO AUTH - FORK PULL REQUEST"
fi