From 1ce034484ca9fd05d667111ca249d5d43ae64fcc Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 10 Jan 2020 05:56:50 -0500 Subject: feat: updated workflow for pull-ruquest benchmark dispatch requests --- .github/workflows/benchmark.yml | 72 ++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a49ed8495..0920f711c 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -16,33 +16,53 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout the npm/cli repo - - uses: actions/checkout@v2 - - # Installs the specific version of nodejs - - name: Use nodejs 12.x - uses: actions/setup-node@v1 - with: - node-version: "12.x" - - # Trigger Webhook - - name: Trigger Webhook + - 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: | - curl \ - -s \ - -X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \ - -H "Accept: application/vnd.github.everest-preview+json" \ - -d \ - ' - { - "event_type": "${{ github.event_name }}", - "client_payload": { - "pr_id": "${{ github.event.pull_request.number }}", - "repo": "${{ github.event.repository.name }}", - "owner": "${{ github.event.repository.owner.login }}", - "commit_sha": "${{ github.event.after }}" - } - }' + # 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 -- cgit v1.2.3