-
Notifications
You must be signed in to change notification settings - Fork 1
tooling: Add version bump target to Makefile. #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,6 +89,41 @@ repl: ## Open MicroPython REPL on the board | |||||||||||||||||||||||||||
| mount: ## Mount lib/ on the board for live testing | ||||||||||||||||||||||||||||
| mpremote connect $(PORT) mount lib/ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # --- Release --- | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| PART ?= patch | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| .PHONY: bump | ||||||||||||||||||||||||||||
| bump: ## Create a version tag (PART=patch|minor|major, default: patch) | ||||||||||||||||||||||||||||
| @if [ "$$(git symbolic-ref --short HEAD)" != "main" ]; then \ | ||||||||||||||||||||||||||||
| echo "Error: bump must be run on the main branch."; exit 1; \ | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
| @if [ -n "$$(git status --porcelain)" ]; then \ | ||||||||||||||||||||||||||||
| echo "Error: working tree is not clean. Commit or stash changes first."; exit 1; \ | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
| @LAST=$$(git tag --sort=-v:refname | head -1); \ | ||||||||||||||||||||||||||||
| if [ -z "$$LAST" ]; then \ | ||||||||||||||||||||||||||||
| NEXT="v1.0.0"; \ | ||||||||||||||||||||||||||||
| else \ | ||||||||||||||||||||||||||||
| MAJOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f1); \ | ||||||||||||||||||||||||||||
| MINOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f2); \ | ||||||||||||||||||||||||||||
| PATCH=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f3); \ | ||||||||||||||||||||||||||||
| case "$(PART)" in \ | ||||||||||||||||||||||||||||
| major) MAJOR=$$((MAJOR + 1)); MINOR=0; PATCH=0 ;; \ | ||||||||||||||||||||||||||||
| minor) MINOR=$$((MINOR + 1)); PATCH=0 ;; \ | ||||||||||||||||||||||||||||
| patch) PATCH=$$((PATCH + 1)) ;; \ | ||||||||||||||||||||||||||||
| *) echo "Error: PART must be patch, minor or major."; exit 1 ;; \ | ||||||||||||||||||||||||||||
| esac; \ | ||||||||||||||||||||||||||||
| NEXT="v$$MAJOR.$$MINOR.$$PATCH"; \ | ||||||||||||||||||||||||||||
| fi; \ | ||||||||||||||||||||||||||||
| echo "$$LAST → $$NEXT"; \ | ||||||||||||||||||||||||||||
| sed -i "s/^version = \".*\"/version = \"$${NEXT#v}\"/" pyproject.toml; \ | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| sed -i "s/^version = \".*\"/version = \"$${NEXT#v}\"/" pyproject.toml; \ | |
| VERSION=$${NEXT#v}; \ | |
| python - "$$VERSION" << 'PY'; \ | |
| import sys | |
| import pathlib | |
| import re | |
| path = pathlib.Path("pyproject.toml") | |
| text = path.read_text() | |
| version = sys.argv[1] | |
| text = re.sub(r'^version = ".*"$', f'version = "{version}"', text, count=1, flags=re.MULTILINE) | |
| path.write_text(text) | |
| PY |
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a lightweight tag (git tag "$NEXT"), but the linked issue’s desired behavior calls for an annotated tag. If annotated tags are required for releases, switch to creating an annotated tag (and include a message), so metadata is preserved and git describe behaves as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Push branch and tag atomically in bump target
The git push origin main "$$NEXT" call can partially update the remote: if main is accepted but the tag is rejected (for example because the tag already exists remotely or tag creation is restricted), the bump commit is published without its release tag. git push only guarantees all-or-nothing behavior when --atomic is used, so this target can leave the repository in an inconsistent release state even though it reports failure.
Useful? React with 👍 / 👎.
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this Makefile uses .ONESHELL, the long command chain starting here uses ; separators, so failures from sed, git commit, git tag, or git push may not stop the target (the final echo will still exit 0). Consider enabling fail-fast for this recipe (e.g., set -e at the start of the bump recipe or chaining critical commands with &&) so make bump reliably fails on errors and doesn't leave the repo in a partially-updated state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail bump target when git push errors
The bump recipe runs all release steps in one .ONESHELL block and ends with echo, so a failed git push (e.g., auth issue, network problem, or non-fast-forward) is masked and make bump still exits successfully. This can leave a local commit/tag that was never published while printing a success message, which is risky for release automation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bump logic assumes the latest tag is exactly
v<major>.<minor>.<patch>. If the repo ever has non-semver tags (e.g.,v1.2.3-rc1) or tags without a leadingv,MAJOR/MINOR/PATCHparsing and arithmetic can fail. Add a validation step (regex match) and error out with a clear message whenLASTisn't a supported format.