Skip to content

Commit

Permalink
Extract checks from release target to script
Browse files Browse the repository at this point in the history
This extracts the check logic from the release target in Makefile
to a new script, check-version.sh. The code is also modified,
mainly to account for different ways output is displayed and errors
are reported and treated in a Makefile versus a standalone shell
script. (The .sh suffix is for consistency with the naming of
init-tests-after-clone.sh and is *not* intended to suggest sourcing
the script; this script should be executed, not sourced.)
  • Loading branch information
EliahKagan committed Sep 14, 2023
1 parent 5cf7f97 commit 6495d84
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test/fixtures/* eol=lf
init-tests-after-clone.sh eol=lf
check-version.sh eol=lf
Makefile eol=lf
26 changes: 1 addition & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,7 @@ clean:
rm -rf build/ dist/ .eggs/ .tox/

release: clean
# Check that VERSION and changes.rst exist and have no uncommitted changes
test -f VERSION
test -f doc/source/changes.rst
git status -s VERSION doc/source/changes.rst
@test -z "$$(git status -s VERSION doc/source/changes.rst)"

# Check that ALL changes are commited (can comment out if absolutely necessary)
git status -s
@test -z "$$(git status -s)"

# Check that latest tag matches version and is the current head we're releasing
@version_file="$$(cat VERSION)" && \
changes_file="$$(awk '/^[0-9]/ {print $$0; exit}' doc/source/changes.rst)" && \
config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \
latest_tag=$$(git $$config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1) && \
head_sha=$$(git rev-parse HEAD) latest_tag_sha=$$(git rev-parse "$$latest_tag") && \
printf '%-14s = %s\n' 'VERSION file' "$$version_file" \
'changes.rst' "$$changes_file" \
'Latest tag' "$$latest_tag" \
'HEAD SHA' "$$head_sha" \
'Latest tag SHA' "$$latest_tag_sha" && \
test "$$version_file" = "$$changes_file" && \
test "$$latest_tag" = "$$version_file" && \
test "$$head_sha" = "$$latest_tag_sha"

./check-version.sh
make force_release

force_release: clean
Expand Down
46 changes: 46 additions & 0 deletions check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
#
# This script checks if we appear ready to build and publish a new release.
# See the release instructions in README.md for the steps to make this pass.

set -eEfuo pipefail
trap 'printf "%s: Check failed. Stopping.\n" "$0" >&2' ERR

readonly version_path='VERSION'
readonly changes_path='doc/source/changes.rst'

printf 'Checking current directory.\n'
test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable.

printf 'Checking that %s and %s exist and have no committed changes.\n' \
"$version_path" "$changes_path"
test -f "$version_path"
test -f "$changes_path"
git status -s -- "$version_path" "$changes_path"
test -z "$(git status -s -- "$version_path" "$changes_path")"

# This section can be commented out, if absolutely necessary.
printf 'Checking that ALL changes are committed.\n'
git status -s
test -z "$(git status -s)"

printf 'Gathering current version, latest tag, and current HEAD commit info.\n'
version_version="$(cat "$version_path")"
changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")"
config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)"
latest_tag="$(git $config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1)"
head_sha="$(git rev-parse HEAD)"
latest_tag_sha="$(git rev-parse "$latest_tag")"

# Display a table of all the current version, tag, and HEAD commit information.
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"

# Check that latest tag matches version and is the current HEAD we're releasing
test "$version_version" = "$changes_version"
test "$latest_tag" = "$version_version"
test "$head_sha" = "$latest_tag_sha"
printf 'OK, everything looks good.\n'

0 comments on commit 6495d84

Please sign in to comment.