consul/.github/workflows/load-test.yml

70 lines
2.8 KiB
YAML

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
name: Load Test
on:
pull_request:
branches:
- main
types: [labeled]
workflow_dispatch: {}
jobs:
trigger-load-test:
if: ${{ github.event.label.name == 'pr/load-test' }}
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
# This only runs the load test pipeline on the 'main' branch
jsonData=$(jq --null-input -r --arg commit ${{ github.event.pull_request.head.sha }} \
'{branch:"main", parameters: {"commit": $commit, "trigger-load-test": true}}')
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"