# Drop-in CI performance gate — Artillery's `cicd`, the loadr way.
#
# Copy this to .github/workflows/perf-gate.yml. It runs perf-smoke.yaml on every
# pull request; if any threshold is breached the loadr Action exits non-zero and
# this job fails (red check), blocking the merge. JUnit + JSON reports are
# uploaded as artifacts, and the PR can surface the JUnit via your test reporter.
name: perf-gate

on:
  pull_request:
  workflow_dispatch:

jobs:
  loadr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: loadr performance gate
        id: perf
        uses: levantar-ai/loadr@v1
        with:
          plan: examples/cicd/perf-smoke.yaml
          version: latest
          junit: loadr-junit.xml
          summary: loadr-summary.json
          # fail-on-threshold defaults to 'true' → a breached SLO fails the job.
        env:
          TARGET_URL: ${{ vars.STAGING_URL }}

      - name: Upload loadr report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: loadr-report
          path: |
            loadr-junit.xml
            loadr-summary.json

      - name: Summary
        if: always()
        run: |
          echo "passed=${{ steps.perf.outputs.passed }}" >> "$GITHUB_STEP_SUMMARY"
          echo "exit-code=${{ steps.perf.outputs.exit-code }}" >> "$GITHUB_STEP_SUMMARY"
