-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added workflow file for commenting on a pull-request to dispatc…
…h trigger benchmark suite
- Loading branch information
Michael Perrotte
committed
Jan 28, 2020
1 parent
3590e40
commit 5967fa4
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
name: Benchmark CLI - Comment | ||
|
||
on: | ||
issue_comment: | ||
types: [created, edited] | ||
|
||
jobs: | ||
comment-handler: | ||
name: Trigger Benchmarks | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Handle Incoming Comment | ||
env: | ||
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 }} | ||
run: | | ||
# Comment Handler | ||
# Creates an exit early condition if there are errors | ||
# Exit early if `jq` is not present | ||
set -e | ||
jq --version | ||
# Figure out if comment came from pull-request or issue | ||
IS_PR=$(curl -s https://api.github.com/repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER} | jq -cr '.pull_request.url') | ||
if [ "${IS_PR}" != "null" ]; then | ||
echo "Comment from pull/${ISSUE_NUMBER}." | ||
# It is a pull-request; check comment body for correct phrase | ||
if [ "${COMMENT_ACTIONABLE}" == "true" ]; then | ||
# Fetch pull-request information | ||
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 "Authorization: token ${AUTH_TOKEN}" \ | ||
-d \ | ||
' | ||
{ | ||
"event_type": "'"${EVENT_NAME}"'", | ||
"client_payload": { | ||
"pr_id": "'"${ISSUE_NUMBER}"'", | ||
"repo": "'"${PR_REPO}"'", | ||
"owner": "'"${PR_OWNER}"'", | ||
"commit_sha": "'"${PR_COMMIT_SHA}"'" | ||
} | ||
}' | ||
# Create reaction on comment to confirm dispatch was sent | ||
curl \ | ||
-s \ | ||
-X POST https://api.github.com/graphql \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: token ${AUTH_TOKEN}" \ | ||
-d \ | ||
' | ||
{ | ||
"query": "mutation($inputData:AddReactionInput!) { addReaction(input:$inputData) { reaction { content } } }", | ||
"variables": { | ||
"inputData": { | ||
"subjectId": "'"${COMMENT_NODE_ID}"'", | ||
"content": "ROCKET" | ||
} | ||
} | ||
}' | ||
else | ||
echo "Comment not actionable." | ||
fi | ||
else | ||
echo "Comment not from pull-request." | ||
fi |