Skip to content

Commit

Permalink
Simplified release and start of a new version
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Sep 29, 2024
1 parent 379da5c commit 076b92b
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 168 deletions.
105 changes: 92 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ruff_rc_file := .ruff.toml
pylint_rc_file := .pylintrc

# Packages whose dependencies are checked using pip-missing-reqs
check_reqs_packages := pip_check_reqs pipdeptree build pytest coverage coveralls flake8 ruff pylint safety bandit twine towncrier
check_reqs_packages := pip_check_reqs pipdeptree build pytest coverage coveralls flake8 ruff pylint safety bandit towncrier

ifdef TESTCASES
pytest_opts := $(TESTOPTS) -k $(TESTCASES)
Expand Down Expand Up @@ -226,8 +226,11 @@ help:
@echo ' builddoc - Build documentation in: $(doc_build_dir)'
@echo ' authors - Generate AUTHORS.md file from git log'
@echo ' all - Do all of the above'
@echo " release_branch - Create a release branch when releasing a version (requires VERSION and optionally BRANCH to be set)"
@echo " release_publish - Publish to PyPI when releasing a version (requires VERSION and optionally BRANCH to be set)"
@echo " start_branch - Create a start branch when starting a new version (requires VERSION and optionally BRANCH to be set)"
@echo " start_tag - Create a start tag when starting a new version (requires VERSION and optionally BRANCH to be set)"
@echo ' uninstall - Uninstall package from active Python environment'
@echo ' upload - Upload the distribution files to PyPI (includes uninstall+build)'
@echo ' clean - Remove any temporary files'
@echo ' clobber - Remove any build products (includes uninstall+clean)'
@echo ' pyshow - Show location and version of the python and pip commands'
Expand All @@ -238,6 +241,8 @@ help:
@echo ' PIP_CMD=... - Name of pip command. Default: pip'
@echo ' TESTCASES=... - Testcase filter for pytest -k'
@echo ' TESTOPTS=... - Options for pytest'
@echo " VERSION=... - M.N.U version to be released or started"
@echo " BRANCH=... - Name of branch to be released or started (default is derived from VERSION)"

.PHONY: develop
develop: $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done
Expand Down Expand Up @@ -279,19 +284,93 @@ builddoc: $(doc_build_file)
all: install develop check_reqs check test build builddoc authors
@echo '$@ done.'

.PHONY: upload
upload: _check_version uninstall $(bdist_file) $(sdist_file)
ifeq (,$(findstring .dev,$(package_version)))
@echo '==> This will upload $(package_name) version $(package_version) to PyPI!'
.PHONY: release_branch
release_branch:
@bash -c 'if [ -z "$(VERSION)" ]; then echo ""; echo "Error: VERSION env var is not set"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git status -s)" ]; then echo ""; echo "Error: Local git repo has uncommitted files:"; echo ""; git status; false; fi'
git fetch origin
@bash -c 'if [ -z "$$(git tag -l $(VERSION)a0)" ]; then echo ""; echo "Error: Release start tag $(VERSION)a0 does not exist (the version has not been started)"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git tag -l $(VERSION))" ]; then echo ""; echo "Error: Release tag $(VERSION) already exists (the version has already been released)"; echo ""; false; fi'
@bash -c 'if [[ -n "$${BRANCH}" ]]; then echo $${BRANCH} >branch.tmp; elif [[ "$${VERSION#*.*.}" == "0" ]]; then echo "master" >branch.tmp; else echo "stable_$${VERSION%.*}" >branch.tmp; fi'
@bash -c 'if [ -z "$$(git branch --contains $(VERSION)a0 $$(cat branch.tmp))" ]; then echo ""; echo "Error: Release start tag $(VERSION)a0 is not in target branch $$(cat branch.tmp), but in:"; echo ""; git branch --contains $(VERSION)a0;. false; fi'
@echo "==> This will start the release of $(package_name) version $(VERSION) to PyPI using target branch $$(cat branch.tmp)"
@echo -n '==> Continue? [yN] '
@bash -c 'read answer; if [ "$$answer" != "y" ]; then echo "Aborted."; false; fi'
twine upload $(bdist_file) $(sdist_file)
@echo 'Done: Uploaded $(package_name) version to PyPI: $(package_version)'
@echo '$@ done.'
else
@echo 'Error: A development version $(package_version) of $(package_name) cannot be uploaded to PyPI!'
@false
endif
bash -c 'git checkout $$(cat branch.tmp)'
git pull
@bash -c 'if [ -z "$$(git branch -l release_$(VERSION))" ]; then echo "Creating release branch release_$(VERSION)"; git checkout -b release_$(VERSION); fi'
git checkout release_$(VERSION)
make authors
towncrier build --version $(VERSION) --yes
git commit -asm "Release $(VERSION)"
git push --set-upstream origin release_$(VERSION)
rm -f branch.tmp
@echo "Done: Pushed the release branch to GitHub - now go there and create a PR."
@echo "Makefile: $@ done."

.PHONY: release_publish
release_publish:
@bash -c 'if [ -z "$(VERSION)" ]; then echo ""; echo "Error: VERSION env var is not set"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git status -s)" ]; then echo ""; echo "Error: Local git repo has uncommitted files:"; echo ""; git status; false; fi'
git fetch origin
@bash -c 'if [ -n "$$(git tag -l $(VERSION))" ]; then echo ""; echo "Error: Release tag $(VERSION) already exists (the version has already been released)"; echo ""; false; fi'
@bash -c 'if [[ -n "$${BRANCH}" ]]; then echo $${BRANCH} >branch.tmp; elif [[ "$${VERSION#*.*.}" == "0" ]]; then echo "master" >branch.tmp; else echo "stable_$${VERSION%.*}" >branch.tmp; fi'
@bash -c 'if [ "$$(git log --format=format:%s $$(cat branch.tmp)~..$$(cat branch.tmp))" != "Release $(VERSION)" ]; then echo ""; echo "Error: Release branch has not been created yet"; echo ""; false; fi'
@echo "==> This will publish $(package_name) version $(VERSION) to PyPI using target branch $$(cat branch.tmp)"
@echo -n '==> Continue? [yN] '
@bash -c 'read answer; if [ "$$answer" != "y" ]; then echo "Aborted."; false; fi'
bash -c 'git checkout $$(cat branch.tmp)'
git pull
git tag -f $(VERSION)
git push -f --tags
git branch -D release_$(VERSION)
git branch -D -r origin/release_$(VERSION)
rm -f branch.tmp
@echo "Done: Triggered the publish workflow - now wait for it to finish and verify the publishing."
@echo "Makefile: $@ done."

.PHONY: start_branch
start_branch:
@bash -c 'if [ -z "$(VERSION)" ]; then echo ""; echo "Error: VERSION env var is not set"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git status -s)" ]; then echo ""; echo "Error: Local git repo has uncommitted files:"; echo ""; git status; false; fi'
git fetch origin
@bash -c 'if [ -n "$$(git tag -l $(VERSION))" ]; then echo ""; echo "Error: Release tag $(VERSION) already exists (the version has already been released)"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git tag -l $(VERSION)a0)" ]; then echo ""; echo "Error: Release start tag $(VERSION)a0 already exists (the new version has alreay been started)"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git branch -l start_$(VERSION))" ]; then echo ""; echo "Error: Start branch start_$(VERSION) already exists (the start of the new version is already underway)"; echo ""; false; fi'
@bash -c 'if [[ -n "$${BRANCH}" ]]; then echo $${BRANCH} >branch.tmp; elif [[ "$${VERSION#*.*.}" == "0" ]]; then echo "master" >branch.tmp; else echo "stable_$${VERSION%.*}" >branch.tmp; fi'
@echo "==> This will start new version $(VERSION) using target branch $$(cat branch.tmp)"
@echo -n '==> Continue? [yN] '
@bash -c 'read answer; if [ "$$answer" != "y" ]; then echo "Aborted."; false; fi'
bash -c 'git checkout $$(cat branch.tmp)'
git pull
git checkout -b start_$(VERSION)
echo "Dummy change for starting new version $(VERSION)" >changes/noissue.$(VERSION).notshown.rst
git add changes/noissue.$(VERSION).notshown.rst
git commit -asm "Start $(VERSION)"
git push --set-upstream origin start_$(VERSION)
@echo "Done: Pushed the start branch to GitHub - now go there and create a PR."
@echo "Makefile: $@ done."

.PHONY: start_tag
start_tag:
@bash -c 'if [ -z "$(VERSION)" ]; then echo ""; echo "Error: VERSION env var is not set"; echo ""; false; fi'
@bash -c 'if [ -n "$$(git status -s)" ]; then echo ""; echo "Error: Local git repo has uncommitted files:"; echo ""; git status; false; fi'
git fetch origin
@bash -c 'if [ -n "$$(git tag -l $(VERSION)a0)" ]; then echo ""; echo "Error: Release start tag $(VERSION)a0 already exists (the new version has alreay been started)"; echo ""; false; fi'
@bash -c 'if [[ -n "$${BRANCH}" ]]; then echo $${BRANCH} >branch.tmp; elif [[ "$${VERSION#*.*.}" == "0" ]]; then echo "master" >branch.tmp; else echo "stable_$${VERSION%.*}" >branch.tmp; fi'
@bash -c 'if [ "$$(git log --format=format:%s $$(cat branch.tmp)~..$$(cat branch.tmp))" != "Start $(VERSION)" ]; then echo ""; echo "Error: Start branch $$(cat branch.tmp) has not been created yet"; echo ""; false; fi'
@echo "==> This will complete the start of new version $(VERSION) using target branch $$(cat branch.tmp)"
@echo -n '==> Continue? [yN] '
@bash -c 'read answer; if [ "$$answer" != "y" ]; then echo "Aborted."; false; fi'
bash -c 'git checkout $$(cat branch.tmp)'
git pull
git tag -f $(VERSION)a0
git push -f --tags
git branch -D start_$(VERSION)
git branch -D -r origin/start_$(VERSION)
rm -f branch.tmp
@echo "Done: Pushed the release start tag and cleaned up the release start branch."
@echo "Makefile: $@ done."

.PHONY: uninstall
uninstall:
Expand Down
2 changes: 2 additions & 0 deletions changes/70.cleanup.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dev: Dropped the 'make upload' target, because the release to PyPI has
been migrated to using a publish workflow.
3 changes: 3 additions & 0 deletions changes/70.feature.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dev: Encapsulated the releasing of a version to PyPI into new 'release_branch'
and 'release_publish' make targets. See the development documentation for
details.
2 changes: 2 additions & 0 deletions changes/70.feature.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dev: Encapsulated the starting of a new version into new 'start_branch' and
'start_tag' make targets. See the development documentation for details.
Loading

0 comments on commit 076b92b

Please sign in to comment.