2021-01-14 04:20:19 +00:00
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
branches:
|
2021-06-30 17:07:09 +00:00
|
|
|
- main
|
2021-01-14 04:20:19 +00:00
|
|
|
types: [labeled]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
trigger-load-test:
|
2021-01-15 16:09:08 +00:00
|
|
|
if: ${{ github.event.label.name == 'pr/load-test' }}
|
2021-01-14 04:20:19 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Trigger CircleCI Load Test Pipeline
|
|
|
|
run: |
|
|
|
|
# build json payload to trigger CircleCI Load Test Pipeline
|
2021-06-30 17:07:09 +00:00
|
|
|
# This only runs the load test pipeline on the 'main' branch
|
2021-01-14 04:20:19 +00:00
|
|
|
jsonData=$(jq --null-input -r --arg commit ${{ github.event.pull_request.head.sha }} \
|
2021-06-30 17:07:09 +00:00
|
|
|
'{branch:"main", parameters: {"commit": $commit, "trigger-load-test": true}}')
|
2021-01-14 04:20:19 +00:00
|
|
|
echo "Passing JSON data to CircleCI API: $jsonData"
|
|
|
|
load_test_pipeline_id=$(curl -X POST \
|
|
|
|
-H "Circle-Token: ${{ secrets.CIRCLE_TOKEN }}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d "$jsonData" \
|
|
|
|
"https://circleci.com/api/v2/project/gh/${GITHUB_REPOSITORY}/pipeline" | jq -r '.id')
|
|
|
|
echo "LOAD_TEST_PIPELINE_ID=$load_test_pipeline_id" >> $GITHUB_ENV
|
|
|
|
- name: Post Load Test URL to PR
|
|
|
|
env:
|
|
|
|
PR_COMMENT_URL: ${{ github.event.pull_request.comments_url }}
|
|
|
|
run: |
|
|
|
|
echo "LOAD_TEST_PIPELINE_ID is: $LOAD_TEST_PIPELINE_ID"
|
|
|
|
# get load-test workflow
|
|
|
|
workflow=
|
|
|
|
# wait up to a minute for load-test workflow to start
|
|
|
|
until [ $SECONDS -ge 60 ] && exit 1; do
|
|
|
|
workflow=$(curl -s -X GET \
|
|
|
|
-H "Circle-Token: ${{ secrets.CIRCLE_TOKEN }}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
"https://circleci.com/api/v2/pipeline/${LOAD_TEST_PIPELINE_ID}/workflow" | jq '.items[] | select(.name=="load-test")')
|
|
|
|
# if we found a workflow we exit
|
|
|
|
if [ -n "$workflow" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo -n "."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
echo "$workflow"
|
|
|
|
# get pipeline number
|
|
|
|
pipeline_number=$(echo "$workflow" | jq -r '.pipeline_number')
|
|
|
|
# get workflow id
|
|
|
|
workflow_id=$(echo "$workflow" | jq -r '.id')
|
|
|
|
# get project slug
|
|
|
|
project_slug=$(echo "$workflow" | jq -r '.project_slug')
|
|
|
|
# build load test URL
|
|
|
|
load_test_url="https://app.circleci.com/pipelines/${project_slug}/${pipeline_number}/workflows/${workflow_id}"
|
|
|
|
# comment URL to pull request
|
|
|
|
curl -X POST \
|
|
|
|
-H "Authorization: token ${{ secrets.PR_COMMENT_TOKEN }}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d "{\"body\": \"Load Test Pipeline Started at: $load_test_url\"}" \
|
|
|
|
"$PR_COMMENT_URL"
|