Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Perrotte <mike@npmjs.com>2020-01-10 10:59:33 +0300
committerMichael Perrotte <mike@npmjs.com>2020-01-28 20:37:21 +0300
commit5967fa44b3908fde0fcf3379c1d81c53a82903d8 (patch)
treeca7f2a75c359dd5f55d06808a0bfe9ba7788e07d
parent3590e40cc33857a67579a3b47552f83cb39a15db (diff)
feat: added workflow file for commenting on a pull-request to dispatch trigger benchmark suite
-rw-r--r--.github/workflows/benchmark-comment.yml92
1 files changed, 92 insertions, 0 deletions
diff --git a/.github/workflows/benchmark-comment.yml b/.github/workflows/benchmark-comment.yml
new file mode 100644
index 000000000..de86c3c13
--- /dev/null
+++ b/.github/workflows/benchmark-comment.yml
@@ -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