| 1 | #!/usr/bin/env bash |
| 2 | # Bind a normal official release to the main-v2 commit that introduced or |
| 3 | # updated its reviewed release-notes record. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | if [ "$#" -ne 2 ] || [[ ! "$1" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || \ |
| 7 | [[ ! "$2" =~ ^[0-9a-f]{40}$ ]]; then |
| 8 | echo "usage: validate-stable-candidate.sh MAJOR.MINOR.PATCH FULL_COMMIT_SHA" >&2 |
| 9 | exit 2 |
| 10 | fi |
| 11 | |
| 12 | version="$1" |
| 13 | candidate="$2" |
| 14 | script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 15 | |
| 16 | git cat-file -e "$candidate^{commit}" 2>/dev/null || { |
| 17 | echo "release candidate commit is unavailable: $candidate" >&2 |
| 18 | exit 1 |
| 19 | } |
| 20 | parent="$(git rev-parse "$candidate^1" 2>/dev/null)" || { |
| 21 | echo "release candidate must have a first parent: $candidate" >&2 |
| 22 | exit 1 |
| 23 | } |
| 24 | |
| 25 | work_dir="$(mktemp -d "${TMPDIR:-/tmp}/reasonix-stable-candidate.XXXXXX")" |
| 26 | cleanup() { |
| 27 | case "$work_dir" in |
| 28 | */reasonix-stable-candidate.*) rm -rf -- "$work_dir" ;; |
| 29 | *) echo "refusing to clean unexpected candidate directory: $work_dir" >&2 ;; |
| 30 | esac |
| 31 | } |
| 32 | trap cleanup EXIT |
| 33 | |
| 34 | git show "$candidate:release-notes/releases.json" >"$work_dir/current.json" || { |
| 35 | echo "release candidate does not contain release-notes/releases.json: $candidate" >&2 |
| 36 | exit 1 |
| 37 | } |
| 38 | git show "$parent:release-notes/releases.json" >"$work_dir/previous.json" || { |
| 39 | echo "release candidate parent does not contain release-notes/releases.json: $parent" >&2 |
| 40 | exit 1 |
| 41 | } |
| 42 | |
| 43 | node "$script_dir/validate-stable-release-record.mjs" \ |
| 44 | "$work_dir/current.json" "$version" "$work_dir/previous.json" |
| 45 | echo "Stable candidate is bound to its reviewed Notes change: v$version at $candidate" |
| 46 |