From 73a44cace7dcb4d81ca0d4c9f81eaec064bed06c Mon Sep 17 00:00:00 2001 From: Alphonse Paix Date: Thu, 2 Oct 2025 10:44:29 +0200 Subject: [PATCH] update workflow --- .github/workflows/general.yml | 151 ++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 7 deletions(-) diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index b02f24a..8300d8f 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -18,9 +18,73 @@ env: APP_KV_STORE__HOST: redis jobs: + # This job builds and caches artifacts for other jobs to use + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Install mold linker + run: | + sudo apt-get update + sudo apt-get install -y mold clang + + # LONG-TERM CACHE: Cargo registry (shared across workflows) + - name: Cache cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + key: cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + cargo-registry- + + # LONG-TERM CACHE: sqlx-cli binary (shared across workflows) + - name: Cache sqlx-cli + id: cache-sqlx + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/sqlx + ~/.cargo/bin/cargo-sqlx + key: sqlx-cli-${{ env.SQLX_VERSION }} + + # LONG-TERM CACHE: Rust toolchain (shared across workflows) + # Note: Keep cache: false if it times out, the toolchain itself is cached by rustup + - name: Install the Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + cache: false + + - name: Install sqlx-cli + if: steps.cache-sqlx.outputs.cache-hit != 'true' + run: cargo install sqlx-cli + --version=${{ env.SQLX_VERSION }} + --features ${{ env.SQLX_FEATURES }} + --no-default-features + --locked + + # Build the project + - name: Build + run: cargo build --release + + # WORKFLOW-ONLY CACHE: Upload build artifacts for other jobs + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + target/ + ~/.cargo/bin/ + test: name: Test runs-on: ubuntu-latest + needs: build # Wait for build to complete services: postgres: image: postgres @@ -37,24 +101,29 @@ jobs: steps: - name: Check out repository code uses: actions/checkout@v4 + - name: Install mold linker run: | sudo apt-get update sudo apt-get install -y mold clang + + # Download build artifacts from the build job + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifacts + - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: cache: false - - name: Install sqlx-cli - run: cargo install sqlx-cli - --version=${{ env.SQLX_VERSION }} - --features ${{ env.SQLX_FEATURES }} - --no-default-features - --locked + - name: Migrate database run: cargo sqlx migrate run + - name: Run tests run: TEST_LOG=true cargo test + - name: Check that queries are fresh run: cargo sqlx prepare --check --workspace @@ -63,26 +132,55 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + + # LONG-TERM CACHE: Cargo registry + - name: Cache cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + key: cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + cargo-registry- + - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: rustfmt cache: false + - name: Enforce formatting run: cargo fmt --check clippy: name: Clippy runs-on: ubuntu-latest + needs: build # Use artifacts from build env: SQLX_OFFLINE: true steps: - - uses: actions/checkout@v4 + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Install mold linker + run: | + sudo apt-get update + sudo apt-get install -y mold clang + + # Download build artifacts + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifacts + - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: clippy cache: false + - name: Linting run: cargo clippy -- -D warnings @@ -104,26 +202,65 @@ jobs: - 16379:6379 steps: - uses: actions/checkout@v4 + - name: Install mold linker run: | sudo apt-get update sudo apt-get install -y mold clang + + # LONG-TERM CACHE: Cargo registry + - name: Cache cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + key: cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + cargo-registry- + + # LONG-TERM CACHE: sqlx-cli + - name: Cache sqlx-cli + id: cache-sqlx-cov + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/sqlx + ~/.cargo/bin/cargo-sqlx + key: sqlx-cli-${{ env.SQLX_VERSION }} + + # LONG-TERM CACHE: cargo-llvm-cov + - name: Cache cargo-llvm-cov + id: cache-llvm-cov + uses: actions/cache@v3 + with: + path: ~/.cargo/bin/cargo-llvm-cov + key: cargo-llvm-cov-0.6.0 # Pin to a version + - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: llvm-tools-preview cache: false + - name: Install sqlx-cli + if: steps.cache-sqlx-cov.outputs.cache-hit != 'true' run: cargo install sqlx-cli --version=${{ env.SQLX_VERSION }} --features ${{ env.SQLX_FEATURES }} --no-default-features --locked + - name: Migrate database run: cargo sqlx migrate run + - name: Install cargo-llvm-cov + if: steps.cache-llvm-cov.outputs.cache-hit != 'true' uses: taiki-e/install-action@cargo-llvm-cov + - name: Generate code coverage run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + - name: Generate report run: cargo llvm-cov report --html --output-dir coverage