Skip to content

Commit f2321ec

Browse files
d-v-bilan-gold
andauthored
chore: cd workflow (zarr-developers#3935)
* chore: cd workflow * chore: remove python script * feat: use `hatch-vcs` + tag workflow (#171) * tag-based releases --------- Co-authored-by: Ilan Gold <ilanbassgold@gmail.com>
1 parent be160fd commit f2321ec

5 files changed

Lines changed: 158 additions & 21 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: zarr-metadata release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'zarr_metadata-v*'
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
build:
18+
name: Build wheel and sdist
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash
23+
working-directory: packages/zarr-metadata
24+
steps:
25+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
with:
27+
persist-credentials: false
28+
fetch-depth: 0 # hatch-vcs needs full history + tags
29+
30+
- name: Install Hatch
31+
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
32+
with:
33+
version: '1.16.5'
34+
35+
- name: Build
36+
run: hatch build
37+
38+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
39+
with:
40+
name: zarr-metadata-dist
41+
path: packages/zarr-metadata/dist
42+
43+
test_artifacts:
44+
name: Test built artifacts
45+
needs: [build]
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
49+
with:
50+
name: zarr-metadata-dist
51+
path: dist
52+
53+
- name: Install uv
54+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
55+
with:
56+
enable-cache: false
57+
58+
- name: Set up Python
59+
run: uv python install 3.12
60+
61+
- name: Install built wheel and run import smoke test
62+
run: |
63+
wheel=$(ls dist/*.whl)
64+
uv run --with "${wheel}" --python 3.12 --no-project \
65+
python -c "import zarr_metadata; print('zarr_metadata', zarr_metadata.__version__)"
66+
67+
upload_pypi:
68+
name: Upload to PyPI
69+
needs: [build, test_artifacts]
70+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/zarr_metadata-v')
71+
runs-on: ubuntu-latest
72+
environment:
73+
name: zarr-metadata-releases
74+
url: https://pypi.org/p/zarr-metadata
75+
permissions:
76+
id-token: write # required for OIDC trusted publishing
77+
attestations: write # required for artifact attestations
78+
steps:
79+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
80+
with:
81+
name: zarr-metadata-dist
82+
path: dist
83+
84+
- name: Generate artifact attestation
85+
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
86+
with:
87+
subject-path: dist/*
88+
89+
- name: Publish package to PyPI
90+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
91+
92+
upload_testpypi:
93+
name: Upload to TestPyPI
94+
needs: [build, test_artifacts]
95+
if: github.event_name == 'workflow_dispatch'
96+
runs-on: ubuntu-latest
97+
environment:
98+
name: zarr-metadata-releases-test
99+
url: https://test.pypi.org/p/zarr-metadata
100+
permissions:
101+
id-token: write
102+
attestations: write
103+
steps:
104+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
105+
with:
106+
name: zarr-metadata-dist
107+
path: dist
108+
109+
- name: Generate artifact attestation
110+
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
111+
with:
112+
subject-path: dist/*
113+
114+
- name: Publish package to TestPyPI
115+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
116+
with:
117+
repository-url: https://test.pypi.org/legacy/

packages/zarr-metadata/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ Zarr v2 and v3 specs, consolidated metadata, and a subset of the metadata
4747
defined in `zarr-extensions`. We are generally open to contributions that
4848
add types for Zarr metadata with a published spec.
4949

50+
## Releasing
51+
52+
The package version is derived from git tags by `hatch-vcs`. Tags must
53+
match the pattern `zarr_metadata-v<version>` (e.g. `zarr_metadata-v0.2.0`)
54+
so they do not collide with the main `zarr-python` release tags.
55+
56+
To cut a release:
57+
58+
1. Create and push a tag of the form `zarr_metadata-v<version>` on the
59+
commit you want to publish, e.g.:
60+
```
61+
git tag zarr_metadata-v0.2.0 <commit>
62+
git push origin zarr_metadata-v0.2.0
63+
```
64+
2. Pushing the tag fires the `zarr-metadata release` workflow, which
65+
builds the wheel/sdist (version resolved from the tag), runs an
66+
install smoke test, and publishes to PyPI via OIDC trusted publishing.
67+
68+
We intentionally do *not* create a GitHub Release for `zarr-metadata`
69+
versions — GitHub Releases live at the repo level, and a zarr-metadata
70+
release would surface in the zarr-python repo's Releases UI as if it
71+
were a zarr-python release.
72+
73+
To dry-run a build against TestPyPI, dispatch the workflow manually
74+
(`Actions``zarr-metadata release``Run workflow`). Manual dispatches
75+
build from the current commit; with no recent tag the version will look
76+
like `0.1.devN`, which is fine for TestPyPI.
77+
5078
## License
5179

5280
[MIT](./LICENSE.txt)

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.1"
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/src/zarr_metadata/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from importlib.metadata import version
2+
13
from zarr_metadata._common import NamedConfig
24
from zarr_metadata.v2.array import (
35
ArrayDimensionSeparatorV2,
@@ -15,9 +17,7 @@
1517
from zarr_metadata.v3.consolidated import ConsolidatedMetadataV3
1618
from zarr_metadata.v3.group import GroupMetadataV3
1719

18-
__version__ = "0.1.1"
19-
"""Hardcoded package version. Must match the `version` field in
20-
`pyproject.toml`; the sync is enforced by `tests/test_version.py`."""
20+
__version__ = version("zarr-metadata")
2121

2222

2323
__all__ = [

packages/zarr-metadata/tests/test_version.py

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

0 commit comments

Comments
 (0)