|
| 1 | +name: CI-Tests-Optimized |
| 2 | + |
| 3 | +# This is a test optimization workflow that runs tests more efficiently |
| 4 | +# It does NOT build Docker images or upload any artifacts |
| 5 | +# Safe to test on PRs without affecting production |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + pull_request: |
| 10 | + types: [opened, reopened, synchronize, edited] |
| 11 | + |
| 12 | +env: |
| 13 | + RUSTFLAGS: "-D warnings -C link-arg=-fuse-ld=lld" |
| 14 | + RUST_BACKTRACE: 1 |
| 15 | + CARGO_TERM_COLOR: always |
| 16 | + CARGO_INCREMENTAL: 0 |
| 17 | + NEXTEST_RETRIES: 2 |
| 18 | + |
| 19 | +# Unique concurrency group to not interfere with existing workflows |
| 20 | +concurrency: |
| 21 | + group: ci-tests-only-${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'pull_request' && 'PR' || github.sha }} |
| 22 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Quick checks that should pass before running expensive tests |
| 26 | + quick-checks: |
| 27 | + name: Quick Checks |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Install Rust |
| 33 | + uses: dtolnay/rust-toolchain@stable |
| 34 | + with: |
| 35 | + components: rustfmt, clippy |
| 36 | + |
| 37 | + - uses: Swatinem/rust-cache@v2 |
| 38 | + with: |
| 39 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 40 | + |
| 41 | + - name: Check formatting |
| 42 | + run: cargo fmt --all -- --check |
| 43 | + |
| 44 | + - name: Check Cargo.lock |
| 45 | + run: | |
| 46 | + cargo update -w --locked |
| 47 | + git diff --exit-code Cargo.lock |
| 48 | + |
| 49 | + - name: Install cargo-machete |
| 50 | + uses: taiki-e/install-action@v2 |
| 51 | + with: |
| 52 | + tool: cargo-machete |
| 53 | + |
| 54 | + - name: Check unused dependencies |
| 55 | + run: cargo machete |
| 56 | + |
| 57 | + - name: Install taplo |
| 58 | + uses: taiki-e/install-action@v2 |
| 59 | + with: |
| 60 | + tool: taplo-cli |
| 61 | + |
| 62 | + - name: Check TOML formatting |
| 63 | + run: taplo fmt --check |
| 64 | + |
| 65 | + # Detect which files changed to optimize what we test |
| 66 | + detect-changes: |
| 67 | + name: Detect Changes |
| 68 | + runs-on: ubuntu-latest |
| 69 | + outputs: |
| 70 | + rust-changed: ${{ steps.filter.outputs.rust }} |
| 71 | + blockifier-changed: ${{ steps.filter.outputs.blockifier }} |
| 72 | + papyrus-changed: ${{ steps.filter.outputs.papyrus }} |
| 73 | + committer-changed: ${{ steps.filter.outputs.committer }} |
| 74 | + sequencer-changed: ${{ steps.filter.outputs.sequencer }} |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - uses: dorny/paths-filter@v3 |
| 79 | + id: filter |
| 80 | + with: |
| 81 | + filters: | |
| 82 | + rust: |
| 83 | + - '**/*.rs' |
| 84 | + - '**/Cargo.toml' |
| 85 | + - 'Cargo.lock' |
| 86 | + - 'rust-toolchain.toml' |
| 87 | + blockifier: |
| 88 | + - 'crates/blockifier/**' |
| 89 | + - 'crates/blockifier_test_utils/**' |
| 90 | + - 'crates/native_blockifier/**' |
| 91 | + papyrus: |
| 92 | + - 'crates/papyrus**/**' |
| 93 | + committer: |
| 94 | + - 'crates/starknet_committer/**' |
| 95 | + - 'crates/starknet_patricia/**' |
| 96 | + sequencer: |
| 97 | + - 'crates/apollo**/**' |
| 98 | +
|
| 99 | + # Generate test matrix dynamically based on workspace crates |
| 100 | + generate-test-matrix: |
| 101 | + name: Generate Test Matrix |
| 102 | + runs-on: ubuntu-latest |
| 103 | + needs: [quick-checks, detect-changes] |
| 104 | + outputs: |
| 105 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Install Rust |
| 110 | + uses: dtolnay/rust-toolchain@stable |
| 111 | + |
| 112 | + - name: Generate crate matrix |
| 113 | + id: set-matrix |
| 114 | + run: | |
| 115 | + # Get all workspace members |
| 116 | + CRATES=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_members[] | split(" ") | .[0]') |
| 117 | + |
| 118 | + # Convert to JSON array |
| 119 | + MATRIX=$(echo "$CRATES" | jq -R -s -c 'split("\n") | map(select(length > 0))') |
| 120 | + |
| 121 | + echo "matrix=$MATRIX" >> $GITHUB_OUTPUT |
| 122 | + echo "Generated matrix with $(echo "$CRATES" | wc -l) crates" |
| 123 | +
|
| 124 | + # Run clippy and tests for each crate in parallel |
| 125 | + test: |
| 126 | + name: Test ${{ matrix.crate }} |
| 127 | + runs-on: ubuntu-latest |
| 128 | + needs: [generate-test-matrix, detect-changes] |
| 129 | + if: needs.detect-changes.outputs.rust-changed == 'true' |
| 130 | + strategy: |
| 131 | + fail-fast: false |
| 132 | + matrix: |
| 133 | + crate: ${{ fromJson(needs.generate-test-matrix.outputs.matrix) }} |
| 134 | + steps: |
| 135 | + - uses: actions/checkout@v4 |
| 136 | + |
| 137 | + - name: Install Rust |
| 138 | + uses: dtolnay/rust-toolchain@stable |
| 139 | + with: |
| 140 | + components: clippy |
| 141 | + |
| 142 | + - uses: Swatinem/rust-cache@v2 |
| 143 | + with: |
| 144 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 145 | + |
| 146 | + - name: Install nextest |
| 147 | + uses: taiki-e/install-action@v2 |
| 148 | + with: |
| 149 | + tool: cargo-nextest |
| 150 | + |
| 151 | + # Install Python for crates that need it (OS compilation) |
| 152 | + - name: Setup Python (if needed) |
| 153 | + if: contains(matrix.crate, 'starknet_os') || contains(matrix.crate, 'blockifier') |
| 154 | + uses: actions/setup-python@v5 |
| 155 | + with: |
| 156 | + python-version: 'pypy3.9' |
| 157 | + cache: 'pip' |
| 158 | + |
| 159 | + - name: Install Python dependencies (if needed) |
| 160 | + if: contains(matrix.crate, 'starknet_os') || contains(matrix.crate, 'blockifier') |
| 161 | + run: | |
| 162 | + pip install -r scripts/requirements.txt |
| 163 | + ln -s $(which pypy3.9) /usr/local/bin/pypy3.9 || true |
| 164 | + |
| 165 | + - name: Run clippy |
| 166 | + run: | |
| 167 | + cargo clippy -p ${{ matrix.crate }} --all-targets --all-features -- -D warnings |
| 168 | + |
| 169 | + - name: Run tests |
| 170 | + run: | |
| 171 | + cargo nextest run -p ${{ matrix.crate }} --retries ${{ env.NEXTEST_RETRIES }} |
| 172 | + env: |
| 173 | + RUST_LOG: warn |
| 174 | + SEED: 0 |
| 175 | + |
| 176 | + # Workspace compilation, docs, and tests (share compilation cache) |
| 177 | + workspace-checks: |
| 178 | + name: Workspace Checks |
| 179 | + runs-on: ubuntu-latest |
| 180 | + needs: quick-checks |
| 181 | + steps: |
| 182 | + - uses: actions/checkout@v4 |
| 183 | + |
| 184 | + - name: Install Rust |
| 185 | + uses: dtolnay/rust-toolchain@stable |
| 186 | + with: |
| 187 | + components: clippy |
| 188 | + |
| 189 | + - uses: Swatinem/rust-cache@v2 |
| 190 | + with: |
| 191 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 192 | + |
| 193 | + # First, run clippy on the entire workspace to get all compilation done |
| 194 | + - name: Run workspace clippy |
| 195 | + run: cargo clippy --workspace --all-targets --all-features -- -D warnings |
| 196 | + |
| 197 | + # Now docs can reuse the compilation artifacts |
| 198 | + - name: Build documentation |
| 199 | + run: cargo doc --workspace --no-deps --document-private-items |
| 200 | + env: |
| 201 | + RUSTDOCFLAGS: "-D warnings" |
| 202 | + |
| 203 | + # And workspace tests also reuse the cache |
| 204 | + - name: Run workspace tests |
| 205 | + run: cargo test -p workspace_tests |
| 206 | + |
| 207 | + # Test specific feature combinations for key crates |
| 208 | + test-features: |
| 209 | + name: Test Features |
| 210 | + runs-on: ubuntu-latest |
| 211 | + needs: [quick-checks, detect-changes] |
| 212 | + if: needs.detect-changes.outputs.blockifier-changed == 'true' |
| 213 | + strategy: |
| 214 | + matrix: |
| 215 | + include: |
| 216 | + - crate: blockifier |
| 217 | + features: "" |
| 218 | + - crate: blockifier |
| 219 | + features: "--features transaction_serde" |
| 220 | + - crate: blockifier |
| 221 | + features: "--features cairo_native" |
| 222 | + - crate: blockifier |
| 223 | + features: "--features tracing" |
| 224 | + steps: |
| 225 | + - uses: actions/checkout@v4 |
| 226 | + |
| 227 | + - name: Install Rust |
| 228 | + uses: dtolnay/rust-toolchain@stable |
| 229 | + |
| 230 | + - uses: Swatinem/rust-cache@v2 |
| 231 | + with: |
| 232 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 233 | + |
| 234 | + - name: Install nextest |
| 235 | + uses: taiki-e/install-action@v2 |
| 236 | + with: |
| 237 | + tool: cargo-nextest |
| 238 | + |
| 239 | + - name: Setup Python |
| 240 | + uses: actions/setup-python@v5 |
| 241 | + with: |
| 242 | + python-version: 'pypy3.9' |
| 243 | + cache: 'pip' |
| 244 | + |
| 245 | + - name: Install Python dependencies |
| 246 | + run: | |
| 247 | + pip install -r scripts/requirements.txt |
| 248 | + ln -s $(which pypy3.9) /usr/local/bin/pypy3.9 || true |
| 249 | + |
| 250 | + - name: Test with features |
| 251 | + run: | |
| 252 | + cargo nextest run -p ${{ matrix.crate }} ${{ matrix.features }} --retries ${{ env.NEXTEST_RETRIES }} |
| 253 | +
|
| 254 | + # Integration tests (run separately as they're slower) |
| 255 | + integration-tests: |
| 256 | + name: Integration Tests |
| 257 | + runs-on: ubuntu-latest |
| 258 | + needs: [quick-checks, detect-changes] |
| 259 | + if: needs.detect-changes.outputs.sequencer-changed == 'true' |
| 260 | + steps: |
| 261 | + - uses: actions/checkout@v4 |
| 262 | + |
| 263 | + - name: Install Rust |
| 264 | + uses: dtolnay/rust-toolchain@stable |
| 265 | + |
| 266 | + - uses: Swatinem/rust-cache@v2 |
| 267 | + with: |
| 268 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 269 | + |
| 270 | + - name: Install nextest |
| 271 | + uses: taiki-e/install-action@v2 |
| 272 | + with: |
| 273 | + tool: cargo-nextest |
| 274 | + |
| 275 | + - name: Setup Python |
| 276 | + uses: actions/setup-python@v5 |
| 277 | + with: |
| 278 | + python-version: 'pypy3.9' |
| 279 | + cache: 'pip' |
| 280 | + |
| 281 | + - name: Install Python dependencies |
| 282 | + run: | |
| 283 | + pip install -r scripts/requirements.txt |
| 284 | + ln -s $(which pypy3.9) /usr/local/bin/pypy3.9 || true |
| 285 | + |
| 286 | + # Build all binaries together to maximize cache sharing |
| 287 | + - name: Build integration test binaries |
| 288 | + run: | |
| 289 | + cargo build --bins -p apollo_node -p apollo_integration_tests || true |
| 290 | + |
| 291 | + # Run integration tests |
| 292 | + - name: Run integration tests |
| 293 | + run: | |
| 294 | + # Run available integration test binaries |
| 295 | + for test in integration_test_positive_flow integration_test_restart_flow integration_test_revert_flow; do |
| 296 | + if [ -f "target/debug/$test" ]; then |
| 297 | + echo "Running $test..." |
| 298 | + "./target/debug/$test" || true |
| 299 | + fi |
| 300 | + done |
| 301 | + |
| 302 | + # Run integration tests via nextest as well |
| 303 | + cargo nextest run -p apollo_integration_tests || true |
| 304 | +
|
| 305 | + # Papyrus-specific tests |
| 306 | + papyrus-tests: |
| 307 | + name: Papyrus Tests |
| 308 | + runs-on: ubuntu-latest |
| 309 | + needs: [quick-checks, detect-changes] |
| 310 | + if: needs.detect-changes.outputs.papyrus-changed == 'true' |
| 311 | + steps: |
| 312 | + - uses: actions/checkout@v4 |
| 313 | + |
| 314 | + - name: Install Rust |
| 315 | + uses: dtolnay/rust-toolchain@stable |
| 316 | + |
| 317 | + - uses: Swatinem/rust-cache@v2 |
| 318 | + with: |
| 319 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 320 | + |
| 321 | + - name: Build Papyrus |
| 322 | + run: | |
| 323 | + mkdir -p data |
| 324 | + cargo build -p papyrus_node |
| 325 | + |
| 326 | + - name: Test Papyrus startup |
| 327 | + run: | |
| 328 | + timeout 30s target/debug/papyrus_node --chain_id SN_SEPOLIA --base_layer.node_url ${{ secrets.CI_BASE_LAYER_NODE_URL }} || [ $? -eq 124 ] |
| 329 | + |
| 330 | + - name: Run Papyrus integration tests |
| 331 | + run: | |
| 332 | + cargo test --test latency_histogram --test gateway_integration_test --test feeder_gateway_integration_test -- --include-ignored --skip test_gw_integration_testnet |
| 333 | + cargo run -p papyrus_node --bin central_source_integration_test --features="futures-util tokio-stream" || true |
| 334 | +
|
| 335 | + # Final status check |
| 336 | + ci-success: |
| 337 | + name: CI Success |
| 338 | + needs: [quick-checks, test, test-features, integration-tests, workspace-checks, papyrus-tests] |
| 339 | + runs-on: ubuntu-latest |
| 340 | + steps: |
| 341 | + - name: Check all jobs |
| 342 | + run: | |
| 343 | + if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then |
| 344 | + echo "One or more jobs failed" |
| 345 | + exit 1 |
| 346 | + else |
| 347 | + echo "All jobs succeeded" |
| 348 | + fi |
0 commit comments