Skip to content

Commit

Permalink
improve release setup based on the one in GitPython
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 17, 2023
1 parent 810ae3a commit ce03fde
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ MANIFEST
*.egg-info
.noseids
*.sublime-workspace
/env/
51 changes: 7 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,12 @@
.PHONY: build sdist cover test clean-files clean-docs doc all
.PHONY: all clean release force_release

all:
$(info Possible targets:)
$(info doc)
$(info clean-docs)
$(info clean-files)
$(info clean)
$(info test)
$(info coverage)
$(info build)
$(info sdist)
@grep -Ee '^[a-z].*:' Makefile | cut -d: -f1 | grep -vF all

doc:
cd doc && make html
clean:
rm -rf build/ dist/ .eggs/ .tox/

clean-docs:
cd doc && make clean

clean-files:
git clean -fx
rm -rf build/ dist/

clean: clean-files clean-docs

test:
pytest

coverage:
pytest --cov smmap --cov-report xml

build:
./setup.py build

sdist:
./setup.py sdist

release: clean
# Check if latest tag is the current head we're releasing
echo "Latest tag = $$(git tag | sort -nr | head -n1)"
echo "HEAD SHA = $$(git rev-parse head)"
echo "Latest tag SHA = $$(git tag | sort -nr | head -n1 | xargs git rev-parse)"
@test "$$(git rev-parse head)" = "$$(git tag | sort -nr | head -n1 | xargs git rev-parse)"
make force_release

force_release:: clean
git push --tags
python3 setup.py sdist bdist_wheel
force_release: clean
./build-release.sh
twine upload dist/*
git push --tags origin main
26 changes: 26 additions & 0 deletions build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#
# This script builds a release. If run in a venv, it auto-installs its tools.
# You may want to run "make release" instead of running this script directly.

set -eEu

function release_with() {
$1 -m build --sdist --wheel
}

if test -n "${VIRTUAL_ENV:-}"; then
deps=(build twine) # Install twine along with build, as we need it later.
echo "Virtual environment detected. Adding packages: ${deps[*]}"
pip install --quiet --upgrade "${deps[@]}"
echo 'Starting the build.'
release_with python
else
function suggest_venv() {
venv_cmd='python -m venv env && source env/bin/activate'
printf "HELP: To avoid this error, use a virtual-env with '%s' instead.\n" "$venv_cmd"
}
trap suggest_venv ERR # This keeps the original exit (error) code.
echo 'Starting the build.'
release_with python3 # Outside a venv, use python3.
fi

0 comments on commit ce03fde

Please sign in to comment.