Skip to content

Commit d6530c7

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

3 files changed

Lines changed: 92 additions & 5 deletions

File tree

.github/workflows/release.yaml

Lines changed: 90 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,89 @@ 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+
default_branch: ${{ github.event.repository.default_branch }}
62+
permissions:
63+
contents: write
64+
steps:
65+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
66+
with:
67+
filter: blob:none
68+
fetch-depth: 0
69+
persist-credentials: true
70+
- name: Install uv
71+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
72+
with:
73+
enable-cache: false
74+
- name: Get environment
75+
# get the test environment with the oldest Python
76+
id: get-env
77+
run: |
78+
ENV=$(uvx hatch env show --json | jq -r '[to_entries[] | select(.key | startswith("hatch-test") and (contains("pre") | not))]
79+
| sort_by(.value.python)[0].key')
80+
echo "hatch_env=${ENV}" | tee $GITHUB_ENV
81+
- name: create hatch environment
82+
run: uvx hatch env create "$hatch_env"
83+
- name: generate output directory
84+
run: mkdir -p "$data_path"
85+
- name: generate files
86+
working-directory: ${{ env.data_path }}
87+
run: |
88+
uvx hatch run "$hatch_env":../../../../src/mudata/tests/reference.py
89+
uvx hatch run "$hatch_env":sh -c "uv pip freeze | uv pip compile - -o pylock.toml"
90+
- name: configure git
91+
run: |
92+
git config user.name github-actions
93+
git config user.email github-actions@github.com
94+
BRANCH=$(git branch --show-current)
95+
if [ ! "$BRANCH" ] ; then
96+
BRANCH=$(git branch --contains $ref_name -a | tail -n 1 | sed 's/^\s*remotes\/origin\///')
97+
fi
98+
echo branch=${BRANCH} | tee $GITHUB_ENV
99+
- name: commit and push
100+
if: ${{ env.branch != '' }}
101+
working-directory: ${{ env.data_path }}
102+
run: |
103+
git checkout "$branch"
104+
git add .
105+
git commit -m "add backwards compat test files for $ref_name"
106+
git push
107+
if [ "$branch" != "$default_branch" ] ; then
108+
git checkout "$default_branch"
109+
git pull
110+
git cherry-pick -x "$branch"
111+
git push
112+
fi
113+
- name: commit and push
114+
if: ${{ env.branch == '' }}
115+
working-directory: ${{ env.data_path }}
116+
run: |
117+
git checkout "$default_branch"
118+
git pull
119+
git add .
120+
git commit -m "add backwards compat test files for $ref_name"
121+
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)