name: Test on: workflow_call: inputs: skip_coverage: description: "Skip coverage job" required: false default: false type: boolean push: branches: [main, dev] pull_request: branches: [main, dev] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: read id-token: write # Required for OIDC with Codecov jobs: code-formatting: name: Code Formatting runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - run: cargo fmt --check code-linter: name: Code Linter runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - uses: ./.github/actions/rust with: components: clippy - name: Run cargo clippy env: SQLX_OFFLINE: true run: | cargo clippy --all-features --workspace --tests -- -D warnings tests: name: Tests timeout-minutes: 40 runs-on: ubuntu-latest steps: - name: Free up disk space run: | echo "Disk space before cleanup:" df -h # Remove unnecessary packages sudo rm -rf /usr/share/dotnet sudo rm -rf /usr/local/lib/android sudo rm -rf /opt/ghc sudo rm -rf /opt/hostedtoolcache/CodeQL sudo docker image prune --all --force sudo apt-get clean echo "Disk space after cleanup:" df -h - name: Checkout repository uses: actions/checkout@v4 - uses: ./.github/actions/rust - name: Install cargo-nextest uses: taiki-e/install-action@v2 with: tool: nextest - name: Install cargo-near run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.16.1/cargo-near-installer.sh | sh - name: Run tests env: SQLX_OFFLINE: true # Use nextest CI profile with reduced parallelism NEXTEST_PROFILE: ci # Optimize cargo build for faster compilation CARGO_TERM_COLOR: always CARGO_INCREMENTAL: 0 run: ./script/test.sh - name: Cleanup Docker resources if: always() run: | docker compose --file ./service/relayer/compose.dev.yaml down -v || true docker system prune -af --volumes || true coverage: name: Coverage runs-on: ubuntu-latest # Skip coverage when called from other workflows with skip_coverage=true if: ${{ !inputs.skip_coverage }} steps: - name: Free up disk space run: | echo "Disk space before cleanup:" df -h # Remove large pre-installed packages sudo rm -rf /usr/share/dotnet sudo rm -rf /usr/local/lib/android sudo rm -rf /opt/ghc sudo rm -rf /opt/hostedtoolcache/CodeQL sudo rm -rf /usr/local/share/boost sudo rm -rf "$AGENT_TOOLSDIRECTORY" # Remove unnecessary packages sudo apt-get remove -y '^aspnetcore-.*' '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' '^mysql-.*' azure-cli google-chrome-stable firefox powershell mono-devel || true sudo apt-get autoremove -y sudo apt-get clean # Clean Docker sudo docker image prune --all --force sudo docker system prune --all --volumes --force echo "Disk space after cleanup:" df -h - name: Checkout repository uses: actions/checkout@v4 - uses: ./.github/actions/rust with: components: llvm-tools-preview - name: Install tools uses: taiki-e/install-action@v2 with: tool: cargo-llvm-cov,nextest - name: Run tests with coverage env: SQLX_OFFLINE: true CARGO_INCREMENTAL: 0 RUSTFLAGS: "-Cinstrument-coverage" # Use nextest CI profile with optimized parallelism NEXTEST_PROFILE: ci CARGO_TERM_COLOR: always run: | # --lib: unit tests only (excludes slow WASM integration tests) cargo llvm-cov nextest --lib --lcov --output-path coverage.lcov # Aggressive cleanup to free disk space echo "Cleaning up build artifacts..." rm -rf target/llvm-cov-target/*/debug/deps/*.profraw 2>/dev/null || true rm -rf target/llvm-cov-target/*/debug/incremental 2>/dev/null || true rm -rf target/llvm-cov-target/*/debug/build 2>/dev/null || true rm -rf target/debug/incremental 2>/dev/null || true rm -rf target/debug/build 2>/dev/null || true # Remove unnecessary cargo cache rm -rf ~/.cargo/registry/index rm -rf ~/.cargo/registry/cache rm -rf ~/.cargo/git/db echo "Disk space after cleanup:" df -h - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: files: coverage.lcov flags: unittests name: templar-protocol-coverage fail_ci_if_error: true verbose: true token: ${{ secrets.CODECOV_TOKEN }}