|
| 1 | +name: Verify self-update checksums |
| 2 | + |
| 3 | +# Self-update fetches each launcher script from `main` and verifies it against a |
| 4 | +# committed `<script>.sha256` sidecar. If a script is edited without regenerating |
| 5 | +# its sidecar, self-update silently breaks for every user (checksum mismatch → |
| 6 | +# update refused). This workflow fails the PR/push when a sidecar is missing or |
| 7 | +# out of sync, keeping the two in lockstep. (DEVA11Y-475 review follow-up.) |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - 'scripts/**' |
| 13 | + - '.github/workflows/verify-selfupdate-checksums.yml' |
| 14 | + push: |
| 15 | + branches: [main] |
| 16 | + paths: |
| 17 | + - 'scripts/**' |
| 18 | + - '.github/workflows/verify-selfupdate-checksums.yml' |
| 19 | + |
| 20 | +jobs: |
| 21 | + verify-sidecars: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Verify scripts and .sha256 sidecars are in sync |
| 27 | + run: | |
| 28 | + set -uo pipefail |
| 29 | + shopt -s globstar nullglob |
| 30 | + status=0 |
| 31 | +
|
| 32 | + # 1. Every self-updating script must have a sidecar. |
| 33 | + for script in scripts/**/*.sh; do |
| 34 | + if [ ! -f "${script}.sha256" ]; then |
| 35 | + echo "::error file=${script}::Missing checksum sidecar ${script}.sha256. Generate it from the script's directory: shasum -a 256 <name>.sh | awk '{print \$1\" <name>.sh\"}' > <name>.sh.sha256" |
| 36 | + status=1 |
| 37 | + fi |
| 38 | + done |
| 39 | +
|
| 40 | + # 2. Every sidecar must match its script. |
| 41 | + sidecars=(scripts/**/*.sha256) |
| 42 | + if [ ${#sidecars[@]} -eq 0 ]; then |
| 43 | + echo "::error::No .sha256 sidecars found under scripts/." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + for sidecar in "${sidecars[@]}"; do |
| 47 | + dir=$(dirname "$sidecar") |
| 48 | + script="${sidecar%.sha256}" |
| 49 | + if [ ! -f "$script" ]; then |
| 50 | + echo "::error file=${sidecar}::Sidecar references missing script ${script}." |
| 51 | + status=1 |
| 52 | + continue |
| 53 | + fi |
| 54 | + # Sidecars store "<sha256> <basename>", so verify from the script's dir. |
| 55 | + if ( cd "$dir" && sha256sum -c "$(basename "$sidecar")" ); then |
| 56 | + echo "OK: $sidecar" |
| 57 | + else |
| 58 | + echo "::error file=${script}::Checksum mismatch — regenerate ${sidecar} after editing ${script} (run from ${dir}): shasum -a 256 <name>.sh | awk '{print \$1\" <name>.sh\"}' > <name>.sh.sha256" |
| 59 | + status=1 |
| 60 | + fi |
| 61 | + done |
| 62 | +
|
| 63 | + if [ "$status" -ne 0 ]; then |
| 64 | + echo "::error::Self-update checksum verification failed. Regenerate the affected .sha256 sidecar(s) and commit them." |
| 65 | + fi |
| 66 | + exit "$status" |
0 commit comments