|
| 1 | +name: API spec |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'docs/api-spec.yaml' |
| 8 | + - '.spectral.yaml' |
| 9 | + - 'crates/auths-pairing-daemon/src/handlers.rs' |
| 10 | + - 'crates/auths-pairing-daemon/src/router.rs' |
| 11 | + - 'crates/auths-pairing-daemon/src/error.rs' |
| 12 | + - '.github/workflows/api-spec.yml' |
| 13 | + pull_request: |
| 14 | + branches: [main] |
| 15 | + paths: |
| 16 | + - 'docs/api-spec.yaml' |
| 17 | + - '.spectral.yaml' |
| 18 | + - 'crates/auths-pairing-daemon/src/handlers.rs' |
| 19 | + - 'crates/auths-pairing-daemon/src/router.rs' |
| 20 | + - 'crates/auths-pairing-daemon/src/error.rs' |
| 21 | + - '.github/workflows/api-spec.yml' |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + # `pull-requests: read` needed for the drift-gate label check. |
| 26 | + pull-requests: read |
| 27 | + |
| 28 | +jobs: |
| 29 | + # ADR 004: `spectral:oas` baseline + project custom rules in |
| 30 | + # `.spectral.yaml`. Zero errors; warnings allowed with rationale. |
| 31 | + lint: |
| 32 | + name: Spectral lint |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + - uses: actions/setup-node@v4 |
| 37 | + with: |
| 38 | + node-version: '20' |
| 39 | + - name: Install Spectral |
| 40 | + run: npm install -g @stoplight/spectral-cli@6 |
| 41 | + - name: Lint docs/api-spec.yaml |
| 42 | + run: spectral lint docs/api-spec.yaml --fail-severity=error |
| 43 | + |
| 44 | + # ADR 004: if a PR modifies handler/router/error.rs but does not |
| 45 | + # touch docs/api-spec.yaml, fail the check. The label |
| 46 | + # `api-no-spec-change` (applied by a reviewer) overrides for changes |
| 47 | + # that are provably spec-invariant (e.g., internal refactors that |
| 48 | + # preserve wire behavior). |
| 49 | + drift-gate: |
| 50 | + name: Spec drift gate |
| 51 | + if: github.event_name == 'pull_request' |
| 52 | + runs-on: ubuntu-latest |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + - name: Check for spec drift |
| 58 | + env: |
| 59 | + BASE_REF: ${{ github.base_ref }} |
| 60 | + LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} |
| 61 | + run: | |
| 62 | + set -euo pipefail |
| 63 | + git fetch origin "$BASE_REF" --depth=1 |
| 64 | +
|
| 65 | + changed=$(git diff --name-only "origin/$BASE_REF" HEAD) |
| 66 | + echo "Changed files in PR:" |
| 67 | + echo "$changed" |
| 68 | +
|
| 69 | + touched_handler=0 |
| 70 | + touched_spec=0 |
| 71 | + while IFS= read -r f; do |
| 72 | + case "$f" in |
| 73 | + crates/auths-pairing-daemon/src/handlers.rs|\ |
| 74 | + crates/auths-pairing-daemon/src/router.rs|\ |
| 75 | + crates/auths-pairing-daemon/src/error.rs) |
| 76 | + touched_handler=1 ;; |
| 77 | + docs/api-spec.yaml) |
| 78 | + touched_spec=1 ;; |
| 79 | + esac |
| 80 | + done <<< "$changed" |
| 81 | +
|
| 82 | + if [ "$touched_handler" = "1" ] && [ "$touched_spec" = "0" ]; then |
| 83 | + echo |
| 84 | + echo "❌ PR touches daemon handler/router/error.rs but does not update docs/api-spec.yaml." |
| 85 | + echo " Per ADR 004, update docs/api-spec.yaml in the same PR, OR have a reviewer add" |
| 86 | + echo " the 'api-no-spec-change' label if the change is provably spec-invariant." |
| 87 | + if echo "$LABELS" | grep -q '"api-no-spec-change"'; then |
| 88 | + echo " Detected 'api-no-spec-change' label — drift gate overridden." |
| 89 | + exit 0 |
| 90 | + fi |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + echo "✅ Spec drift gate: OK" |
0 commit comments