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

There are only so many jobs that GitHub Actions will run in parallel.
Thus, it makes sense to not create massive matrices but instead group
things together meaningfully.

The new `test` job will:

- Run once for each crate
- Ensure that the crate compiles on its specified MSRV
- Ensure that the tests pass
- Ensure that there are no semver violations

This is an improvement to before because we are running all of these
in parallel which speeds up execution and highlights more errors at
once. Previously, tests run later in the pipeline would not get run
at all until you make sure the "first" one passes.

The new `cross` job supersedes the existing `wasm` job.

This is an improvement because we now also compile the crate for
windows and MacOS. Something that wasn't checked before.

`libp2p` exposes a fair few feature-flags. Some of the combinations
are worth checking independently. For the moment, this concerns only
the executor related transports together with the executor flags but
this list can easily be extended.
  • Loading branch information
thomaseizinger committed Nov 8, 2022
1 parent 342b175 commit 569cbf6
Showing 1 changed file with 88 additions and 60 deletions.
148 changes: 88 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,120 @@ concurrency:
cancel-in-progress: true

jobs:
test-desktop: # Run tests, MSRV and semver checks for each crate.
name: Build and test
test:
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) }}
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1

- uses: actions/checkout@v3

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

- name: Check if ${{ matrix.crate }} compiles on MSRV (Rust ${{ steps.parse-msrv.outputs.version }})
run: cargo check --package ${{ matrix.crate }} --all-features

- name: Switch to latest Rust stable for tests
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true

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

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

test-wasm:
name: Build on WASM
- name: Check if crate has been released
id: check-released
run: |
RESPONSE_CODE=$(curl https://crates.io/api/v1/crates/${{ matrix.crate }} --silent --write-out "%{http_code}" --output /dev/null)
echo "code=${RESPONSE_CODE}"
echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT
- name: Check public API for semver violations
if: steps.check-released.outputs.code == 200 # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped.
run: |
cargo install cargo-semver-checks
cargo semver-checks check-release -p ${{ matrix.crate }}
cross:
name: Compile on ${{ matrix.target }}
strategy:
matrix:
include:
- target: "wasm32-unknown-unknown"
os: ubuntu-latest
- target: "wasm32-unknown-emscripten"
os: ubuntu-latest
- target: "wasm32-wasi"
os: ubuntu-latest
- target: "x86_64-apple-darwin"
os: macos-latest
- target: "x86_64-pc-windows-msvc"
os: windows-latest
runs-on: ${{ matrix.os }}
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
target: ${{ matrix.target }}

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

- run: cargo check --package libp2p --all-features --target=${{ matrix.target }}

feature_matrix: # Test various feature combinations work correctly
name: Compile with select features (${{ matrix.features }})
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: [
wasm32-unknown-emscripten,
wasm32-wasi
]
include:
- toolchain: wasm32-unknown-unknown
args: "--features wasm-bindgen"
- features: "mdns tcp dns tokio"
- features: "mdns tcp dns 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
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
target: ${{ matrix.toolchain }}
override: true

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

- 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 libp2p --features="${{ matrix.features }}"

check-rustdoc-links:
name: Check rustdoc intra-doc links
Expand All @@ -87,7 +146,7 @@ jobs:
- name: Check rustdoc links
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links --deny warnings" cargo doc --verbose --workspace --no-deps --all-features --document-private-items

check-clippy:
clippy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -116,7 +175,7 @@ jobs:
with:
command: custom-clippy # cargo alias to allow reuse of config locally

integration-test:
ipfs-integration-test:
name: Integration tests
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -184,35 +243,4 @@ jobs:
- id: cargo-metadata
run: |
WORKSPACE_MEMBERS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | .[] | select(.publish == null) | .name' | jq -s '.' | jq -c '.')
echo "::set-output name=members::${WORKSPACE_MEMBERS}"
semver-check:
runs-on: ubuntu-latest
needs: gather_published_crates
strategy:
fail-fast: false
matrix:
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@bb6001c4ea612bf59c3abfc4756fbceee4f870c7 # 0.10.0
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v3

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

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

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

- run: cargo install cargo-semver-checks

- name: Semver Check
run: cargo semver-checks check-release -p ${{ matrix.crate }}
echo "members=${WORKSPACE_MEMBERS}" >> $GITHUB_OUTPUT

0 comments on commit 569cbf6

Please sign in to comment.