Skip to content

Commit 60b1a55

Browse files
authored
tooling: Add version bump target to Makefile. (#237)
* tooling: Add version bump target to Makefile. * tooling: Configure semantic-release for automated versioning. * tooling: Address PR review comments on bump target.
1 parent f7b5944 commit 60b1a55

6 files changed

Lines changed: 318 additions & 26 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
release:
14+
name: Semantic Release
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
persist-credentials: false
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
cache: npm
26+
27+
- run: npm ci
28+
29+
- name: Run semantic-release
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: npx semantic-release

.releaserc.json

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
{
2-
"branches": ["main"],
3-
"repositoryUrl": "https://github.com/steamicc/micropython-steami-lib.git",
4-
"debug": false,
5-
"plugins": [
6-
"@semantic-release/commit-analyzer",
7-
"@semantic-release/release-notes-generator",
8-
[
9-
"@semantic-release/changelog",
10-
{
11-
"changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file. See\n[Conventional Commits](https://conventionalcommits.org) for commit guidelines."
12-
}
13-
],
14-
[
15-
"@semantic-release/github",
16-
{
17-
"assets": "pack/*.tgz"
18-
}
19-
],
20-
[
21-
"@semantic-release/git",
22-
{
23-
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
24-
}
25-
]
26-
]
27-
}
2+
"branches": ["main"],
3+
"repositoryUrl": "https://github.com/steamicc/micropython-steami-lib.git",
4+
"tagFormat": "v${version}",
5+
"plugins": [
6+
["@semantic-release/commit-analyzer", {
7+
"releaseRules": [
8+
{"type": "feat", "release": "minor"},
9+
{"type": "fix", "release": "patch"},
10+
{"type": "perf", "release": "patch"},
11+
{"type": "refactor", "release": "patch"},
12+
{"type": "tooling", "release": "patch"},
13+
{"type": "docs", "release": false},
14+
{"type": "style", "release": false},
15+
{"type": "test", "release": false},
16+
{"type": "ci", "release": false},
17+
{"type": "build", "release": false},
18+
{"type": "chore", "release": false}
19+
]
20+
}],
21+
"@semantic-release/release-notes-generator",
22+
["@semantic-release/changelog", {
23+
"changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file.\nSee [Conventional Commits](https://conventionalcommits.org) for commit guidelines."
24+
}],
25+
["@semantic-release/exec", {
26+
"prepareCmd": "sed -i 's/^version = \".*\"/version = \"${nextRelease.version}\"/' pyproject.toml"
27+
}],
28+
["@semantic-release/git", {
29+
"assets": ["CHANGELOG.md", "pyproject.toml"],
30+
"message": "chore(release): v${nextRelease.version}. [skip ci]\n\n${nextRelease.notes}"
31+
}],
32+
"@semantic-release/github"
33+
]
34+
}

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ 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+
Releases are handled automatically by [semantic-release](https://semantic-release.gitbook.io/) when commits are pushed to `main`. The version is determined from commit messages:
109+
110+
- `fix:` → patch bump (v1.0.0 → v1.0.1)
111+
- `feat:` → minor bump (v1.0.0 → v1.1.0)
112+
- `BREAKING CHANGE:` in commit body → major bump (v1.0.0 → v2.0.0)
113+
- `docs:`, `style:`, `test:`, `ci:`, `chore:` → no release
114+
115+
semantic-release automatically updates `pyproject.toml`, generates `CHANGELOG.md`, creates a git tag, and publishes a GitHub release.
116+
117+
To force a specific version manually (override):
118+
119+
```bash
120+
make bump # patch: v1.0.0 → v1.0.1
121+
make bump PART=minor # minor: v1.0.1 → v1.1.0
122+
make bump PART=major # major: v1.1.0 → v2.0.0
123+
```
124+
106125
## Notes
107126

108127
* Keep implementations simple and readable

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,48 @@ 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+
@echo "Note: releases are normally handled by semantic-release in CI."
99+
@echo "Use 'make bump' only to force a specific version.\n"
100+
@if [ "$$(git symbolic-ref --short HEAD)" != "main" ]; then \
101+
echo "Error: bump must be run on the main branch."; exit 1; \
102+
fi
103+
@if [ -n "$$(git status --porcelain)" ]; then \
104+
echo "Error: working tree is not clean. Commit or stash changes first."; exit 1; \
105+
fi
106+
@set -e; \
107+
LAST=$$(git tag --sort=-v:refname | head -1); \
108+
if [ -z "$$LAST" ]; then \
109+
NEXT="v1.0.0"; \
110+
else \
111+
if ! echo "$$LAST" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$'; then \
112+
echo "Error: latest tag '$$LAST' is not in supported format v<major>.<minor>.<patch>."; exit 1; \
113+
fi; \
114+
MAJOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f1); \
115+
MINOR=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f2); \
116+
PATCH=$$(echo "$$LAST" | sed 's/^v//' | cut -d. -f3); \
117+
case "$(PART)" in \
118+
major) MAJOR=$$((MAJOR + 1)); MINOR=0; PATCH=0 ;; \
119+
minor) MINOR=$$((MINOR + 1)); PATCH=0 ;; \
120+
patch) PATCH=$$((PATCH + 1)) ;; \
121+
*) echo "Error: PART must be patch, minor or major."; exit 1 ;; \
122+
esac; \
123+
NEXT="v$$MAJOR.$$MINOR.$$PATCH"; \
124+
fi; \
125+
echo "$$LAST → $$NEXT"; \
126+
VERSION=$${NEXT#v}; \
127+
python3 -c "import re, pathlib; p=pathlib.Path('pyproject.toml'); p.write_text(re.sub(r'^version = \".*\"', 'version = \"$$VERSION\"', p.read_text(), count=1, flags=re.MULTILINE))"; \
128+
git add pyproject.toml; \
129+
git commit -m "chore: Bump version to $$NEXT."; \
130+
git tag -a "$$NEXT" -m "Release $$NEXT"; \
131+
git push origin main "$$NEXT"; \
132+
echo "Tag $$NEXT pushed to origin."
133+
92134
# --- Utilities ---
93135

94136
.PHONY: clean

package-lock.json

Lines changed: 190 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"@commitlint/cz-commitlint": "^20.5.0",
2121
"@semantic-release/changelog": "^6.0.3",
2222
"@semantic-release/commit-analyzer": "^13.0.0",
23+
"@semantic-release/exec": "^7.1.0",
2324
"@semantic-release/git": "^10.0.1",
2425
"@semantic-release/github": "^11.0.0",
2526
"commitizen": "^4.2.4",
27+
"conventional-changelog-conventionalcommits": "^9.3.0",
2628
"cross-env": "^7.0.3",
2729
"git-precommit-checks": "^3.1.0",
2830
"husky": "^9.1.7",

0 commit comments

Comments
 (0)