Skip to content

Commit

Permalink
chore(benchmarks): tidy up benchmark workflows
Browse files Browse the repository at this point in the history
PR-URL: #4145
Credit: @nlf
Close: #4145
Reviewed-by: @wraithgar
  • Loading branch information
nlf committed Dec 9, 2021
1 parent 1d8bec5 commit 6b80faa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/benchmark-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ jobs:
DISPATCH_REPO: "benchmarks"
DISPATCH_OWNER: "npm"
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
OWNER: ${{ github.event.repository.owner.login }}
REPO: ${{ github.event.repository.name }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
COMMENT_BODY: ${{ github.event.comment.body }}
COMMENT_ID: ${{ github.event.comment.id }}
COMMENT_NODE_ID: ${{ github.event.comment.node_id }}
COMMENT_ACTIONABLE: ${{ startsWith(github.event.comment.body, 'test this please ✅') }}
AUTH_TOKEN: ${{ secrets.NPM_DEPLOY_USER_PAT }}
AUTH_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }}
run: |
# Comment Handler
Expand All @@ -46,24 +43,22 @@ jobs:
PR_DATA=$(curl -s "${IS_PR}")
PR_OWNER=$(echo "${PR_DATA}" | jq '.head.repo.owner.login')
PR_REPO=$(echo "${PR_DATA}" | jq '.head.repo.name')
PR_COMMIT_SHA=$(curl -s "${IS_PR}/commits" | jq -r '.[0].sha')
# dispatch request for benchmarks
echo "Dispatching request..."
curl \
-s \
-X POST https://api.github.com/repos/${DISPATCH_OWNER}/${DISPATCH_REPO}/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${AUTH_TOKEN}" \
-d \
'
{
"event_type": "'"${EVENT_NAME}"'",
"event_type": "'"${EVENT_NAME} ${PR_OWNER}/${PR_REPO}#${ISSUE_NUMBER}"'",
"client_payload": {
"pr_id": "'"${ISSUE_NUMBER}"'",
"repo": "'"${PR_REPO}"'",
"owner": "'"${PR_OWNER}"'",
"commit_sha": "'"${PR_COMMIT_SHA}"'"
"owner": "'"${PR_OWNER}"'"
}
}'
Expand Down
28 changes: 6 additions & 22 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
name: Benchmark Suite

on:
push:
branches:
- "latest"
pull_request:
branches:
- "**"
Expand All @@ -21,48 +18,35 @@ jobs:
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 }}
AUTH_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }}
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 "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${AUTH_TOKEN}" \
-d \
'
{
"event_type": "'"${EVENT_NAME}"'",
"event_type": "'"${EVENT_NAME} ${PR_OWNER}/${REPO}#${PR_NUMBER}"'",
"client_payload": {
"pr_id": "'"${PR_NUMBER}"'",
"repo": "'"${REPO}"'",
"owner": "'"${PR_OWNER}"'",
"commit_sha": "'"${REF_SHA}"'"
"owner": "'"${PR_OWNER}"'"
}
}'
}
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
# Dispatch request for benchmarks
dispatch_request
else
echo "NO AUTH - FORK PULL REQUEST"
fi

0 comments on commit 6b80faa

Please sign in to comment.