From ce03fde1a0059f6d7db9cf40b9a9d12b75797e7b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 17 Sep 2023 10:25:42 +0200 Subject: [PATCH] improve release setup based on the one in GitPython --- .gitignore | 1 + Makefile | 51 +++++++----------------------------------------- build-release.sh | 26 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 44 deletions(-) create mode 100755 build-release.sh diff --git a/.gitignore b/.gitignore index 0124754..85cc74f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ MANIFEST *.egg-info .noseids *.sublime-workspace +/env/ diff --git a/Makefile b/Makefile index 051e99b..978632e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build-release.sh b/build-release.sh new file mode 100755 index 0000000..5840e44 --- /dev/null +++ b/build-release.sh @@ -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