|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Verify that a successful Release Prepare run produced the exact release set. |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +die() { |
| 7 | + printf 'release artifacts: %s\n' "$*" >&2 |
| 8 | + exit 1 |
| 9 | +} |
| 10 | + |
| 11 | +run_json="${1:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}" |
| 12 | +artifact_dir="${2:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}" |
| 13 | +version="${3:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}" |
| 14 | +commit="${4:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}" |
| 15 | + |
| 16 | +test -f "$run_json" || die "missing workflow-run metadata: $run_json" |
| 17 | +test -d "$artifact_dir" || die "missing artifact directory: $artifact_dir" |
| 18 | +[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z][A-Za-z0-9-]*\.[0-9]+)?$ ]] || |
| 19 | + die "invalid release version: $version" |
| 20 | +[[ "$commit" =~ ^[0-9a-f]{40}$ ]] || die "invalid release commit: $commit" |
| 21 | + |
| 22 | +jq -e \ |
| 23 | + --arg commit "$commit" \ |
| 24 | + '.head_sha == $commit |
| 25 | + and .path == ".github/workflows/release-prepare.yml" |
| 26 | + and .event == "push" |
| 27 | + and .status == "completed" |
| 28 | + and .conclusion == "success"' \ |
| 29 | + "$run_json" >/dev/null || |
| 30 | + die "selected run is not a successful Release Prepare run for the tag commit" |
| 31 | + |
| 32 | +expected=( |
| 33 | + "pagedb-fsck-${version}-linux-x64.tar.gz" |
| 34 | + "pagedb-fsck-${version}-linux-arm64.tar.gz" |
| 35 | + "pagedb-fsck-${version}-macos-arm64.tar.gz" |
| 36 | + "pagedb-fsck-${version}-macos-x64.tar.gz" |
| 37 | + "pagedb-fsck-${version}-windows-x64.zip" |
| 38 | +) |
| 39 | + |
| 40 | +shopt -s nullglob dotglob |
| 41 | +entries=("$artifact_dir"/*) |
| 42 | +shopt -u nullglob dotglob |
| 43 | +test "${#entries[@]}" -eq "${#expected[@]}" || |
| 44 | + die "expected exactly ${#expected[@]} release archives" |
| 45 | + |
| 46 | +for entry in "${entries[@]}"; do |
| 47 | + test -f "$entry" && test ! -L "$entry" || |
| 48 | + die "unexpected release artifact: $entry" |
| 49 | +done |
| 50 | +for archive in "${expected[@]}"; do |
| 51 | + test -f "$artifact_dir/$archive" || |
| 52 | + die "missing release archive: $archive" |
| 53 | +done |
| 54 | + |
| 55 | +printf 'release artifacts: ok\n' |
0 commit comments