Skip to content

Commit 59e0cc0

Browse files
committed
chore: cd workflow
1 parent f8c0c5d commit 59e0cc0

1 file changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: zarr-metadata release
2+
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 publishes the version as-declared in
9+
# pyproject.toml. Each version is a single shot — re-runs
10+
# for the same version will be rejected by PyPI.
11+
# - `testpypi` -> https://test.pypi.org. The build appends a
12+
# `.dev<run_number>` suffix to the version automatically
13+
# so each test push gets a unique version on TestPyPI.
14+
on:
15+
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
25+
26+
permissions:
27+
contents: read
28+
29+
concurrency:
30+
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.target }}
31+
cancel-in-progress: false
32+
33+
jobs:
34+
build:
35+
name: Build wheel and sdist
36+
runs-on: ubuntu-latest
37+
defaults:
38+
run:
39+
shell: bash
40+
working-directory: packages/zarr-metadata
41+
steps:
42+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
43+
with:
44+
persist-credentials: false
45+
46+
- name: Apply dev-suffix for TestPyPI builds
47+
if: inputs.target == 'testpypi'
48+
env:
49+
RUN_NUMBER: ${{ github.run_number }}
50+
run: |
51+
python3 <<'PY'
52+
import os, re
53+
from pathlib import Path
54+
55+
run_number = os.environ["RUN_NUMBER"]
56+
pyp = Path("pyproject.toml")
57+
init = Path("src/zarr_metadata/__init__.py")
58+
59+
base = re.search(r'^version\s*=\s*"([^"]+)"', pyp.read_text(), re.M).group(1)
60+
new_version = f"{base}.dev{run_number}"
61+
print(f"::notice::TestPyPI build: {base} -> {new_version}")
62+
63+
pyp.write_text(re.sub(
64+
r'^(version\s*=\s*)"[^"]+"',
65+
rf'\1"{new_version}"',
66+
pyp.read_text(),
67+
count=1,
68+
flags=re.M,
69+
))
70+
init.write_text(re.sub(
71+
r'^(__version__\s*=\s*)"[^"]+"',
72+
rf'\1"{new_version}"',
73+
init.read_text(),
74+
count=1,
75+
flags=re.M,
76+
))
77+
PY
78+
79+
- name: Install Hatch
80+
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
81+
with:
82+
version: '1.16.5'
83+
84+
- name: Build
85+
run: hatch build
86+
87+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
88+
with:
89+
name: zarr-metadata-dist
90+
path: packages/zarr-metadata/dist
91+
92+
test_artifacts:
93+
name: Test built artifacts
94+
needs: [build]
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
98+
with:
99+
name: zarr-metadata-dist
100+
path: dist
101+
102+
- name: List built artifacts
103+
run: ls -la dist
104+
105+
- name: Install uv
106+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
107+
108+
- name: Set up Python
109+
run: uv python install 3.12
110+
111+
- name: Install built wheel and run import smoke test
112+
run: |
113+
wheel=$(ls dist/*.whl)
114+
uv run --with "${wheel}" --python 3.12 --no-project \
115+
python -c "import zarr_metadata; print('zarr_metadata', zarr_metadata.__version__)"
116+
117+
upload_pypi:
118+
name: Upload to PyPI
119+
needs: [build, test_artifacts]
120+
if: inputs.target == 'pypi'
121+
runs-on: ubuntu-latest
122+
environment:
123+
name: zarr-metadata-releases
124+
url: https://pypi.org/p/zarr-metadata
125+
permissions:
126+
id-token: write # required for OIDC trusted publishing
127+
attestations: write # required for artifact attestations
128+
steps:
129+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
130+
with:
131+
name: zarr-metadata-dist
132+
path: dist
133+
134+
- name: Generate artifact attestation
135+
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
136+
with:
137+
subject-path: dist/*
138+
139+
- name: Publish package to PyPI
140+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
141+
142+
upload_testpypi:
143+
name: Upload to TestPyPI
144+
needs: [build, test_artifacts]
145+
if: inputs.target == 'testpypi'
146+
runs-on: ubuntu-latest
147+
environment:
148+
name: zarr-metadata-releases-test
149+
url: https://test.pypi.org/p/zarr-metadata
150+
permissions:
151+
id-token: write
152+
attestations: write
153+
steps:
154+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
155+
with:
156+
name: zarr-metadata-dist
157+
path: dist
158+
159+
- name: Generate artifact attestation
160+
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
161+
with:
162+
subject-path: dist/*
163+
164+
- name: Publish package to TestPyPI
165+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
166+
with:
167+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)