Merge pull request #1121 from scriptnovaa/feature/implement-loop-opti… #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rust CI | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| - main | |
| pull_request: | |
| branches: | |
| - develop | |
| - main | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| frontend: | |
| name: Frontend UI Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Audit NPM dependencies | |
| run: npm audit --audit-level=moderate | |
| - name: Run frontend tests with coverage | |
| run: npm run test:coverage -- --ci --reporters=default | |
| check: | |
| name: Check, Lint & Test | |
| runs-on: ubuntu-latest | |
| # Hard cap: entire job must complete within 30 minutes. | |
| # Prevents runaway builds from blocking the merge queue indefinitely. | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Record job start time | |
| run: echo "JOB_START=$(date +%s)" >> "$GITHUB_ENV" | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Lint commit messages | |
| uses: wagoid/commitlint-github-action@v6 | |
| continue-on-error: true | |
| with: | |
| configFile: .commitlintrc.json | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| components: clippy, rustfmt | |
| # ── Cache ──────────────────────────────────────────── | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| # Cache key prefix — increment to bust cache manually | |
| prefix-key: "v1-rust" | |
| # Cache the registry and target directories | |
| shared-key: "crowdfund" | |
| cache-targets: true | |
| cache-all-crates: true | |
| # ── Alternative: using actions/cache directly ──────── | |
| # Uncomment below and remove rust-cache above if preferred: | |
| # | |
| # - name: Cache cargo registry | |
| # uses: actions/cache@v3 | |
| # with: | |
| # path: | | |
| # ~/.cargo/registry | |
| # ~/.cargo/git | |
| # target/ | |
| # key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| # restore-keys: | | |
| # ${{ runner.os }}-cargo- | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Build crowdfund WASM for tests | |
| # Bound: WASM build should complete within 10 minutes on a warm cache. | |
| timeout-minutes: 10 | |
| run: cargo build --release --target wasm32-unknown-unknown -p crowdfund | |
| - name: Run Clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run tests including property-based tests | |
| # Bound: test suite must complete within 15 minutes. | |
| timeout-minutes: 15 | |
| env: | |
| PROPTEST_CASES: 1000 | |
| run: cargo test --workspace | |
| - name: Generate Rustdoc | |
| run: cargo doc --no-deps --workspace | |
| - name: Report WASM binary size | |
| run: ls -lh target/wasm32-unknown-unknown/release/crowdfund.wasm | |
| - name: Install wasm-opt (Binaryen) | |
| run: sudo apt-get install -y binaryen | |
| - name: Optimize WASM with wasm-opt | |
| run: | | |
| wasm-opt -Oz --enable-sign-ext \ | |
| target/wasm32-unknown-unknown/release/crowdfund.wasm \ | |
| -o target/wasm32-unknown-unknown/release/crowdfund.opt.wasm | |
| - name: Fail if WASM exceeds 256 KB | |
| run: | | |
| SIZE=$(stat -c%s target/wasm32-unknown-unknown/release/crowdfund.opt.wasm) | |
| MAX=$((256 * 1024)) | |
| if [ "$SIZE" -gt "$MAX" ]; then | |
| echo "WASM binary too large: $SIZE bytes (max $MAX bytes)" | |
| exit 1 | |
| else | |
| echo "WASM size OK: $SIZE bytes" | |
| fi | |
| - name: Log total job elapsed time | |
| if: always() | |
| run: | | |
| END=$(date +%s) | |
| ELAPSED=$(( END - JOB_START )) | |
| echo "Total job time: ${ELAPSED}s" | |
| # Warn (but do not fail) if elapsed exceeds the soft target of 20 min. | |
| SOFT_LIMIT_S=$(( 20 * 60 )) | |
| if [ "$ELAPSED" -gt "$SOFT_LIMIT_S" ]; then | |
| echo "::warning::Job took ${ELAPSED}s — exceeds soft limit of ${SOFT_LIMIT_S}s. Consider optimising slow steps." | |
| fi |