Skip to content

Commit d3c74eb

Browse files
authored
feat: use hatch-vcs + tag workflow (#171)
1 parent 44cb295 commit d3c74eb

3 files changed

Lines changed: 17 additions & 45 deletions

File tree

.github/workflows/zarr-metadata-release.yml

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
11
name: zarr-metadata release
22

3-
# Manual-only release for now. Once we settle on a tag scheme
4-
# (e.g. `zarr-metadata/v0.1.0`), this workflow can grow a
5-
# `release:` or `push: tags:` trigger.
6-
#
7-
# Operator picks the target index at dispatch time:
8-
# - `pypi` -> https://pypi.org
9-
# - `testpypi` -> https://test.pypi.org
10-
#
11-
# Both indexes reject re-uploads of an existing version, so each publish
12-
# requires a version bump in pyproject.toml. For TestPyPI dry-runs, use a
13-
# PEP 440 pre-release/dev suffix (e.g. `0.1.0.dev1`) in the source.
143
on:
154
workflow_dispatch:
16-
inputs:
17-
target:
18-
description: 'Index to publish to'
19-
required: true
20-
type: choice
21-
default: testpypi
22-
options:
23-
- testpypi
24-
- pypi
5+
release:
6+
types: [published]
257

268
permissions:
279
contents: read
2810

2911
concurrency:
30-
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.target }}
12+
group: ${{ github.workflow }}-${{ github.ref }}
3113
cancel-in-progress: false
3214

3315
jobs:
@@ -42,6 +24,7 @@ jobs:
4224
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4325
with:
4426
persist-credentials: false
27+
fetch-depth: 0 # hatch-vcs needs full history + tags
4528

4629
- name: Install Hatch
4730
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
@@ -66,9 +49,6 @@ jobs:
6649
name: zarr-metadata-dist
6750
path: dist
6851

69-
- name: List built artifacts
70-
run: ls -la dist
71-
7252
- name: Install uv
7353
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
7454

@@ -79,12 +59,12 @@ jobs:
7959
run: |
8060
wheel=$(ls dist/*.whl)
8161
uv run --with "${wheel}" --python 3.12 --no-project \
82-
python -c "import zarr_metadata; print('zarr_metadata', zarr_metadata.__version__)"
62+
python -c "import zarr_metadata"
8363
8464
upload_pypi:
8565
name: Upload to PyPI
8666
needs: [build, test_artifacts]
87-
if: inputs.target == 'pypi'
67+
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'zarr_metadata/')
8868
runs-on: ubuntu-latest
8969
environment:
9070
name: zarr-metadata-releases
@@ -109,7 +89,7 @@ jobs:
10989
upload_testpypi:
11090
name: Upload to TestPyPI
11191
needs: [build, test_artifacts]
112-
if: inputs.target == 'testpypi'
92+
if: github.event_name == 'workflow_dispatch'
11393
runs-on: ubuntu-latest
11494
environment:
11595
name: zarr-metadata-releases-test

packages/zarr-metadata/pyproject.toml

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

55
[project]
66
name = "zarr-metadata"
7-
version = "0.1.0"
7+
dynamic = ["version"]
88
description = "Spec-defined metadata types for Zarr v2 and v3."
99
readme = "README.md"
1010
requires-python = ">=3.11"
@@ -32,6 +32,14 @@ dependencies = [
3232
[dependency-groups]
3333
test = ["pytest", "pydantic>=2"]
3434

35+
[tool.hatch.version]
36+
source = "vcs"
37+
tag-pattern = '^zarr_metadata/v(?P<version>.+)$'
38+
# `git_describe_command` ensures we get the zarr_metadata tags instead of latest.
39+
# `local_scheme` strips the git commit info so the appending info is just a counter from latest tag.
40+
# test-pypi doesn't accept git commit info in tags, and the count should be enough to distinguish unique runs.
41+
raw-options = { root = "../..", git_describe_command = "git describe --dirty --tags --long --match zarr_metadata/v*", local_scheme = "no-local-version" }
42+
3543
[tool.hatch.build.targets.wheel]
3644
packages = ["src/zarr_metadata"]
3745

packages/zarr-metadata/tests/test_version.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)