|
| 1 | +name: Check scripts |
| 2 | + |
| 3 | +# Verifies that the scripts in the repository are consistent with each other before a pull request can be merged. |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + workflow_dispatch: # adds a manual "Run workflow" button, handy for testing |
| 10 | + |
| 11 | +jobs: |
| 12 | + checksums: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check out the repository |
| 16 | + uses: actions/checkout@v5 |
| 17 | + |
| 18 | + - name: Check that every script is listed in SHA256SUMS.txt |
| 19 | + run: | |
| 20 | + ls *.sql | sort > /tmp/scripts.txt |
| 21 | + awk '{print $2}' SHA256SUMS.txt | sort > /tmp/listed.txt |
| 22 | + if ! diff /tmp/scripts.txt /tmp/listed.txt; then |
| 23 | + echo "The scripts in the repository and the files listed in SHA256SUMS.txt do not match." |
| 24 | + echo "Lines starting with < are scripts that are not listed; lines starting with > are listed files that do not exist." |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + echo "All scripts are listed." |
| 28 | +
|
| 29 | + - name: Check that the checksums are current |
| 30 | + run: sha256sum -c SHA256SUMS.txt |
| 31 | + |
| 32 | + versions: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Check out the repository |
| 36 | + uses: actions/checkout@v5 |
| 37 | + |
| 38 | + - name: Check that every script has the same version timestamp |
| 39 | + run: | |
| 40 | + set -u |
| 41 | +
|
| 42 | + # Every script in a release is built at the same time and stamped with that time. |
| 43 | + # The installation scripts contain one stamp per stored procedure they include, so this also detects an installation script built from an outdated procedure. |
| 44 | + PATTERN='Version: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' |
| 45 | +
|
| 46 | + echo "Version timestamps found in each script:" |
| 47 | + for f in *.sql; do |
| 48 | + STAMPS=$(grep -hoE "$PATTERN" "$f" | sed 's/^Version: //' | sort -u | tr '\n' ' ') |
| 49 | + printf ' %-42s %s\n' "$f" "${STAMPS:-(none)}" |
| 50 | + done |
| 51 | +
|
| 52 | + ALL=$(grep -hoE "$PATTERN" *.sql | sed 's/^Version: //' | sort -u) |
| 53 | + COUNT=$(printf '%s\n' "$ALL" | grep -c . || true) |
| 54 | +
|
| 55 | + echo |
| 56 | + if [ "$COUNT" -eq 0 ]; then |
| 57 | + echo "No version timestamps were found. The scripts are expected to carry one." |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + if [ "$COUNT" -ne 1 ]; then |
| 61 | + echo "The scripts do not all have the same version timestamp:" |
| 62 | + printf '%s\n' "$ALL" | sed 's/^/ /' |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + echo "All scripts have the same version timestamp: $ALL" |
0 commit comments