ci: 👷 Improve CI job for rust tests and format (#9)

This commit is contained in:
Facundo Farall 2025-03-19 20:30:03 -03:00 committed by GitHub
parent 70a034fab7
commit 55a1ef26b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 12579 additions and 96 deletions

View file

@ -1,90 +0,0 @@
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
WORKING_DIR: operator
jobs:
cargo-check:
name: Cargo Check
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check
cargo-fmt:
name: Cargo Format
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run cargo fmt
run: cargo fmt --all -- --check
cargo-test:
name: Cargo Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --verbose

View file

@ -1,3 +1,8 @@
# Foundry Tests: CI for Foundry components (smart contracts for EigenLayer and Snowbridge interaction)
#
# Overview:
# 1. All Foundry Tests: Executes the full suite of Foundry tests found within the `./contracts` directory
name: Foundry AVS Smart Contract Tests
on:

117
.github/workflows/rust-lint.yml vendored Normal file
View file

@ -0,0 +1,117 @@
# Lint and Format: CI for Rust components (DataHaven runtime and node Rust tests)
#
# Overview:
# 1. Check Rust Format: Check that the Rust code is formatted correctly
# 2. Check Rust Lint: Check that the Rust code is linted correctly
name: Lint and Format
on:
pull_request:
push:
branches:
- main
- perm-*
workflow_dispatch:
inputs:
pull_request:
description: set to pull_request number to execute on external pr
required: false
env:
CARGO_TERM_COLOR: always
WORKING_DIR: operator
jobs:
setup:
runs-on: ubuntu-latest
outputs:
node_changed: ${{ steps.node_check.outputs.changed }}
env:
SKIP_BUILD_LABEL_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'skip-node-build') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if Substrate Node needs rebuild
id: node_check
run: |
BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}"
HEAD_SHA="${{ github.sha }}"
if [[ "${{ env.SKIP_BUILD_LABEL_PRESENT }}" != "true" ]] && git diff --name-only $BASE_SHA $HEAD_SHA | grep -E '^operator/(client|node|pallets|runtime)/|^operator/Cargo\.toml$'; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Comparing changes from $BASE_SHA to $HEAD_SHA"
echo "changed=false" >> $GITHUB_OUTPUT
fi
cargo-fmt:
needs: [setup]
if: needs.setup.outputs.node_changed == 'true'
name: "Check format with rustfmt"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
# ! If this action starts failing, it may be because of this,
# ! For now this is not needed, and makes the workflow slower
# - name: Install protoc
# run: |
# sudo apt-get update
# sudo apt-get install -y protobuf-compiler
# protoc --version
- name: Run cargo fmt
run: cargo fmt --all -- --check
check-rust-lint:
needs: [setup]
if: needs.setup.outputs.node_changed == 'true'
name: "Check lint with clippy"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install libpq-dev
run: sudo apt-get update && sudo apt-get install -y libpq-dev
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
- name: Run cargo clippy
run: SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --features try-runtime,runtime-benchmarks --locked
env:
RUSTFLAGS: -D warnings

109
.github/workflows/rust-tests.yml vendored Normal file
View file

@ -0,0 +1,109 @@
# Rust Tests: CI for Rust components (DataHaven runtime and node Rust tests)
#
# Overview:
# 1. Prepare: This job handles the setup phase where the cargo nextest archive is created
# and uploaded to the workflow for use in the subsequent jobs
# 2. All Rust Tests: Executes the full suite of Rust tests across two partitions to
# to reduce total execution time.
name: DataHave Operator Rust Tests
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
jobs:
setup:
runs-on: ubuntu-latest
outputs:
node_changed: ${{ steps.node_check.outputs.changed }}
env:
SKIP_BUILD_LABEL_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'skip-node-build') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if Substrate Node needs rebuild
id: node_check
run: |
BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}"
HEAD_SHA="${{ github.sha }}"
if [[ "${{ env.SKIP_BUILD_LABEL_PRESENT }}" != "true" ]] && git diff --name-only $BASE_SHA $HEAD_SHA | grep -E '^operator/(client|node|pallets|runtime)/|^operator/Cargo\.toml$'; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Comparing changes from $BASE_SHA to $HEAD_SHA"
echo "changed=false" >> $GITHUB_OUTPUT
fi
prepare:
needs: [setup]
if: needs.setup.outputs.node_changed == 'true'
name: Prepare artifacts for Rust tests
runs-on: ubuntu-latest
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
CARGO_TERM_COLOR: always
defaults:
run:
working-directory: ./operator
steps:
- uses: actions/checkout@v4
with:
# By default actions/checkout checks out a merge commit. Check out the PR head instead.
# https://github.com/actions/checkout#checkout-pull-request-head-commit-instead-of-merge-commit
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions-rust-lang/setup-rust-toolchain@v1.8
with:
cache: false
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4
- uses: rui314/setup-mold@v1
- name: Install nextest
uses: taiki-e/install-action@nextest
# Install libpq-dev
- name: Install libpq-dev
run: sudo apt-get update && sudo apt-get install -y libpq-dev
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: Build and archive tests
run: cargo nextest archive --archive-file nextest-archive.tar.zst
- name: Upload archive to workflow
uses: actions/upload-artifact@v4
with:
name: nextest-archive
path: ./operator/nextest-archive.tar.zst
all-rust-tests:
needs: [setup, prepare]
if: needs.setup.outputs.node_changed == 'true'
name: Run all Operator Rust tests (/w partitioning)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
partition: [1, 2]
defaults:
run:
working-directory: ./operator
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Download archive
uses: actions/download-artifact@v4
with:
name: nextest-archive
- name: Run Tests for All Projects!
run: |
~/.cargo/bin/cargo-nextest nextest run \
--archive-file ../nextest-archive.tar.zst \
--partition count:${{ matrix.partition }}/2

4
.gitignore vendored
View file

@ -3,10 +3,6 @@
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

12346
operator/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::{Pallet as ValidatorSet, *};
use frame_benchmarking::v2::{account, benchmarks, impl_benchmark_test_suite, vec, BenchmarkError};
use frame_benchmarking::v2::{account, benchmarks, impl_test_function, BenchmarkError};
use frame_support::traits::EnsureOrigin;
use frame_system::{EventRecord, Pallet as System};

View file

@ -1,5 +1,5 @@
[toolchain]
channel = "1.81.0"
channel = "1.85"
components = [
"cargo",
"clippy",