|
| 1 | +name: Guard Generated Catalog |
| 2 | + |
| 3 | +# samples/hosted-agent/sample-catalog.json is GENERATED by the "Sync Sample |
| 4 | +# Catalog" workflow and must never be edited or committed by hand. This check |
| 5 | +# fails any PR that modifies it unless the PR originates from a sync-workflow |
| 6 | +# branch (ci/sync-sample-catalog-*). |
| 7 | +# |
| 8 | +# For this to ENFORCE (not merely report), the protected branch must also: |
| 9 | +# - mark the "guard-catalog" check as a REQUIRED status check, and |
| 10 | +# - disallow direct pushes (PRs only) — a pull_request guard cannot catch a |
| 11 | +# direct push. |
| 12 | +# |
| 13 | +# A pull_request workflow only guards PRs targeting the branch it lives on, so |
| 14 | +# this file must exist on every protected branch you want covered. |
| 15 | + |
| 16 | +on: |
| 17 | + pull_request: |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + guard-catalog: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Reject manual edits to sample-catalog.json |
| 32 | + env: |
| 33 | + HEAD_REF: ${{ github.head_ref }} |
| 34 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 35 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + set -euo pipefail |
| 39 | + CATALOG="samples/hosted-agent/sample-catalog.json" |
| 40 | +
|
| 41 | + # Did this PR change the generated catalog at all? |
| 42 | + if git diff --quiet "$BASE_SHA" "$HEAD_SHA" -- "$CATALOG"; then |
| 43 | + echo "PR does not touch $CATALOG — OK." |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # It did. Only the Sync Sample Catalog workflow (which opens PRs from |
| 48 | + # ci/sync-sample-catalog-* branches) is allowed to change it. |
| 49 | + if [[ "$HEAD_REF" == ci/sync-sample-catalog-* ]]; then |
| 50 | + echo "Change to $CATALOG came from sync branch '$HEAD_REF' — OK." |
| 51 | + exit 0 |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "::error file=$CATALOG::$CATALOG is generated by the 'Sync Sample Catalog' workflow and must not be edited or committed manually. Revert your changes to this file; CI will regenerate it." |
| 55 | + exit 1 |
0 commit comments