Skip to content

Commit 804ccd1

Browse files
committed
add GitHub action to automatically generate test files for each release
1 parent 5fd0161 commit 804ccd1

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

.github/workflows/release.yaml

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

tests/test_io_backwards_compat.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ def assert_mdata_equal(a: md.MuData, b: object, *, exact: bool = False):
4141

4242
ARCHIVE_PATH = Path(__file__).parent / "data" / "archives"
4343

44-
ARCHIVES = tuple(ARCHIVE_PATH.glob("v*"))
4544

46-
47-
@pytest.fixture(params=ARCHIVES, ids=lambda x: x.name)
45+
@pytest.fixture(params=tuple(ARCHIVE_PATH.glob("v*")), ids=lambda x: x.name)
4846
def archive_dir(request: pytest.FixtureRequest):
4947
return request.param
5048

0 commit comments

Comments
 (0)