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 5025f45 commit 9257dad
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 213 deletions.
111 changes: 96 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ check_py_files := \
done_dir := done

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

# Safety policy file
safety_install_policy_file := .safety-policy-install.yml
Expand Down Expand Up @@ -208,8 +208,12 @@ help:
@echo " builddoc - Build the documentation in $(doc_build_dir)"
@echo " all - Do all of the above"
@echo " docker - Build local Docker image $(docker_image_name):$(docker_image_tag)"
@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 " docker - Build local Docker image in registry $(docker_registry)"
@echo " authors - Generate AUTHORS.md file from git log"
@echo " upload - Upload the package to Pypi"
@echo " clean - Remove any temporary files"
@echo " clobber - Remove any build products"
@echo " platform - Display the information about the platform as seen by make"
Expand All @@ -222,6 +226,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 @@ -314,6 +320,94 @@ builddoc: _check_version $(doc_build_file)
all: install develop check_reqs check pylint test build builddoc check_reqs
@echo "Makefile: $@ done."

.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: 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: docker
docker: _check_version $(done_dir)/docker_$(pymn)_$(PACKAGE_LEVEL).done
@echo "Makefile: $@ done."
Expand All @@ -328,19 +422,6 @@ authors: _check_version
echo '```' >>AUTHORS.md
@echo '$@ done.'

.PHONY: upload
upload: _check_version $(bdist_file) $(sdist_file)
ifeq (,$(findstring .dev,$(package_version)))
@echo "==> This will upload $(package_name) version $(package_version) to PyPI!"
@echo -n "==> Continue? [yN] "
@bash -c 'read answer; if [ "$$answer" != "y" ]; then echo "Aborted."; false; fi'
twine upload $(bdist_file) $(sdist_file)
@echo "Makefile: Done: Uploaded $(package_name) version to PyPI: $(package_version)"
else
@echo "Error: A development version $(package_version) of $(package_name) cannot be uploaded to PyPI!"
@false
endif

.PHONY: clean
clean:
-$(call RM_R_FUNC,*.pyc)
Expand Down
2 changes: 2 additions & 0 deletions changes/97.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/97.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/97.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 9257dad

Please sign in to comment.