Skip to content

Commit 6879aea

Browse files
committed
add GitHub action to automatically generate test files for each release
1 parent 94ed597 commit 6879aea

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

.github/workflows/release.yaml

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ on:
66
- "v?[0-9]+.[0-9]+.[0-9]+**"
77
workflow_dispatch:
88

9-
# Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/
9+
permissions:
10+
contents: read
11+
1012
jobs:
13+
# Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/
1114
release:
1215
name: Upload release to PyPI
1316
runs-on: ubuntu-latest
@@ -30,3 +33,85 @@ jobs:
3033
run: uv build
3134
- name: Publish package distributions to PyPI
3235
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
36+
37+
is-prerelease:
38+
name: Check if this is a pre-release
39+
runs-on: ubuntu-slim
40+
outputs:
41+
is_prerelease: ${{ steps.check_prerelease.outputs.is_prerelease }}
42+
steps:
43+
- name: Check if this is a pre-release
44+
id: check_prerelease
45+
run: |
46+
PRE=$(echo "$ref_name" | sed -E 's/^v[0-9]+\.[0-9]+\.[0-9]+(.+?)$/\1/' | wc -w)
47+
if [ $PRE = 0 ] ; then
48+
PRE=false
49+
else
50+
PRE=true
51+
fi
52+
echo "is_prerelease=$PRE" | tee $GITHUB_OUTPUT
53+
54+
generate-test-data:
55+
name: Generate test files for backwards compatibility testing
56+
needs: is-prerelease
57+
if: ${{ needs.is-prerelease.outputs.is_prerelease == 'false' && github.event_name == 'push' && github.event.created && github.ref_type == 'tag' }}
58+
runs-on: ubuntu-slim
59+
env:
60+
data_path: ./tests/data/archives/${{ github.ref_name }}
61+
permissions:
62+
contents: write
63+
steps:
64+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
65+
with:
66+
filter: blob:none
67+
fetch-depth: 0
68+
persist-credentials: true
69+
- name: Install uv
70+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
71+
with:
72+
enable-cache: false
73+
- name: Get environment
74+
# get the test environment with the oldest Python
75+
id: get-env
76+
run: |
77+
ENV=$(uvx hatch env show --json | jq -r '[to_entries[] | select(.key | startswith("hatch-test") and (contains("pre") | not))]
78+
| sort_by(.value.python)[0].key')
79+
echo "hatch_env=${ENV}" | tee $GITHUB_ENV
80+
- name: create hatch environment
81+
run: uvx hatch env create "$hatch_env"
82+
- name: generate output directory
83+
run: mkdir -p "$data_path"
84+
- name: generate files
85+
working-directory: ${{ env.data_path }}
86+
run: |
87+
uvx hatch run "$hatch_env":../../../../src/mudata/tests/reference.py
88+
uvx hatch run "$hatch_env":sh -c "uv pip freeze | uv pip compile - -o pylock.toml"
89+
- name: configure git
90+
run: |
91+
git config user.name github-actions
92+
git config user.email github-actions@github.com
93+
BRANCH=$(git branch --show-current)
94+
if [ ! "$BRANCH" ] ; then
95+
BRANCH=$(git branch --contains $ref_name -a | tail -n 1 | sed 's/^\s*remotes\/origin\///')
96+
fi
97+
echo branch=${BRANCH} | tee $GITHUB_ENV
98+
- name: commit and push
99+
if: ${{ env.branch != '' }}
100+
run: |
101+
git checkout "$branch"
102+
git add .
103+
git commit -m "add backwards compat test files for $ref_name"
104+
HASH=$(git rev-parse HEAD)
105+
git push
106+
if [ "$branch" != main ] ; then
107+
git checkout main
108+
git cherry-pick -x $HASH
109+
git push
110+
fi
111+
- name: commit and push
112+
if: ${{ env.branch == '' }}
113+
run: |
114+
git checkout main
115+
git add .
116+
git commit -m "add backwards compat test files for $ref_name"
117+
git push

src/mudata/tests/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def generate_reference(axis: Literal[0, 1]) -> MuData:
4444
for axis in (0, 1):
4545
mdata = generate_reference(axis)
4646
write_h5mu(f"mdata_axis{axis}.h5mu", mdata, compression="gzip", compression_opts=9)
47-
write_zarr(zarr.storage.ZipStore(f"mdata_axis{axis}.zarr.zip"), mdata)
47+
write_zarr(zarr.storage.ZipStore(f"mdata_axis{axis}.zarr.zip", mode="w"), mdata)

0 commit comments

Comments
 (0)