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 <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Sep 28, 2024
1 parent ec67464 commit fc1300f
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 171 deletions.
114 changes: 97 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,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

# Ruff config file
ruff_rc_file := .ruff.toml
Expand Down Expand Up @@ -213,9 +213,12 @@ help:
@echo " build - Build the distribution files in $(dist_dir)"
@echo " builddoc - Build the 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 " docker - Build local Docker image in registry $(docker_registry) and run it to show version"
@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 @@ -228,8 +231,10 @@ help:
@echo " latest - Latest package versions available on Pypi"
@echo " minimum - A minimum version as defined in minimum-constraints-*.txt"
@echo " Optional, defaults to 'latest'."
@echo ' PYTHON_CMD=... - Name of python command. Default: python'
@echo ' PIP_CMD=... - Name of pip command. Default: pip'
@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 @@ -366,6 +371,94 @@ builddoc: $(doc_build_file)
all: install develop check_reqs check ruff pylint test build builddoc check_reqs safety bandit
@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: all
docker: $(done_dir)/docker_$(pymn)_$(PACKAGE_LEVEL).done
@echo "Makefile: $@ done."
Expand All @@ -384,19 +477,6 @@ AUTHORS.md: _always
echo '```' >>AUTHORS.md.tmp
sh -c "if ! diff -q AUTHORS.md.tmp AUTHORS.md; then mv AUTHORS.md.tmp AUTHORS.md; else rm AUTHORS.md.tmp; fi"

.PHONY: upload
upload: $(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/617.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/617.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/617.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.
6 changes: 0 additions & 6 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ sphinxcontrib-websupport>=1.2.4
autodocsumm>=0.2.12
Babel>=2.11.0

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

# Package dependency management tools (not used by any make rules)
pipdeptree>=2.2.0
# pip-check-reqs 2.4.3 fixes a speed issue on Python 3.11 and requires pip>=21.2.4
Expand Down
Loading

0 comments on commit fc1300f

Please sign in to comment.