Skip to content

Commit a0777aa

Browse files
committed
feat: auto-versioning from git tags and manual bump workflow
- Switch to hatch-vcs for automatic version from git tags - Add bump-version.yml workflow (manual dispatch: patch/minor/major) - Simplify release.yml to use uv build with hatch-vcs - Exclude generated _version.py from git and ruff
1 parent 21588b7 commit a0777aa

4 files changed

Lines changed: 78 additions & 20 deletions

File tree

.github/workflows/bump-version.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Bump Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
jobs:
16+
bump:
17+
name: Bump version and tag
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # Required to read all tags
26+
27+
- name: Get latest version tag
28+
id: current
29+
run: |
30+
TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
31+
echo "tag=${TAG:-v0.0.0}" >> $GITHUB_OUTPUT
32+
echo "Current version: ${TAG:-v0.0.0}"
33+
34+
- name: Calculate next version
35+
id: next
36+
run: |
37+
VERSION="${{ steps.current.outputs.tag }}"
38+
VERSION="${VERSION#v}"
39+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
40+
41+
case "${{ inputs.bump }}" in
42+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
43+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
44+
patch) PATCH=$((PATCH + 1)) ;;
45+
esac
46+
47+
NEXT="v${MAJOR}.${MINOR}.${PATCH}"
48+
echo "version=$NEXT" >> $GITHUB_OUTPUT
49+
echo "Next version: $NEXT"
50+
51+
- name: Create and push tag
52+
run: |
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
git tag -a "${{ steps.next.outputs.version }}" -m "Release ${{ steps.next.outputs.version }}"
56+
git push origin "${{ steps.next.outputs.version }}"
57+
echo "Tagged and pushed ${{ steps.next.outputs.version }}"

.github/workflows/release.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Required for hatch-vcs to resolve version from tags
1921

2022
- name: Set up Python
2123
uses: actions/setup-python@v5
2224
with:
2325
python-version: '3.14'
2426

25-
- name: Install build tools
26-
run: |
27-
python -m pip install --upgrade pip
28-
python -m pip install build
29-
# Ensure git tags are available for versioning
30-
git fetch --prune --unshallow --tags || true
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v3
3129

3230
- name: Build package
33-
run: python -m build
31+
run: uv build
3432

3533
- name: Publish to PyPI
3634
uses: pypa/gh-action-pypi-publish@release/v1
@@ -99,21 +97,19 @@ jobs:
9997

10098
steps:
10199
- uses: actions/checkout@v4
100+
with:
101+
fetch-depth: 0 # Required for hatch-vcs to resolve version from tags
102102

103103
- name: Set up Python
104104
uses: actions/setup-python@v5
105105
with:
106106
python-version: '3.14'
107107

108-
- name: Install build tools
109-
run: |
110-
python -m pip install --upgrade pip
111-
python -m pip install build
112-
# Ensure git tags are available for versioning
113-
git fetch --prune --unshallow --tags || true
108+
- name: Install uv
109+
uses: astral-sh/setup-uv@v3
114110

115111
- name: Build packages
116-
run: python -m build
112+
run: uv build
117113

118114
- name: Upload wheel
119115
uses: actions/upload-artifact@v4
@@ -165,13 +161,10 @@ jobs:
165161
dist/*.whl
166162
dist/*.tar.gz
167163
body: |
168-
## 🚀 Release v${{ steps.version.outputs.VERSION }}
164+
## Release v${{ steps.version.outputs.VERSION }}
169165
170166
### Installation Options:
171167
172-
#### Direct Download
173-
Download the packages attached to this release.
174-
175168
#### PyPI
176169
```bash
177170
# Using uvx (no installation required)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Python
22
__pycache__/
3+
src/pararam_nexus_mcp/_version.py
34
*.py[cod]
45
*$py.class
56
*.so

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pararam-nexus-mcp"
3-
version = "0.1.0"
3+
dynamic = ["version"]
44
description = "Model Context Protocol server for pararam.io - a modern communication and collaboration platform"
55
readme = "README.md"
66
requires-python = ">=3.14"
@@ -55,9 +55,15 @@ dev = [
5555
]
5656

5757
[build-system]
58-
requires = ["hatchling"]
58+
requires = ["hatchling", "hatch-vcs"]
5959
build-backend = "hatchling.build"
6060

61+
[tool.hatch.version]
62+
source = "vcs"
63+
64+
[tool.hatch.build.hooks.vcs]
65+
version-file = "src/pararam_nexus_mcp/_version.py"
66+
6167
[tool.hatch.build.targets.wheel]
6268
packages = ["src/pararam_nexus_mcp"]
6369

@@ -70,6 +76,7 @@ exclude = [
7076
"__pycache__",
7177
"build",
7278
"dist",
79+
"_version.py",
7380
]
7481
line-length = 120
7582
indent-width = 4

0 commit comments

Comments
 (0)