Skip to content

Commit 161cf42

Browse files
committed
tooling: Add version bump target to Makefile.
1 parent f7b5944 commit 161cf42

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ All pull requests must pass these checks:
103103
| Mock tests | `tests.yml` | Runs mock driver tests |
104104
| Example validation | `tests.yml` | Validates example files syntax and imports |
105105

106+
## Releasing
107+
108+
Version tags are created with `make bump`:
109+
110+
```bash
111+
make bump # patch: v1.0.0 → v1.0.1
112+
make bump PART=minor # minor: v1.0.1 → v1.1.0
113+
make bump PART=major # major: v1.1.0 → v2.0.0
114+
```
115+
116+
This will:
117+
1. Check you are on `main` with a clean working tree
118+
2. Compute the next version from the latest git tag
119+
3. Update `pyproject.toml` version
120+
4. Commit, tag, and push to origin
121+
106122
## Notes
107123

108124
* Keep implementations simple and readable

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,41 @@ repl: ## Open MicroPython REPL on the board
8989
mount: ## Mount lib/ on the board for live testing
9090
mpremote connect $(PORT) mount lib/
9191

92+
# --- Release ---
93+
94+
PART ?= patch
95+
96+
.PHONY: bump
97+
bump: ## Create a version tag (PART=patch|minor|major, default: patch)
98+
@if [ "$$(git symbolic-ref --short HEAD)" != "main" ]; then \
99+
echo "Error: bump must be run on the main branch."; exit 1; \
100+
fi
101+
@if [ -n "$$(git status --porcelain)" ]; then \
102+
echo "Error: working tree is not clean. Commit or stash changes first."; exit 1; \
103+
fi
104+
@LAST=$$(git tag --sort=-v:refname | head -1); \
105+
if [ -z "$$LAST" ]; then \
106+
NEXT="v1.0.0"; \
107+
else \
108+
MAJOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f1); \
109+
MINOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f2); \
110+
PATCH=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f3); \
111+
case "$(PART)" in \
112+
major) MAJOR=$$((MAJOR + 1)); MINOR=0; PATCH=0 ;; \
113+
minor) MINOR=$$((MINOR + 1)); PATCH=0 ;; \
114+
patch) PATCH=$$((PATCH + 1)) ;; \
115+
*) echo "Error: PART must be patch, minor or major."; exit 1 ;; \
116+
esac; \
117+
NEXT="v$$MAJOR.$$MINOR.$$PATCH"; \
118+
fi; \
119+
echo "$$LAST → $$NEXT"; \
120+
sed -i "s/^version = \".*\"/version = \"$${NEXT#v}\"/" pyproject.toml; \
121+
git add pyproject.toml; \
122+
git commit -m "chore: Bump version to $$NEXT."; \
123+
git tag "$$NEXT"; \
124+
git push origin main "$$NEXT"; \
125+
echo "Tag $$NEXT pushed to origin."
126+
92127
# --- Utilities ---
93128

94129
.PHONY: clean

0 commit comments

Comments
 (0)