Skip to content

Commit e8c3085

Browse files
committed
Merge branch 'portable-makefile'
2 parents 35f2339 + 1e0b3f9 commit e8c3085

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

‎.gitattributes‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/fixtures/*eol=lf
2-
init-tests-after-clone.sh
2+
*.sheol=lf
3+
/Makefileeol=lf

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.py[co]
22
*.swp
33
*~
4+
.env/
5+
env/
46
.venv/
57
venv/
68
/*.egg-info

‎Makefile‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ clean:
77
rm -rf build/ dist/ .eggs/ .tox/
88

99
release: clean
10-
# Check if latest tag is the current head we're releasing
11-
echo"Latest tag = $$(git tag | sort -nr | head -n1)"
12-
echo"HEAD SHA = $$(git rev-parse head)"
13-
echo"Latest tag SHA = $$(git tag | sort -nr | head -n1 | xargs git rev-parse)"
14-
@test "$$(git rev-parse head)" = "$$(git tag | sort -nr | head -n1 | xargs git rev-parse)"
10+
./check-version.sh
1511
make force_release
1612

1713
force_release: clean
18-
# IF we're in a virtual environment, add build tools
19-
test -z "$$VIRTUAL_ENV"|| pip install -U build twine
20-
python3 -m build --sdist --wheel ||echo"Use a virtual-env with 'python -m venv env && source env/bin/activate' instead"
14+
./build-release.sh
2115
twine upload dist/*
2216
git push --tags origin main

‎build-release.sh‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#
3+
# This script builds a release. If run in a venv, it auto-installs its tools.
4+
# You may want to run "make release" instead of running this script directly.
5+
6+
set -eEu
7+
8+
functionrelease_with(){
9+
$1 -m build --sdist --wheel
10+
}
11+
12+
iftest -n "${VIRTUAL_ENV:-}";then
13+
deps=(build twine) # Install twine along with build, as we need it later.
14+
echo"Virtual environment detected. Adding packages: ${deps[*]}"
15+
pip install --quiet --upgrade "${deps[@]}"
16+
echo'Starting the build.'
17+
release_with python
18+
else
19+
functionsuggest_venv(){
20+
venv_cmd='python -m venv env && source env/bin/activate'
21+
printf"HELP: To avoid this error, use a virtual-env with '%s' instead.\n""$venv_cmd"
22+
}
23+
trap suggest_venv ERR # This keeps the original exit (error) code.
24+
echo'Starting the build.'
25+
release_with python3 # Outside a venv, use python3.
26+
fi

‎check-version.sh‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
(0)