Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/zarr-metadata-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: zarr-metadata release

on:
workflow_dispatch:
release:
types: [published]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Build wheel and sdist
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: packages/zarr-metadata
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0 # hatch-vcs needs full history + tags

- name: Install Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
with:
version: '1.16.5'

- name: Build
run: hatch build

- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: zarr-metadata-dist
path: packages/zarr-metadata/dist

test_artifacts:
name: Test built artifacts
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: zarr-metadata-dist
path: dist

- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

- name: Set up Python
run: uv python install 3.12

- name: Install built wheel and run import smoke test
run: |
wheel=$(ls dist/*.whl)
uv run --with "${wheel}" --python 3.12 --no-project \
python -c "import zarr_metadata; print('zarr_metadata', zarr_metadata.__version__)"

upload_pypi:
name: Upload to PyPI
needs: [build, test_artifacts]
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'zarr_metadata/')
runs-on: ubuntu-latest
environment:
name: zarr-metadata-releases
url: https://pypi.org/p/zarr-metadata
permissions:
id-token: write # required for OIDC trusted publishing
attestations: write # required for artifact attestations
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: zarr-metadata-dist
path: dist

- name: Generate artifact attestation
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
with:
subject-path: dist/*

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

upload_testpypi:
name: Upload to TestPyPI
needs: [build, test_artifacts]
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment:
name: zarr-metadata-releases-test
url: https://test.pypi.org/p/zarr-metadata
permissions:
id-token: write
attestations: write
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: zarr-metadata-dist
path: dist

- name: Generate artifact attestation
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
with:
subject-path: dist/*

- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
with:
repository-url: https://test.pypi.org/legacy/
20 changes: 20 additions & 0 deletions packages/zarr-metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ Zarr v2 and v3 specs, consolidated metadata, and a subset of the metadata
defined in `zarr-extensions`. We are generally open to contributions that
add types for Zarr metadata with a published spec.

## Releasing
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilan-gold how does this look


The package version is derived from git tags by `hatch-vcs`. Tags must
match the pattern `zarr_metadata/v<version>` (e.g. `zarr_metadata/v0.2.0`)
so they do not collide with the main `zarr-python` release tags.

To cut a release:

1. Create a GitHub Release whose tag is `zarr_metadata/v<version>`,
targeting the commit you want to publish.
2. Publishing the release fires the `zarr-metadata release` workflow,
which builds the wheel/sdist (version resolved from the tag), runs
an install smoke test, and publishes to PyPI via OIDC trusted
publishing.

To dry-run a build against TestPyPI, dispatch the workflow manually
(`Actions` → `zarr-metadata release` → `Run workflow`). Manual dispatches
build from the current commit; with no recent tag the version will look
like `0.1.devN`, which is fine for TestPyPI.

## License

[MIT](./LICENSE.txt)
12 changes: 10 additions & 2 deletions packages/zarr-metadata/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["hatchling>=1.29.0"]
requires = ["hatchling>=1.29.0", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "zarr-metadata"
version = "0.1.1"
dynamic = ["version"]
description = "Spec-defined metadata types for Zarr v2 and v3."
readme = "README.md"
requires-python = ">=3.11"
Expand Down Expand Up @@ -32,6 +32,14 @@ dependencies = [
[dependency-groups]
test = ["pytest", "pydantic>=2"]

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

[tool.hatch.build.targets.wheel]
packages = ["src/zarr_metadata"]

Expand Down
6 changes: 3 additions & 3 deletions packages/zarr-metadata/src/zarr_metadata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from importlib.metadata import version

from zarr_metadata._common import NamedConfig
from zarr_metadata.v2.array import (
ArrayDimensionSeparatorV2,
Expand All @@ -15,9 +17,7 @@
from zarr_metadata.v3.consolidated import ConsolidatedMetadataV3
from zarr_metadata.v3.group import GroupMetadataV3

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


__all__ = [
Expand Down
16 changes: 0 additions & 16 deletions packages/zarr-metadata/tests/test_version.py

This file was deleted.

Loading