Skip to content

Commit 03ec089

Browse files
committed
Adopt hatch-vcs for git-tag-driven versioning
1 parent 354dc62 commit 03ec089

8 files changed

Lines changed: 23 additions & 33 deletions

File tree

.github/workflows/lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
steps:
4242
- name: Checkout Code
4343
uses: actions/checkout@v6
44+
with:
45+
fetch-depth: 0
4446

4547
- name: Setup uv
4648
uses: astral-sh/setup-uv@v7

.github/workflows/pytest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
steps:
4343
- name: Checkout Code
4444
uses: actions/checkout@v6
45+
with:
46+
fetch-depth: 0
4547

4648
- name: Setup uv
4749
uses: astral-sh/setup-uv@v7

.github/workflows/release.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,17 @@ on:
66
- "*.*.*"
77

88
jobs:
9-
validate-version:
10-
if: github.repository == 'sapporo-wes/sapporo-service'
11-
runs-on: ubuntu-24.04
12-
steps:
13-
- name: Checkout Code
14-
uses: actions/checkout@v6
15-
16-
- name: Verify tag matches pyproject.toml version
17-
run: |
18-
TAG="${GITHUB_REF_NAME}"
19-
PKG_VERSION=$(python3 -c "
20-
import tomllib
21-
with open('pyproject.toml', 'rb') as f:
22-
print(tomllib.load(f)['project']['version'])
23-
")
24-
if [ "$TAG" != "$PKG_VERSION" ]; then
25-
echo "::error::Tag '$TAG' does not match pyproject.toml version '$PKG_VERSION'"
26-
exit 1
27-
fi
28-
echo "Version check passed: $TAG == $PKG_VERSION"
29-
309
pypi-publish:
3110
if: github.repository == 'sapporo-wes/sapporo-service'
32-
needs: [validate-version]
3311
runs-on: ubuntu-24.04
3412
permissions:
3513
contents: read
3614
id-token: write
3715
steps:
3816
- name: Checkout Code
3917
uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
4020

4121
- name: Setup uv
4222
uses: astral-sh/setup-uv@v7
@@ -60,7 +40,6 @@ jobs:
6040

6141
docker-push:
6242
if: github.repository == 'sapporo-wes/sapporo-service'
63-
needs: [validate-version]
6443
runs-on: ubuntu-24.04
6544
permissions:
6645
contents: read

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ __marimo__/
219219
.streamlit/secrets.toml
220220

221221
# Project specific
222+
sapporo/_version.py
222223
runs/
223224
keycloak-data/
224225
tests/htmlcov/

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ WORKDIR /app
3636

3737
COPY pyproject.toml uv.lock README.md ./
3838

39+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION}
40+
3941
# Named volume inherits image permissions on first creation;
4042
# make writable so arbitrary UID (dev) can run uv commands.
4143
RUN uv sync --frozen --all-extras && \

docs/development.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,22 @@ To bump the spec version:
168168

169169
### Version Management
170170

171-
- The `version` field in `pyproject.toml` is the single source of truth
171+
- The git tag is the single source of truth for the package version (`hatch-vcs`)
172172
- At runtime, the version is obtained via `importlib.metadata.version("sapporo")`
173-
- Docker image version is injected by CI from the tag name with `--build-arg VERSION=...`
173+
- Docker image version is injected by CI from the tag name with `--build-arg VERSION=...` and `SETUPTOOLS_SCM_PRETEND_VERSION`
174174

175175
### Release Steps
176176

177-
1. Update `version` in `pyproject.toml` on the `develop` branch and run `uv lock`
178-
2. Create a PR from `develop` to `main` and merge
179-
3. Create a version tag on the `main` branch:
177+
1. Create a PR to `main` and merge
178+
2. Create a version tag on the `main` branch and push:
180179

181180
```bash
182181
git checkout main && git pull
183182
git tag X.Y.Z
184183
git push origin X.Y.Z
185184
```
186185

187-
4. The tag push triggers `release.yml` automatically:
188-
- Version consistency check (tag == pyproject.toml version)
186+
3. The tag push triggers `release.yml` automatically:
189187
- Publish PyPI package (Trusted Publishing)
190188
- Build and push multi-architecture Docker image (ghcr.io)
191189
- Create GitHub Release (auto-generated release notes)

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
66
name = "sapporo"
7-
version = "2.2.0"
7+
dynamic = ["version"]
88
authors = [
99
{ name = "DDBJ (Bioinformatics and DDBJ Center)", email = "tazro.ohta@chiba-u.jp" },
1010
]
@@ -67,6 +67,13 @@ tests = [
6767
sapporo = "sapporo.app:main"
6868
sapporo-cli = "sapporo.cli:main"
6969

70+
[tool.hatch.version]
71+
source = "vcs"
72+
fallback-version = "0.0.0"
73+
74+
[tool.hatch.build.hooks.vcs]
75+
version-file = "sapporo/_version.py"
76+
7077
[tool.hatch.build.targets.wheel]
7178
packages = ["sapporo"]
7279

uv.lock

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

0 commit comments

Comments
 (0)