-
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Semantic Release | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: npm | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Run semantic-release | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: npx semantic-release |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,34 @@ | ||
| { | ||
| "branches": ["main"], | ||
| "repositoryUrl": "https://github.com/steamicc/micropython-steami-lib.git", | ||
| "debug": false, | ||
| "plugins": [ | ||
| "@semantic-release/commit-analyzer", | ||
| "@semantic-release/release-notes-generator", | ||
| [ | ||
| "@semantic-release/changelog", | ||
| { | ||
| "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." | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/github", | ||
| { | ||
| "assets": "pack/*.tgz" | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/git", | ||
| { | ||
| "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
| } | ||
| ] | ||
| ] | ||
| } | ||
| "branches": ["main"], | ||
| "repositoryUrl": "https://github.com/steamicc/micropython-steami-lib.git", | ||
| "tagFormat": "v${version}", | ||
| "plugins": [ | ||
| ["@semantic-release/commit-analyzer", { | ||
| "releaseRules": [ | ||
| {"type": "feat", "release": "minor"}, | ||
| {"type": "fix", "release": "patch"}, | ||
| {"type": "perf", "release": "patch"}, | ||
| {"type": "refactor", "release": "patch"}, | ||
| {"type": "tooling", "release": "patch"}, | ||
| {"type": "docs", "release": false}, | ||
| {"type": "style", "release": false}, | ||
| {"type": "test", "release": false}, | ||
| {"type": "ci", "release": false}, | ||
| {"type": "build", "release": false}, | ||
| {"type": "chore", "release": false} | ||
| ] | ||
| }], | ||
| "@semantic-release/release-notes-generator", | ||
| ["@semantic-release/changelog", { | ||
| "changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file.\nSee [Conventional Commits](https://conventionalcommits.org) for commit guidelines." | ||
| }], | ||
| ["@semantic-release/exec", { | ||
| "prepareCmd": "sed -i 's/^version = \".*\"/version = \"${nextRelease.version}\"/' pyproject.toml" | ||
| }], | ||
| ["@semantic-release/git", { | ||
| "assets": ["CHANGELOG.md", "pyproject.toml"], | ||
| "message": "chore(release): v${nextRelease.version}. [skip ci]\n\n${nextRelease.notes}" | ||
| }], | ||
| "@semantic-release/github" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,48 @@ 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) | ||
| @echo "Note: releases are normally handled by semantic-release in CI." | ||
| @echo "Use 'make bump' only to force a specific version.\n" | ||
| @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 | ||
| @set -e; \ | ||
| LAST=$$(git tag --sort=-v:refname | head -1); \ | ||
| if [ -z "$$LAST" ]; then \ | ||
| NEXT="v1.0.0"; \ | ||
| else \ | ||
| if ! echo "$$LAST" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$'; then \ | ||
| echo "Error: latest tag '$$LAST' is not in supported format v<major>.<minor>.<patch>."; exit 1; \ | ||
| fi; \ | ||
| 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"; \ | ||
| VERSION=$${NEXT#v}; \ | ||
| 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))"; \ | ||
| git add pyproject.toml; \ | ||
| git commit -m "chore: Bump version to $$NEXT."; \ | ||
| git tag -a "$$NEXT" -m "Release $$NEXT"; \ | ||
| git push origin main "$$NEXT"; \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
| echo "Tag $$NEXT pushed to origin." | ||
|
Comment on lines
+131
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
|
|
||
| # --- Utilities --- | ||
|
|
||
| .PHONY: clean | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.