|
| 1 | +# Manual-trigger workflow to run Gatling load tests against overpass.deflock.org. |
| 2 | +# |
| 3 | +# Trigger from the Actions tab → "Load Test" → "Run workflow" → pick a scenario. |
| 4 | +# The HTML report is uploaded as a downloadable artifact (retained 30 days). |
| 5 | +# |
| 6 | +# When "all" is selected, all 4 simulations run in parallel on separate runners, |
| 7 | +# hitting the server simultaneously for distributed load. A summary job then |
| 8 | +# collects all reports and posts a PR comment with download links. |
| 9 | + |
| 10 | +name: Load Test |
| 11 | + |
| 12 | +on: |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + scenario: |
| 16 | + description: 'Test scenario to run' |
| 17 | + required: true |
| 18 | + default: 'baseline' |
| 19 | + type: choice |
| 20 | + options: |
| 21 | + - baseline |
| 22 | + - concurrent |
| 23 | + - stress |
| 24 | + - burst |
| 25 | + - all |
| 26 | + |
| 27 | +concurrency: |
| 28 | + group: load-test |
| 29 | + cancel-in-progress: true |
| 30 | + |
| 31 | +jobs: |
| 32 | + # Build the matrix dynamically based on the selected scenario. |
| 33 | + # This avoids the `matrix` context parsing issue in job-level `if`. |
| 34 | + resolve-matrix: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + outputs: |
| 37 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 38 | + steps: |
| 39 | + - id: set-matrix |
| 40 | + run: | |
| 41 | + if [ "${{ inputs.scenario }}" = "all" ]; then |
| 42 | + echo 'matrix={"include":[{"name":"baseline","class":"deflock.OverpassSimulation"},{"name":"concurrent","class":"deflock.ConcurrentSimulation"},{"name":"stress","class":"deflock.StressSimulation"},{"name":"burst","class":"deflock.BurstSimulation"}]}' >> "$GITHUB_OUTPUT" |
| 43 | + elif [ "${{ inputs.scenario }}" = "baseline" ]; then |
| 44 | + echo 'matrix={"include":[{"name":"baseline","class":"deflock.OverpassSimulation"}]}' >> "$GITHUB_OUTPUT" |
| 45 | + elif [ "${{ inputs.scenario }}" = "concurrent" ]; then |
| 46 | + echo 'matrix={"include":[{"name":"concurrent","class":"deflock.ConcurrentSimulation"}]}' >> "$GITHUB_OUTPUT" |
| 47 | + elif [ "${{ inputs.scenario }}" = "stress" ]; then |
| 48 | + echo 'matrix={"include":[{"name":"stress","class":"deflock.StressSimulation"}]}' >> "$GITHUB_OUTPUT" |
| 49 | + elif [ "${{ inputs.scenario }}" = "burst" ]; then |
| 50 | + echo 'matrix={"include":[{"name":"burst","class":"deflock.BurstSimulation"}]}' >> "$GITHUB_OUTPUT" |
| 51 | + fi |
| 52 | +
|
| 53 | + load-test: |
| 54 | + needs: resolve-matrix |
| 55 | + runs-on: ubuntu-latest |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: ${{ fromJson(needs.resolve-matrix.outputs.matrix) }} |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v5 |
| 61 | + |
| 62 | + - name: Set up JDK 21 |
| 63 | + uses: actions/setup-java@v4 |
| 64 | + with: |
| 65 | + distribution: temurin |
| 66 | + java-version: 21 |
| 67 | + |
| 68 | + # Caches Gradle wrapper and dependencies between runs |
| 69 | + - name: Setup Gradle |
| 70 | + uses: gradle/actions/setup-gradle@v4 |
| 71 | + |
| 72 | + - name: Run Gatling simulation (${{ matrix.name }}) |
| 73 | + working-directory: load-tests |
| 74 | + run: ./gradlew gatlingRun --simulation ${{ matrix.class }} --non-interactive |
| 75 | + |
| 76 | + - name: Upload Gatling report |
| 77 | + if: always() |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + name: gatling-report-${{ matrix.name }} |
| 81 | + path: load-tests/build/reports/gatling/ |
| 82 | + retention-days: 30 |
| 83 | + |
| 84 | + # Post a summary comment on the PR (if triggered from a PR branch) with |
| 85 | + # links to download each report artifact. |
| 86 | + summary: |
| 87 | + needs: load-test |
| 88 | + if: always() |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v5 |
| 92 | + |
| 93 | + - name: Find associated PR |
| 94 | + id: find-pr |
| 95 | + run: | |
| 96 | + # Search for a PR with this branch as the head ref. Check the |
| 97 | + # current repo first, then the parent (upstream) repo if this is a fork. |
| 98 | + PR=$(gh pr list --repo "${{ github.repository }}" --head "${{ github.ref_name }}" --json number --jq '.[0].number' 2>/dev/null || echo "") |
| 99 | + if [ -z "$PR" ]; then |
| 100 | + PARENT=$(gh api "repos/${{ github.repository }}" --jq '.parent.full_name // empty' 2>/dev/null || echo "") |
| 101 | + if [ -n "$PARENT" ]; then |
| 102 | + PR=$(gh pr list --repo "$PARENT" --head "${{ github.ref_name }}" --json number --jq '.[0].number' 2>/dev/null || echo "") |
| 103 | + if [ -n "$PR" ]; then |
| 104 | + echo "pr_repo=$PARENT" >> "$GITHUB_OUTPUT" |
| 105 | + fi |
| 106 | + fi |
| 107 | + else |
| 108 | + echo "pr_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT" |
| 109 | + fi |
| 110 | + echo "pr_number=$PR" >> "$GITHUB_OUTPUT" |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + |
| 114 | + - name: Post PR comment with report links |
| 115 | + if: steps.find-pr.outputs.pr_number != '' |
| 116 | + env: |
| 117 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 119 | + run: | |
| 120 | + SCENARIO="${{ inputs.scenario }}" |
| 121 | + RUN_ID="${{ github.run_id }}" |
| 122 | +
|
| 123 | + # Build artifact links from the matrix |
| 124 | + ARTIFACTS="" |
| 125 | + if [ "$SCENARIO" = "all" ] || [ "$SCENARIO" = "baseline" ]; then |
| 126 | + ARTIFACTS="$ARTIFACTS\n| Baseline | [Download]($RUN_URL/artifacts) |" |
| 127 | + fi |
| 128 | + if [ "$SCENARIO" = "all" ] || [ "$SCENARIO" = "concurrent" ]; then |
| 129 | + ARTIFACTS="$ARTIFACTS\n| Concurrent | [Download]($RUN_URL/artifacts) |" |
| 130 | + fi |
| 131 | + if [ "$SCENARIO" = "all" ] || [ "$SCENARIO" = "stress" ]; then |
| 132 | + ARTIFACTS="$ARTIFACTS\n| Stress | [Download]($RUN_URL/artifacts) |" |
| 133 | + fi |
| 134 | + if [ "$SCENARIO" = "all" ] || [ "$SCENARIO" = "burst" ]; then |
| 135 | + ARTIFACTS="$ARTIFACTS\n| Burst | [Download]($RUN_URL/artifacts) |" |
| 136 | + fi |
| 137 | +
|
| 138 | + BODY=$(cat <<EOF |
| 139 | + ## Load Test Results — \`$SCENARIO\` |
| 140 | +
|
| 141 | + | Scenario | Report | |
| 142 | + |----------|--------| |
| 143 | + $(echo -e "$ARTIFACTS") |
| 144 | +
|
| 145 | + [View full run]($RUN_URL) |
| 146 | +
|
| 147 | + > Download the artifact ZIP → extract → open \`index.html\` for interactive charts. |
| 148 | + EOF |
| 149 | + ) |
| 150 | +
|
| 151 | + gh pr comment "${{ steps.find-pr.outputs.pr_number }}" --repo "${{ steps.find-pr.outputs.pr_repo }}" --body "$BODY" |
0 commit comments