Skip to content

Github CI: Test CI to reduce build time with matrix concurrency #662

Github CI: Test CI to reduce build time with matrix concurrency

Github CI: Test CI to reduce build time with matrix concurrency #662

name: ci
on:
pull_request:
paths-ignore:
- "**.md"
- "doc/**"
workflow_dispatch:
defaults:
run:
shell: bash
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev
- name: Install Rust nightly
run: rustup toolchain install nightly
- name: Show active toolchain
run: rustup show active-toolchain
- name: Add nightly rustfmt
run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
- name: Cache rust toolchain and dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/
target/
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-rust-
- name: Rustfmt
run: cargo +nightly fmt --all -- --check
clippy:
runs-on: ubuntu-latest
needs: rustfmt
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler libssl-dev
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/
target/
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-rust-
- name: Cargo Clippy
run: rustup component add rust-src && cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings
check-runtime-benchmarks:
runs-on: ubuntu-latest
needs: rustfmt
strategy:
matrix:
feature_flag: [true, false] # Two runs: with and without the 'runtime-benchmarks' feature
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq protobuf-compiler libssl-dev
- name: Cache rust toolchain and dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/
target/
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-rust-
- name: Determine packages to test
id: set_packages
run: |
echo "Checking for 'runtime-benchmarks' feature in Cargo.toml files..."
packages_with_feature=()
packages_without_feature=()
for cargo_file in $(find . -name "Cargo.toml"); do
if grep -q "\[features\]" "$cargo_file"; then
if grep -q "runtime-benchmarks" "$cargo_file"; then
package_name=$(basename $(dirname "$cargo_file"))
packages_with_feature+=("$package_name")
else
package_name=$(basename $(dirname "$cargo_file"))
packages_without_feature+=("$package_name")
fi
else
package_name=$(basename $(dirname "$cargo_file"))
packages_without_feature+=("$package_name")
fi
done
# Output lists as JSON arrays
echo "::set-output name=packages_with_feature::$(printf '["%s"]' "${packages_with_feature[@]}" | jq -R . | jq -s .)"
echo "::set-output name=packages_without_feature::$(printf '["%s"]' "${packages_without_feature[@]}" | jq -R . | jq -s .)"
- name: Run tests
run: |
if [[ ${{ matrix.feature_flag }} == "true" ]]; then
# Test with runtime-benchmarks feature
for package in ${{ fromJson(steps.set_packages.outputs.packages_with_feature) }}; do
echo "Running tests for package: $package with 'runtime-benchmarks' feature"
cargo test --release --package "$package" --features "runtime-benchmarks" --no-fail-fast
done
else
# Test without runtime-benchmarks feature
for package in ${{ fromJson(steps.set_packages.outputs.packages_without_feature) }}; do
echo "Running tests for package: $package without 'runtime-benchmarks' feature"
cargo test --release --package "$package" --no-fail-fast
done
fi