|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
set -eEfuo pipefail |
|
trap 'echo "$0: Check failed. Stopping." >&2' ERR |
|
|
|
readonly version_path='VERSION' |
|
readonly changes_path='doc/source/changes.rst' |
|
|
|
function check_status() { |
|
git status -s "$@" |
|
test -z "$(git status -s "$@")" |
|
} |
|
|
|
function get_latest_tag() { |
|
local config_opts |
|
printf -v config_opts ' -c versionsort.suffix=-%s' alpha beta pre rc RC |
|
|
|
git $config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1 |
|
} |
|
|
|
echo 'Checking current directory.' |
|
test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" |
|
|
|
echo "Checking that $version_path and $changes_path exist and have no uncommitted changes." |
|
test -f "$version_path" |
|
test -f "$changes_path" |
|
check_status -- "$version_path" "$changes_path" |
|
|
|
|
|
echo 'Checking that ALL changes are committed.' |
|
check_status --ignore-submodules |
|
|
|
version_version="$(<"$version_path")" |
|
changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")" |
|
latest_tag="$(get_latest_tag)" |
|
head_sha="$(git rev-parse HEAD)" |
|
latest_tag_sha="$(git rev-parse "${latest_tag}^{commit}")" |
|
|
|
|
|
echo |
|
echo 'The VERSION must be the same in all locations, and so must the HEAD and tag SHA' |
|
printf '%-14s = %s\n' 'VERSION file' "$version_version" \ |
|
'changes.rst' "$changes_version" \ |
|
'Latest tag' "$latest_tag" \ |
|
'HEAD SHA' "$head_sha" \ |
|
'Latest tag SHA' "$latest_tag_sha" |
|
|
|
|
|
test "$version_version" = "$changes_version" |
|
test "$latest_tag" = "$version_version" |
|
test "$head_sha" = "$latest_tag_sha" |
|
echo 'OK, everything looks good.' |
|
|