Skip to content

Commit

Permalink
Refactor test and build jobs
Browse files Browse the repository at this point in the history
Overall, we want to:

- Run as few jobs as possible
- Have the jobs finish as fast as possible
- Have the jobs redo as little work as possible

We change our CI jobs into:

1) A matrix job for all tests, split by crate.
2) A matrix job for testing certain feature combinations and MSRV.

We make this split because:

A test is no good unless run, thus the `test` job always activates
all features.
MSRV and exposed feature only concern the public API of a crate,
thus the `check` job doesn't run on all targets.
  • Loading branch information
thomaseizinger committed Nov 7, 2022
1 parent 236bdef commit dbfad1e
Showing 1 changed file with 44 additions and 54 deletions.
98 changes: 44 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,79 @@ concurrency:
cancel-in-progress: true

jobs:
test-desktop:
name: Build and test
test: # Test all workspace crates
name: Test ${{ matrix.crate }}
runs-on: ubuntu-latest
needs: gather_published_crates
strategy:
fail-fast: false
matrix:
args: [
"--no-default-features",
"--all-features",
"--benches --all-features",
]
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
include:
# Building the meta-crate for WASM is good enough.
- crate: libp2p
args: "--toolchain wasm32-unknown-unknown"
- crate: libp2p
features: "--toolchain wasm32-unknown-emscripten"
- crate: libp2p
features: "--toolchain wasm32-wasi"

steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable # Ensure tests always run on latest stable
override: true

- uses: Swatinem/rust-cache@22c9328bcba27aa81a32b1bef27c7e3c78052531 # v2.0.1
with:
key: ${{ matrix.args }}
key: ${{ matrix.crate }}-${{ matrix.args }}

- run: cargo test --workspace ${{ matrix.args }}
- run: cargo test --package ${{ matrix.crate }} --all-features ${{ matrix.args }}

test-wasm:
name: Build on WASM
check: # Check that various feature combinations compile whilst adhering to the stated MSRV.
runs-on: ubuntu-latest
needs: gather_published_crates
strategy:
fail-fast: false
matrix:
toolchain: [
wasm32-unknown-emscripten,
wasm32-wasi
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
args: [
"--all-features"
]
include:
- toolchain: wasm32-unknown-unknown
args: "--features wasm-bindgen"
- crate: libp2p
args: "--features=all-transports --features tokio",
- crate: libp2p
features: "--features=all-transports --features async-std"
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1

- uses: actions/checkout@v3

- name: Install Rust ${{ matrix.toolchain }}
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
- name: Get MSRV for ${{ matrix.crate }}
id: parse-msrv
run: |
RUST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "libp2p") | .rust_version')
echo "::set-output name=version::${RUST_VERSION}"
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: stable
target: ${{ matrix.toolchain }}
profile: minimal
toolchain: ${{ steps.parse-msrv.outputs.version }}
override: true

- uses: Swatinem/rust-cache@22c9328bcba27aa81a32b1bef27c7e3c78052531 # v2.0.1
with:
key: ${{ matrix.toolchain }}
with:
key: ${{ matrix.crate }}-${{ matrix.args }}

- name: Build on ${{ matrix.toolchain }}
# TODO: also run `cargo test`
# TODO: ideally we would build `--workspace`, but not all crates compile for WASM
run: cargo build --target=${{ matrix.toolchain }} ${{ matrix.args }}
- run: cargo check --package ${{ matrix.crate }} ${{ matrix.args }}

check-rustdoc-links:
name: Check rustdoc intra-doc links
Expand Down Expand Up @@ -115,34 +133,6 @@ jobs:
with:
command: custom-clippy # cargo alias to allow reuse of config locally

check-executor-features:
runs-on: ubuntu-latest
strategy:
matrix:
executor: [
"--features tokio",
"--features async-std",
""
]
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- uses: Swatinem/rust-cache@22c9328bcba27aa81a32b1bef27c7e3c78052531 # v2.0.1

- name: Run cargo check
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: check --all-targets --features=all-transports ${{ matrix.executor }}

integration-test:
name: Integration tests
runs-on: ubuntu-latest
Expand Down

0 comments on commit dbfad1e

Please sign in to comment.