Derive test configs from hatch (#98) #377
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
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
env: | |
PYTEST_ADDOPTS: "-v --color=yes" | |
FORCE_COLOR: "1" | |
jobs: | |
get-environments: | |
runs-on: ubuntu-latest | |
outputs: | |
envs: ${{ steps.get-envs.outputs.envs }} | |
pythons: ${{ steps.get-pythons.outputs.pythons }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
filter: blob:none | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
- name: Get test environments | |
id: get-envs | |
run: | | |
ENVS_JSON=$( | |
FORCE_COLOR= uvx hatch env show --json | | |
jq -c 'to_entries | map(select(.key | startswith("hatch-test")) | { name: .key, python: .value.python })' | |
) | |
echo "envs=$ENVS_JSON" | tee $GITHUB_OUTPUT | |
- name: Get python versions | |
id: get-pythons | |
env: | |
ENVS_JSON: ${{ steps.get-envs.outputs.envs }} | |
run: | | |
PYTHONS_JSON=$(echo "$ENVS_JSON" | jq -c 'map(.python) | unique') | |
echo "pythons=$PYTHONS_JSON" | tee $GITHUB_OUTPUT | |
test: | |
name: Tests | |
needs: get-environments | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
env: ${{ fromJSON(needs.get-environments.outputs.envs) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
filter: blob:none | |
- uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
cache-dependency-glob: pyproject.toml | |
python-version: ${{ matrix.env.python }} | |
- name: create environment | |
run: uvx hatch env create ${{ matrix.env.name }} | |
- name: run tests with coverage | |
run: | | |
uvx hatch run ${{ matrix.env.name }}:run-cov | |
# https://github.com/codecov/codecov-cli/issues/648 | |
uvx hatch run ${{ matrix.env.name }}:coverage xml | |
rm test-data/.coverage | |
- uses: codecov/codecov-action@v5 | |
with: | |
name: ${{ matrix.env.name }} | |
fail_ci_if_error: true | |
files: test-data/coverage.xml | |
token: ${{ secrets.CODECOV_TOKEN }} | |
bench: | |
name: CPU Benchmarks | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.13' | |
- uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
cache-dependency-glob: pyproject.toml | |
- run: uv pip install --system -e .[test,full] | |
- uses: CodSpeedHQ/action@v3 | |
with: | |
run: pytest -m benchmark --codspeed | |
token: ${{ secrets.CODSPEED_TOKEN }} | |
import: | |
name: Import Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
filter: blob:none | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.13' | |
- uses: astral-sh/setup-uv@v5 | |
with: | |
cache-dependency-glob: pyproject.toml | |
- run: uv pip install --system -e . | |
- run: python -c 'import fast_array_utils as fau; print(fau.__all__)' | |
- run: uv pip install --system -e .[testing] | |
- run: python -c 'import testing.fast_array_utils as tfau; print(tfau.ArrayType("numpy", "ndarray"))' | |
check: | |
name: Static Checks | |
needs: get-environments | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ${{ fromJSON(needs.get-environments.outputs.pythons) }} | |
env: | |
SKIP: no-commit-to-branch # this CI runs on the main branch | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
filter: blob:none | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- uses: pre-commit/[email protected] | |
pass: | |
name: All Checks | |
if: always() | |
needs: | |
- get-environments | |
- test | |
- bench | |
- import | |
- check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: re-actors/alls-green@release/v1 | |
with: | |
jobs: ${{ toJSON(needs) }} |