Use pooch for dataset downloads (#244) #1071
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| schedule: | |
| - cron: "0 5 1,15 * *" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| defaults: | |
| run: | |
| # to fail on error in multiline statements (-e), in pipes (-o pipefail), and on unset variables (-u). | |
| shell: bash -euo pipefail {0} | |
| jobs: | |
| # Get the test environment from hatch as defined in pyproject.toml. | |
| # This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are | |
| # run locally and on continuous integration. | |
| # Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for | |
| # more details. | |
| get-environments: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| envs: ${{ steps.get-envs.outputs.envs }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| filter: blob:none | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| - name: Get test environments | |
| id: get-envs | |
| run: | | |
| ENVS_JSON=$(uvx hatch env show --json | jq -c 'to_entries | |
| | map( | |
| select(.key | startswith("hatch-test")) | |
| | { | |
| name: .key, | |
| label: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end), | |
| python: .value.python | |
| } | |
| )') | |
| echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT | |
| # Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above. | |
| test: | |
| needs: get-environments | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest] | |
| env: ${{ fromJSON(needs.get-environments.outputs.envs) }} | |
| name: ${{ matrix.env.label }} | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| filter: blob:none | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: ${{ matrix.env.python }} | |
| cache-dependency-glob: pyproject.toml | |
| - name: create hatch environment | |
| run: uvx hatch env create ${{ matrix.env.name }} | |
| - name: Show installed packages | |
| if: matrix.env.python == '3.14' | |
| run: | | |
| uvx hatch run hatch-test.py3.14:uv pip freeze | |
| # Restore example datasets (downloaded from physionet.org etc.) from a previous run, so flaky/blocked upstream hosts don't break CI. | |
| # The key is static so the cache is reused across runs; bump the version when a dataset URL changes. | |
| - name: Restore datasets cache | |
| id: data-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: ehrapy_data | |
| key: ehrapy-data-tests-v2 | |
| - name: run tests using hatch | |
| env: | |
| MPLBACKEND: agg | |
| PLATFORM: ${{ matrix.os }} | |
| DISPLAY: :42 | |
| # --dist loadgroup so tests sharing a dataset download path (marked with @pytest.mark.xdist_group) run on the | |
| # same worker and don't download/extract the same dataset concurrently on a cold cache. | |
| run: uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto --dist loadgroup | |
| # Only persist the cache after a green run that had to download (cache miss), so a partial/failed download is never saved under the (immutable) key. | |
| - name: Save datasets cache | |
| if: steps.data-cache.outputs.cache-hit != 'true' && success() | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: ehrapy_data | |
| key: ehrapy-data-tests-v2 | |
| - name: generate coverage report | |
| run: | | |
| # See https://coverage.readthedocs.io/en/latest/config.html#run-patch | |
| test -f .coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine | |
| uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly | |
| uvx hatch run ${{ matrix.env.name }}:coverage xml # create report for upload | |
| - name: Upload coverage | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch | |
| # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why. | |
| check: | |
| name: Tests pass in all hatch environments | |
| if: always() | |
| needs: | |
| - get-environments | |
| - test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: re-actors/alls-green@release/v1 | |
| with: | |
| jobs: ${{ toJSON(needs) }} |