Skip to content

Commit

Permalink
feat: updated workflow for pull-ruquest benchmark dispatch requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Perrotte committed Jan 13, 2020
1 parent 0abdef5 commit ef13d25
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ef13d25

Please sign in to comment.