Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/actions/check-changes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Detect changed files.
description: Checks if any relevant files have changed in the current pull request or commit. Always returns true if running on the default branch, to ensure all changes are thoroughly checked.

# The file filters are defined in `.github/change-filters.yml`.
#
# Requires
# ```
# permissions:
# pull-requests: read
# ```

# Set job outputs to values from filter step
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label.
outputs:
extensions:
description: "The extension definitions have changed"
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.std-extensions == 'true' }}
rust:
description: "Rust files have changed"
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.rust == 'true' }}
rust-core:
description: "The main tket rust library has changed"
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.rust == 'true' }}
python:
description: "Python files have changed"
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.python == 'true' }}

runs:
using: composite
# Check if changes were made to the relevant files.
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
steps:
- name: Override label
shell: bash
id: override
run: |
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
if [ "$OVERRIDE_LABEL" == "true" ]; then
echo "Overriding due to label 'run-ci-checks'"
echo "out=true" >> $GITHUB_OUTPUT
elif [ "$DEFAULT_BRANCH" == "true" ]; then
echo "Overriding due to running on the default branch"
echo "out=true" >> $GITHUB_OUTPUT
fi
env:
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'S-run-thorough-ci-tests') }}
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
- if: steps.override.outputs.out != 'true'
uses: dorny/paths-filter@v3
id: change-filters
with:
filters: .github/change-filters.yml
8 changes: 4 additions & 4 deletions .github/change-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ rust: &rust
- *schema
- ".github/workflows/ci.yml"
- "impl/rs/**"
- "impl/Cargo.toml"
- "impl/Cargo.lock"
- "Cargo.toml"
- "Cargo.lock"

python: &python
- *schema
- ".github/workflows/ci.yml"
- "impl/py/**"
- "impl/pyproject.toml"
- "impl/uv.lock"
- "pyproject.toml"
- "uv.lock"
131 changes: 131 additions & 0 deletions .github/workflows/ci-py.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Continuous integration 🐍

on:
push:
branches:
- main
pull_request:
branches:
- '**'
merge_group:
types: [checks_requested]
workflow_dispatch: {}

env:
SCCACHE_GHA_ENABLED: "true"
# Pinned version for the uv package manager
UV_VERSION: "0.8.12"
UV_FROZEN: 1

jobs:
# Check if changes were made to the relevant files.
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
changes:
name: Check for changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
python: ${{ steps.filter.outputs.python }}
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/check-changes
id: filter

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.13']

steps:
- uses: actions/checkout@v5
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.9

- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Setup dependencies.
run: uv sync --python ${{ matrix.python-version }}

# TODO: Fix lints and re-enable
#- 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

test:
needs: [changes]
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.13', coverage: true }
steps:
- uses: actions/checkout@v5

- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
enable-cache: true

- name: Setup dependencies
run: uv sync --python ${{ matrix.python-version.py }}

- name: Run tests
if: github.event_name == 'merge_group' || !matrix.python-version.coverage
run: |
uv run pytest

- name: Run python tests with coverage instrumentation
if: github.event_name != 'merge_group' && matrix.python-version.coverage
run: |
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@v5
with:
files: coverage.xml
name: python
flags: python
token: ${{ secrets.CODECOV_TOKEN }}

# 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,
]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Fail if required checks failed
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: |
echo "Required checks failed"
echo "Please check the logs for more information"
exit 1
- name: Pass if all required checks passed
run: |
echo "All required checks passed"
104 changes: 15 additions & 89 deletions .github/workflows/ci.yml → .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous integration
name: Continuous integration 🦀

on:
push:
Expand All @@ -25,39 +25,17 @@ jobs:
changes:
name: Check for changes
runs-on: ubuntu-latest
# Required permissions
permissions:
contents: read
pull-requests: read
# Set job outputs to values from filter step
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label.
outputs:
schema: ${{ steps.filter.outputs.schema == 'true' || steps.override.outputs.out == 'true' }}
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
rust: ${{ steps.filter.outputs.rust }}
steps:
- uses: actions/checkout@v5
- name: Override label
id: override
run: |
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
if [ "$OVERRIDE_LABEL" == "true" ]; then
echo "Overriding due to label 'run-ci-checks'"
echo "out=true" >> $GITHUB_OUTPUT
elif [ "$DEFAULT_BRANCH" == "true" ]; then
echo "Overriding due to running on the default branch"
echo "out=true" >> $GITHUB_OUTPUT
fi
env:
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
- uses: dorny/paths-filter@v3
id: filter
with:
filters: .github/change-filters.yml
- uses: actions/checkout@v5
- uses: ./.github/actions/check-changes
id: filter

rs-check:
name: 🦀 Check lints
name: Check lints
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
Expand All @@ -78,7 +56,7 @@ jobs:
RUSTDOCFLAGS: "-Dwarnings"

rs-benches:
name: 🦀 Build Rust benchmarks 🏋️
name: Build Rust benchmarks 🏋️
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
Expand All @@ -95,7 +73,7 @@ jobs:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
runs-on: ubuntu-latest
name: 🦀 tests (Rust stable, all features)
name: tests (Rust stable, all features)
steps:
- uses: actions/checkout@v5
- uses: mozilla-actions/sccache-action@v0.0.9
Expand All @@ -121,7 +99,7 @@ jobs:
# Stable is covered by `tests-stable-all-features`
# Nightly is covered by `tests-nightly-coverage`
rust: ["1.85", beta]
name: 🦀 tests (Rust ${{ matrix.rust }})
name: tests (Rust ${{ matrix.rust }})
steps:
- uses: actions/checkout@v5
- uses: mozilla-actions/sccache-action@v0.0.9
Expand All @@ -142,7 +120,7 @@ jobs:
# Run only if there are changes in the relevant files
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
runs-on: ubuntu-latest
name: 🦀 tests (Rust nightly, coverage)
name: tests (Rust nightly, coverage)
steps:
- uses: actions/checkout@v5
- uses: mozilla-actions/sccache-action@v0.0.9
Expand All @@ -169,67 +147,15 @@ jobs:
flags: rust
#token: ${{ secrets.CODECOV_TOKEN }}

# Ensure that the generated capnp implementations are up to date
#
# Run `just update-capnp` to update the generated code.
capnp-schema:
needs: [changes]
if: ${{ needs.changes.outputs.schema == 'true' && github.event_name != 'merge_group' }}
name: Keep the capnp generated code up-to-date with the schema
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: mozilla-actions/sccache-action@v0.0.9
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install CapnProto
run: |
curl -O https://capnproto.org/capnproto-c++-${CAPNPROTO_VERSION}.tar.gz
tar zxf capnproto-c++-${CAPNPROTO_VERSION}.tar.gz
cd capnproto-c++-${CAPNPROTO_VERSION}
./configure
make -j6 check
sudo make install
- name: Get cargo binstall
uses: cargo-bins/cargo-binstall@main
- name: Install capnproto-rust plugin
run: cargo binstall capnpc
- name: Regenerate the Rust capnp code
run: |
capnp compile \
-orust:impl/rs/src \
--src-prefix=impl \
impl/capnp/jeff.capnp
- name: Regenerate the C++ capnp code
run: |
patch -p0 < impl/capnp/cpp_namespace.patch
capnp compile \
-oc++:impl/cpp/src \
--src-prefix=impl \
impl/capnp/jeff.capnp
patch -p0 -R < impl/capnp/cpp_namespace.patch
- name: Re-encode the test .jeff files
run: ./examples/encode_examples.sh
- name: Check if the generated capnproto code is up to date
run: |
git diff --exit-code impl/rs/src/capnp/ impl/cpp/src/capnp/ examples/
if [ $? -ne 0 ]; then
echo "The capnp generated code is not up to date"
echo "Please run 'just update-capnp' 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,
rs-check,
rs-tests-stable-all-features,
# We don't include `capnp-schema` as a required check, since it takes a while to install the latest capnp system lib
]
needs: [
changes,
rs-check,
rs-tests-stable-all-features,
]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
Expand Down
Loading
Loading