Last active
January 12, 2024 18:14
-
-
Save mzpqnxow/a74071d2e479fb3a1c6d97e647f06a10 to your computer and use it in GitHub Desktop.
target for a Makefile for an `autombump and publish to PyPi/Artifactory` Makefile (via versioneer and git)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# | |
# ... | |
# The release target will do the following: | |
# - Bump your current *3 digit* git tag (you *MUST* be using x.y.z format) by git tagging | |
# `make release bump=major` | |
# `make release bump=minor` | |
# `make release` | |
# - Build/publish your Python package via setuptools, dynamically inserting the bumped | |
# version (so no need to update or track a version in setup.py) | |
# - Push the newly updated tags to git | |
# | |
# NOTES: | |
# 1. Requires versioneer, which is very easy to set up. See https://github.com/warner/python-versioneer | |
# 2. The default bump is the lease significant version number, referreed to usually as | |
# the patch number. Other you can explicitly choose major and minor. | |
# 3. You should add twine to do the uploading to PyPi/Artifactory, because it requires/enforces TLS and | |
# permits signing of package releases | |
# | |
# So, in full context, this is just a target in a Makefile of a Python package that has already been initialized | |
# with versioneer, and is checked out of and managed from github. **YOU MUST TAG IT AT LEAST ONCE WITH A 3 DIGIT | |
# VERSION via `git tag 0.0.1` or I don't know what will happen | |
# | |
# The autobumb logic was partially or in whole stolen from StackOverflow!! | |
# | |
release: | |
$(eval v := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//')) | |
ifeq ($(bump), major) | |
$(eval f := 1) | |
else ifeq ($(bump), minor) | |
$(eval f := 2) | |
else | |
$(eval f := 3) | |
endif | |
git tag `echo $(v) | awk -F. -v OFS=. -v f=$(f) '{ $$f++ } 1'` | |
# The *old* way ... | |
# python setup.py sdist upload -r local | |
# The *new* way w/twine | |
python setup.py sdist || (rm -rf dist/ ; echo Failed to build sdist ; /bin/false) | |
twine upload -r local dist/* --verbose || rm -rf dist | |
git commit -am "Bumped to version `echo $(v) | awk -F. -v OFS=. -v f=$(f) '{ $$f++ } 1'`" | |
git push || /bin/true | |
git push --tags | |
# | |
# ... | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment