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 28, 2024
1 parent 107ce96 commit 567a5db
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 162 deletions.
108 changes: 93 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# These commands on all OS platforms in the active Python environment:
# python
# pip
# twine
# These commands on Linux and macOS:
# uname
# Environment variables:
Expand Down Expand Up @@ -209,7 +208,7 @@ check_py_files := \
$(test_end2end_py_files) \

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

ifdef TESTCASES
pytest_opts := $(TESTOPTS) -k "$(TESTCASES)"
Expand Down Expand Up @@ -254,11 +253,14 @@ help:
@echo ' build - Build the distribution files in $(dist_dir): $(dist_files)'
@echo ' builddoc - Build documentation in: $(doc_build_dir)'
@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 " end2end - Run end2end tests (adds to coverage results)"
@echo " end2end_show - Show HMCs defined for end2end tests"
@echo ' authors - Generate AUTHORS.md file from git log'
@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 " platform - Display the information about the platform as seen by make"
Expand All @@ -282,6 +284,8 @@ help:
@echo " Optional, defaults to 'latest'."
@echo ' PYTHON_CMD=... - Name of python command. Default: python'
@echo ' PIP_CMD=... - Name of pip command. Default: pip'
@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: platform
platform:
Expand Down Expand Up @@ -458,23 +462,97 @@ clean:
@echo 'Done: Cleaned out all temporary files.'
@echo "Makefile: $@ done."

.PHONY: all
all: install develop check_reqs check ruff pylint test build builddoc safety bandit
.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'
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: upload
upload: $(dist_files)
ifeq (,$(findstring .dev,$(package_version)))
@echo '==> This will upload $(package_name) version $(package_version) to PyPI!'
.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'
twine upload $(dist_files)
@echo 'Done: Uploaded $(package_name) version to PyPI: $(package_version)'
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: all
all: install develop check_reqs check ruff pylint test build builddoc safety bandit
@echo "Makefile: $@ done."
else
@echo 'Error: A development version $(package_version) of $(package_name) cannot be uploaded to PyPI!'
@false
endif

$(sdist_file): $(done_dir)/develop_$(pymn)_$(PACKAGE_LEVEL).done pyproject.toml $(dist_dependent_files)
@echo "Makefile: Building the source distribution archive: $(sdist_file)"
Expand Down
2 changes: 2 additions & 0 deletions changes/645.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/645.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/645.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.
5 changes: 0 additions & 5 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ entrypoints>=0.3.0
# Ruff checker (no imports, invoked via ruff script):
ruff>=0.3.5

# Twine (no imports, invoked via twine script):
twine>=3.0.0
# readme-renderer 25.0 or higher is needed to address issue on Windows with py39
readme-renderer>=25.0

# Unit test (indirect dependencies):
pluggy>=1.3.0

Expand Down
Loading

0 comments on commit 567a5db

Please sign in to comment.