Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarks / Contributing Updates #689

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/benchmark-comment.yml
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
73 changes: 46 additions & 27 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +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" \
-H "Authorization: token ${{ secrets.NPM_DEPLOY_USER_PAT }}" \
-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