Continuous integration 🐍 #2031
Workflow file for this run
This file contains 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: Continuous integration 🐍 | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
merge_group: | |
types: [checks_requested] | |
workflow_dispatch: {} | |
env: | |
SCCACHE_GHA_ENABLED: "true" | |
HUGR_BIN_DIR: ${{ github.workspace }}/target/debug | |
HUGR_BIN: ${{ github.workspace }}/target/debug/hugr | |
UV_CACHE_DIR: /tmp/.uv-cache | |
jobs: | |
# Check if changes were made to the relevant files. | |
# Always returns true if running on the default branch, to ensure all changes are throughly checked. | |
changes: | |
name: Check for changes in Python files | |
runs-on: ubuntu-latest | |
# Required permissions | |
permissions: | |
pull-requests: read | |
# Set job outputs to values from filter step | |
outputs: | |
python: ${{ github.ref_name == github.event.repository.default_branch || steps.filter.outputs.python }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: .github/change-filters.yml | |
check: | |
needs: changes | |
if: ${{ needs.changes.outputs.python == 'true' }} | |
name: check python ${{ matrix.python-version }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.10', '3.12'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run sccache-cache | |
uses: mozilla-actions/sccache-action@v0.0.5 | |
- name: Set up uv | |
run: .github/script/install-uv.sh | |
- name: "Set up Python" | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Restore uv cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.UV_CACHE_DIR }} | |
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | |
restore-keys: | | |
uv-${{ runner.os }} | |
- name: Setup dependencies. Fail if the lockfile is outdated. | |
run: uv sync --locked | |
- name: Type check with mypy | |
run: uv run mypy . | |
- name: Check formatting with ruff | |
run: uv run ruff format --check | |
- name: Lint with ruff | |
run: uv run ruff check | |
- name: Minimize uv cache | |
run: uv cache prune --ci | |
build_binary: | |
needs: changes | |
if: ${{ needs.changes.outputs.python == 'true' }} | |
name: Build HUGR binary | |
runs-on: ubuntu-latest | |
env: | |
SCCACHE_GHA_ENABLED: "true" | |
RUSTC_WRAPPER: "sccache" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.5 | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Build HUGR binary | |
run: cargo build -p hugr-cli | |
- name: Upload the binary to the artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: hugr_binary | |
path: target/debug/hugr | |
test: | |
needs: [changes, build_binary] | |
if: ${{ needs.changes.outputs.python == 'true' }} | |
name: test python ${{ matrix.python-version.py }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: | |
- { py: '3.10', coverage: false } | |
- { py: '3.12', coverage: true } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up uv | |
run: .github/script/install-uv.sh | |
- name: "Set up Python" | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version.py }} | |
- name: Restore uv cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.UV_CACHE_DIR }} | |
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | |
restore-keys: | | |
uv-${{ runner.os }} | |
- name: Download the hugr binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: hugr_binary | |
path: ${{env.HUGR_BIN_DIR}} | |
- name: Setup dependencies | |
run: uv sync | |
- name: Setup Graphviz | |
uses: ts-graphviz/setup-graphviz@v2 | |
- name: Run tests | |
if: github.event_name == 'merge_group' || !matrix.python-version.coverage | |
run: | | |
chmod +x $HUGR_BIN | |
HUGR_RENDER_DOT=1 uv run pytest | |
- name: Run python tests with coverage instrumentation | |
if: github.event_name != 'merge_group' && matrix.python-version.coverage | |
run: | | |
chmod +x $HUGR_BIN | |
HUGR_RENDER_DOT=1 uv run pytest --cov=./ --cov-report=xml | |
- name: Upload python coverage to codecov.io | |
if: github.event_name != 'merge_group' && matrix.python-version.coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
files: coverage.xml | |
name: python | |
flags: python | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Minimize uv cache | |
run: uv cache prune --ci | |
# Ensure that the serialization schema is up to date | |
serialization-schema: | |
needs: [changes] | |
if: ${{ needs.changes.outputs.python == 'true' }} | |
name: Check serialization schema | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run sccache-cache | |
uses: mozilla-actions/sccache-action@v0.0.5 | |
- name: Set up uv | |
run: .github/script/install-uv.sh | |
- name: "Set up Python" | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Restore uv cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.UV_CACHE_DIR }} | |
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | |
restore-keys: | | |
uv-${{ runner.os }} | |
- name: Setup dependencies | |
run: uv sync | |
- name: Generate the updated schema | |
run: | | |
uv run scripts/generate_schema.py specification/schema/ | |
- name: Check if the schema is up to date | |
run: | | |
git diff --exit-code --name-only specification/schema/ | |
if [ $? -ne 0 ]; then | |
echo "The serialization schema is not up to date" | |
echo "Please run 'just update-schema' and commit the changes" | |
exit 1 | |
fi | |
# This is a meta job to mark successful completion of the required checks, | |
# even if they are skipped due to no changes in the relevant files. | |
required-checks: | |
name: Required checks 🐍 | |
needs: [changes, check, test, serialization-schema] | |
if: ${{ !cancelled() }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fail if required checks failed | |
# This condition should simply be `if: failure() || cancelled()`, | |
# but there seems to be a bug in the github workflow runner. | |
# | |
# See https://github.com/orgs/community/discussions/80788 | |
if: | | |
needs.changes.result == 'failure' || needs.changes.result == 'cancelled' || | |
needs.check.result == 'failure' || needs.check.result == 'cancelled' || | |
needs.test.result == 'failure' || needs.test.result == 'cancelled' || | |
needs.serialization-schema.result == 'failure' || needs.serialization-schema.result == 'cancelled' | |
run: | | |
echo "Required checks failed" | |
echo "Please check the logs for more information" | |
exit 1 | |
- name: Pass if required checks passed | |
run: | | |
echo "All required checks passed" |