66 pull_request :
77 branches : [main]
88 workflow_dispatch :
9+ inputs :
10+ tag :
11+ description : ' Git tag to build and publish (e.g. v3.1.6)'
12+ required : true
13+ type : string
914
1015permissions :
1116 contents : read
1217
18+ concurrency :
19+ group : ${{ github.workflow }}-${{ github.ref }}
20+ cancel-in-progress : true
21+
1322jobs :
1423
24+ validate_tag :
25+ if : github.event_name == 'workflow_dispatch'
26+ runs-on : ubuntu-latest
27+ steps :
28+ - name : Validate tag format
29+ run : |
30+ if [[ ! "${{ inputs.tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([a-z]+[0-9]*)?$ ]]; then
31+ echo "::error::Invalid tag format '${{ inputs.tag }}'. Expected format: v1.2.3, v1.2.3a1, v1.2.3rc1"
32+ exit 1
33+ fi
34+ - name : Verify tag exists
35+ run : |
36+ git ls-remote --tags "${{ github.server_url }}/${{ github.repository }}" "${{ inputs.tag }}" | grep -q "${{ inputs.tag }}" || {
37+ echo "::error::Tag '${{ inputs.tag }}' does not exist in the repository"
38+ exit 1
39+ }
40+
1541 build_artifacts :
42+ needs : [validate_tag]
43+ if : always() && (needs.validate_tag.result == 'success' || needs.validate_tag.result == 'skipped')
1644 name : Build wheel on ubuntu-latest
1745 runs-on : ubuntu-latest
1846 strategy :
2149 steps :
2250 - uses : actions/checkout@v6
2351 with :
52+ ref : ${{ inputs.tag || github.ref }}
2453 submodules : true
2554 fetch-depth : 0
2655
3564 version : ' 1.16.5'
3665 - name : Build wheel and sdist
3766 run : hatch build
38- - uses : actions/upload-artifact@v6
67+ - uses : actions/upload-artifact@v7
3968 with :
4069 name : releases
4170 path : dist
@@ -55,16 +84,26 @@ jobs:
5584 ls dist
5685
5786 upload_pypi :
58- needs : [build_artifacts]
87+ needs : [build_artifacts, test_dist_pypi ]
5988 runs-on : ubuntu-latest
60- if : github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
89+ if : >-
90+ (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v'))
91+ || (github.event_name == 'workflow_dispatch' && startsWith(inputs.tag, 'v'))
92+ environment :
93+ name : releases
94+ url : https://pypi.org/p/zarr
95+ permissions :
96+ id-token : write
97+ attestations : write
98+ artifact-metadata : write
6199 steps :
62100 - uses : actions/download-artifact@v7
63101 with :
64102 name : releases
65103 path : dist
66- - uses : pypa/gh-action-pypi-publish@v1.13.0
104+ - name : Generate artifact attestation
105+ uses : actions/attest@v4
67106 with :
68- user : __token__
69- password : ${{ secrets.pypi_password }}
70- # To test: repository_url: https://test. pypi.org/legacy/
107+ subject-path : dist/*
108+ - name : Publish package to PyPI
109+ uses : pypa/gh-action- pypi-publish@v1.13.0
0 commit comments