Skip to content

Commit 6495d84

Browse files
committed
Extract checks from release target to script
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.)
1 parent 5cf7f97 commit 6495d84

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
test/fixtures/* eol=lf
22
init-tests-after-clone.sh eol=lf
3+
check-version.sh eol=lf
34
Makefile eol=lf

Makefile

+1-25
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,7 @@ clean:
77
rm -rf build/ dist/ .eggs/ .tox/
88

99
release: clean
10-
# Check that VERSION and changes.rst exist and have no uncommitted changes
11-
test -f VERSION
12-
test -f doc/source/changes.rst
13-
git status -s VERSION doc/source/changes.rst
14-
@test -z "$$(git status -s VERSION doc/source/changes.rst)"
15-
16-
# Check that ALL changes are commited (can comment out if absolutely necessary)
17-
git status -s
18-
@test -z "$$(git status -s)"
19-
20-
# Check that latest tag matches version and is the current head we're releasing
21-
@version_file="$$(cat VERSION)" && \
22-
changes_file="$$(awk '/^[0-9]/ {print $$0; exit}' doc/source/changes.rst)" && \
23-
config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \
24-
latest_tag=$$(git $$config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1) && \
25-
head_sha=$$(git rev-parse HEAD) latest_tag_sha=$$(git rev-parse "$$latest_tag") && \
26-
printf '%-14s = %s\n' 'VERSION file' "$$version_file" \
27-
'changes.rst' "$$changes_file" \
28-
'Latest tag' "$$latest_tag" \
29-
'HEAD SHA' "$$head_sha" \
30-
'Latest tag SHA' "$$latest_tag_sha" && \
31-
test "$$version_file" = "$$changes_file" && \
32-
test "$$latest_tag" = "$$version_file" && \
33-
test "$$head_sha" = "$$latest_tag_sha"
34-
10+
./check-version.sh
3511
make force_release
3612

3713
force_release: clean

check-version.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script checks if we appear ready to build and publish a new release.
4+
# See the release instructions in README.md for the steps to make this pass.
5+
6+
set -eEfuo pipefail
7+
trap 'printf "%s: Check failed. Stopping.\n" "$0" >&2' ERR
8+
9+
readonly version_path='VERSION'
10+
readonly changes_path='doc/source/changes.rst'
11+
12+
printf 'Checking current directory.\n'
13+
test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable.
14+
15+
printf 'Checking that %s and %s exist and have no committed changes.\n' \
16+
"$version_path" "$changes_path"
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+
printf 'Checking that ALL changes are committed.\n'
24+
git status -s
25+
test -z "$(git status -s)"
26+
27+
printf 'Gathering current version, latest tag, and current HEAD commit info.\n'
28+
version_version="$(cat "$version_path")"
29+
changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")"
30+
config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)"
31+
latest_tag="$(git $config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1)"
32+
head_sha="$(git rev-parse HEAD)"
33+
latest_tag_sha="$(git rev-parse "$latest_tag")"
34+
35+
# Display a table of all the current version, tag, and HEAD commit information.
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 latest tag matches version and is the current HEAD we're releasing
43+
test "$version_version" = "$changes_version"
44+
test "$latest_tag" = "$version_version"
45+
test "$head_sha" = "$latest_tag_sha"
46+
printf 'OK, everything looks good.\n'

0 commit comments

Comments
 (0)