|
| 1 | +# PATH-GUARD WORKFLOW — SR-159 |
| 2 | +# |
| 3 | +# Enforces the repo's path doctrine on every PR. The doctrine itself lives |
| 4 | +# in two places that MUST stay in sync: |
| 5 | +# |
| 6 | +# 1. survey-cli/AGENTS.md § PATH DOCTRINE (human-readable spec) |
| 7 | +# 2. scripts/path_guard.py (machine-readable manifest + checker) |
| 8 | +# |
| 9 | +# This workflow is a thin shim around `scripts/path_guard.py --diff`. |
| 10 | +# Keep it small. All policy logic belongs in the Python script so the |
| 11 | +# pre-commit hook and CI run the exact same code path. |
| 12 | +# |
| 13 | +# History: |
| 14 | +# - 2026-05-13 SR-159: created. Reason: SR-154 (100-file PR landed in a |
| 15 | +# non-existent dir) + SR-162 (daemon.py vs daemon/ shadow killed CI for |
| 16 | +# a week). Both could have been blocked by a 5-line CI check. |
| 17 | +# |
| 18 | +# Style notes (mirroring .github/workflows/ci.yml §13.8.4): |
| 19 | +# - Action versions are Brain-property. Bumped explicitly, never @latest. |
| 20 | +# - actions/checkout@v5, setup-python@v6 to stay on Node-24 runtime. |
| 21 | +# - fetch-depth: 0 is REQUIRED because the guard runs `git diff |
| 22 | +# $base...HEAD` and needs the merge-base reachable. |
| 23 | + |
| 24 | +name: path-guard |
| 25 | + |
| 26 | +on: |
| 27 | + pull_request: |
| 28 | + # No `branches:` filter — see ci.yml: PRs against integration branches |
| 29 | + # must also be gated, otherwise drift sneaks in via long-running feat |
| 30 | + # branches (SR-50..SR-55 precedent in PR #54). |
| 31 | + push: |
| 32 | + branches: |
| 33 | + - main |
| 34 | + - master |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + pull-requests: write # for the failure comment |
| 39 | + |
| 40 | +jobs: |
| 41 | + path-guard: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v5 |
| 45 | + with: |
| 46 | + # Needed for `git diff $base...HEAD` to resolve the merge-base. |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Set up Python |
| 50 | + uses: actions/setup-python@v6 |
| 51 | + with: |
| 52 | + python-version: "3.13" |
| 53 | + |
| 54 | + - name: Run path-guard (diff mode) |
| 55 | + id: guard |
| 56 | + # The script uses $GITHUB_BASE_REF on pull_request events and falls |
| 57 | + # back to origin/main on push events. No `pip install` — pure stdlib. |
| 58 | + # |
| 59 | + # `set -o pipefail` is REQUIRED — without it the exit code of `tee` |
| 60 | + # (always 0) masks a non-zero exit from path_guard.py and the guard |
| 61 | + # silently passes on real violations. This is not theoretical: the |
| 62 | + # first iteration of this workflow shipped without pipefail, the |
| 63 | + # demo probe PR (#174) showed the violations in the log but the |
| 64 | + # check was marked green. Do NOT remove this line. |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -o pipefail |
| 68 | + python scripts/path_guard.py --diff | tee path_guard.out |
| 69 | + env: |
| 70 | + # Explicit even though Actions sets it automatically — makes the |
| 71 | + # script's behaviour obvious to anyone reading the workflow. |
| 72 | + GITHUB_BASE_REF: ${{ github.base_ref }} |
| 73 | + |
| 74 | + - name: Comment on PR when guard fails |
| 75 | + if: failure() && github.event_name == 'pull_request' |
| 76 | + uses: actions/github-script@v7 |
| 77 | + with: |
| 78 | + script: | |
| 79 | + const fs = require('fs'); |
| 80 | + const out = fs.existsSync('path_guard.out') |
| 81 | + ? fs.readFileSync('path_guard.out', 'utf8') |
| 82 | + : '(no output captured)'; |
| 83 | + const body = [ |
| 84 | + '### path-guard failed (SR-159)', |
| 85 | + '', |
| 86 | + 'This PR adds files outside the canonical repo layout. The doctrine', |
| 87 | + 'lives in [`survey-cli/AGENTS.md` § PATH DOCTRINE](https://github.com/' + |
| 88 | + context.repo.owner + '/' + context.repo.repo + |
| 89 | + '/blob/main/survey-cli/AGENTS.md#path-doctrine-sr-159).', |
| 90 | + '', |
| 91 | + '<details><summary>Guard output</summary>', |
| 92 | + '', |
| 93 | + '```', |
| 94 | + out, |
| 95 | + '```', |
| 96 | + '', |
| 97 | + '</details>', |
| 98 | + '', |
| 99 | + 'If the verdict is wrong (e.g. a genuinely new canonical area),', |
| 100 | + '**STOP** and comment on the issue with rationale — do not work', |
| 101 | + 'around the guard.', |
| 102 | + ].join('\n'); |
| 103 | + await github.rest.issues.createComment({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + issue_number: context.issue.number, |
| 107 | + body, |
| 108 | + }); |
0 commit comments