|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# This script checks if we are in a consistent state to build a new release. |
| 4 | +# See the release instructions in README.md for the steps to make this pass. |
| 5 | +# You may want to run "make release" instead of running this script directly. |
| 6 | + |
| 7 | +set -eEfuo pipefail |
| 8 | +trap'echo "$0: Check failed. Stopping." >&2' ERR |
| 9 | + |
| 10 | +readonly version_path='VERSION' |
| 11 | +readonly changes_path='doc/source/changes.rst' |
| 12 | + |
| 13 | +echo'Checking current directory.' |
| 14 | +test"$(cd -- "$(dirname -- "$0")"&& pwd)" = "$(pwd)"# Ugly, but portable. |
| 15 | + |
| 16 | +echo"Checking that $version_path and $changes_path exist and have no uncommitted changes." |
| 17 | +test -f "$version_path" |
| 18 | +test -f "$changes_path" |
| 19 | +git status -s -- "$version_path""$changes_path" |
| 20 | +test -z "$(git status -s -- "$version_path""$changes_path")" |
| 21 | + |
| 22 | +# This section can be commented out, if absolutely necessary. |
| 23 | +echo'Checking that ALL changes are committed.' |
| 24 | +git status -s --ignore-submodules |
| 25 | +test -z "$(git status -s --ignore-submodules)" |
| 26 | + |
| 27 | +version_version="$(cat "$version_path")" |
| 28 | +changes_version="$(awk '/^[0-9]/{print $0; exit}'"$changes_path")" |
| 29 | +config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" |
| 30 | +latest_tag="$(git $config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1)" |
| 31 | +head_sha="$(git rev-parse HEAD)" |
| 32 | +latest_tag_sha="$(git rev-parse "$latest_tag")" |
| 33 | + |
| 34 | +# Display a table of all the current version, tag, and HEAD commit information. |
| 35 | +echo$'\nThe VERSION must be the same in all locations, and so must the HEAD and tag SHA' |
| 36 | +printf'%-14s = %s\n''VERSION file'"$version_version" \ |
| 37 | +'changes.rst'"$changes_version" \ |
| 38 | +'Latest tag'"$latest_tag" \ |
| 39 | +'HEAD SHA'"$head_sha" \ |
| 40 | +'Latest tag SHA'"$latest_tag_sha" |
| 41 | + |
| 42 | +# Check that the latest tag and current version match the HEAD we're releasing. |
| 43 | +test"$version_version" = "$changes_version" |
| 44 | +test"$latest_tag" = "$version_version" |
| 45 | +test"$head_sha" = "$latest_tag_sha" |
| 46 | +echo'OK, everything looks good.' |
0 commit comments