|
| 1 | +name: Checksum Verification |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ main ] |
| 6 | + push: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + verify-checksums: |
| 12 | + runs-on: ubuntu-24.04 |
| 13 | + timeout-minutes: 15 |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - name: 'Fast verify: successful download (dash)' |
| 18 | + run: | |
| 19 | + set -ex |
| 20 | + # ensure clean state and perform an initial download (should succeed) |
| 21 | + rm -f build/dash/0.5.13.tar.gz |
| 22 | + sh shvr.sh download dash_0.5.13 |
| 23 | +
|
| 24 | + - name: 'Corrupt checksum and assert download fails' |
| 25 | + run: | |
| 26 | + set -ex |
| 27 | + # backup checksum file |
| 28 | + cp checksums/dash/0.5.13.tar.gz.sha256sums checksums/dash/0.5.13.tar.gz.sha256sums.bak |
| 29 | + # corrupt checksum: replace hash with ones; keep filename |
| 30 | + printf '1111111111111111111111111111111111111111111111111111111111111111 %s\n' "0.5.13.tar.gz" > checksums/dash/0.5.13.tar.gz.sha256sums |
| 31 | + # remove any existing artifact to force re-download |
| 32 | + rm -f build/dash/0.5.13.tar.gz |
| 33 | + set +e |
| 34 | + # attempt download once; if the worker network is flaky this may fail |
| 35 | + # for reasons other than checksum mismatch. Capture logs and RC so we |
| 36 | + # can differentiate mismatch from other failures. |
| 37 | + # run the download and capture the exit code; write logs to file |
| 38 | + sh shvr.sh download dash_0.5.13 > download.log 2>&1 |
| 39 | + rc=$? |
| 40 | + # show the log to the step output so it appears in CI |
| 41 | + cat download.log |
| 42 | + set -e |
| 43 | + if [ "$rc" -eq 0 ]; then |
| 44 | + echo "Expected checksum verification to fail but it succeeded" >&2 |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + # ensure the failure was due to checksum mismatch; depending on the |
| 48 | + # runner and sha256sum version we may see one of multiple messages: |
| 49 | + # - our own 'sha256sum mismatch for ...' message |
| 50 | + # - a 'filename: FAILED' message emitted by 'sha256sum -c' |
| 51 | + # If neither is present then this is likely a transient network or |
| 52 | + # download tool error; fail the CI with the full log to help debug. |
| 53 | + grep -q "sha256sum mismatch" download.log || grep -q ": FAILED" download.log || (cat download.log && exit 1) |
| 54 | +
|
| 55 | + - name: 'Restore checksum and verify success' |
| 56 | + run: | |
| 57 | + set -ex |
| 58 | + mv checksums/dash/0.5.13.tar.gz.sha256sums.bak checksums/dash/0.5.13.tar.gz.sha256sums |
| 59 | + rm -f build/dash/0.5.13.tar.gz |
| 60 | + sh shvr.sh download dash_0.5.13 |
0 commit comments