@@ -16,33 +16,53 @@ jobs:
1616    runs-on : ubuntu-latest 
1717
1818    steps :
19-       #  Checkout the npm/cli repo
20-       - uses : actions/checkout@v2 
21- 
22-       #  Installs the specific version of nodejs
23-       - name : Use nodejs 12.x 
24-         uses : actions/setup-node@v1 
25-         with :
26-           node-version : " 12.x" 
27- 
28-       #  Trigger Webhook
29-       - name : Trigger Webhook 
19+       - name : Handle Incoming Pull-Request 
3020        env :
3121          DISPATCH_REPO : " benchmarks" 
3222          DISPATCH_OWNER : " npm" 
23+           EVENT_NAME : ${{ github.event_name }} 
24+           EVENT_ACTION : ${{ github.event.action }} 
25+           REPO : ${{ github.event.repository.name }} 
26+           PR_NUMBER : ${{ github.event.pull_request.number }} 
27+           PR_OWNER : ${{ github.event.pull_request.head.repo.owner.login }} 
28+           PR_COMMITS_URL : ${{ github.event.pull_request.commits_url }} 
29+           PR_COMMIT_SHA : ${{ github.event.pull_request.head.sha }} 
30+           AUTH_TOKEN : ${{ secrets.NPM_DEPLOY_USER_PAT }} 
3331        run : | 
34-           curl \ 
35-             -s \ 
36-             -X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \ 
37-             -H "Accept: application/vnd.github.everest-preview+json" \ 
38-             -d \ 
39-             ' 
40-             { 
41-               "event_type": "${{ github.event_name }}", 
42-               "client_payload": { 
43-                 "pr_id": "${{ github.event.pull_request.number }}", 
44-                 "repo": "${{ github.event.repository.name }}", 
45-                 "owner": "${{ github.event.repository.owner.login }}", 
46-                 "commit_sha": "${{ github.event.after }}" 
47-               } 
48-             }' 
32+           # Dispatch Handler 
33+ 
34+           dispatch_request () { 
35+             echo "Dispatching request..." 
36+             REF_SHA=$1 
37+             curl \ 
38+               -s \ 
39+               -X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \ 
40+               -H "Accept: application/vnd.github.everest-preview+json" \ 
41+               -H "Authorization: token ${AUTH_TOKEN}" \ 
42+               -d \ 
43+               ' 
44+               { 
45+                 "event_type": "'"${EVENT_NAME}"'", 
46+                 "client_payload": { 
47+                   "pr_id": "'"${PR_NUMBER}"'", 
48+                   "repo": "'"${REPO}"'", 
49+                   "owner": "'"${PR_OWNER}"'", 
50+                   "commit_sha": "'"${REF_SHA}"'" 
51+                 } 
52+               }' 
53+           } 
54+ 
55+           if [ "${AUTH_TOKEN}" != "" ]; then 
56+             if [ "${EVENT_ACTION}" == "opened" ]; then 
57+               # Fetch the head commit sha, since it doesn't exist in the body of this event 
58+               COMMIT_SHA=$(curl -s "${PR_COMMITS_URL}" | jq -r '.[0].sha') 
59+ 
60+               # Dispatch request for benchmarks 
61+               dispatch_request "${COMMIT_SHA}" 
62+             else 
63+               # Dispatch request for benchmarks 
64+               dispatch_request "${PR_COMMIT_SHA}" 
65+             fi 
66+           else 
67+             echo "NO AUTH - FORK PULL REQUEST" 
68+           fi 
0 commit comments