From 5309f693df5844e321f2787369c04ea7c97de1bd Mon Sep 17 00:00:00 2001 From: Yuki WADA Date: Wed, 12 Apr 2023 11:29:30 +0900 Subject: [PATCH] feat(ci): sccache --- .github/workflows/ci.yaml | 64 +++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9bddf6fe..0f369024 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,9 +4,31 @@ on: env: image_name: ghcr.io/giganticminecraft/seichi-poral-backend + RUST_BACKTRACE: full + SCCACHE_CACHE_SIZE: 2G + SCCACHE_VERSION: 0.3.3 + # SCCACHE_RECACHE: 1 # Uncomment this to clear cache, then comment it back out jobs: + rustfmt: + name: rustfmt check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: rustfmt + override: true + - uses: LoliGothick/rustfmt-check@v0.3.2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + flags: --all + args: --config-path=./.cargo-husky/hooks/rustfmt.toml + working-directory: ./server + lint-and-test: + needs: [ rustfmt ] name: Lint and test server runs-on: ubuntu-latest steps: @@ -23,32 +45,48 @@ jobs: target: x86_64-unknown-linux-musl components: clippy, rustfmt - # > selecting a toolchain either by action or manual `rustup` calls should happen - # > before the plugin, as it uses the current rustc version as its cache key - # https://github.com/Swatinem/rust-cache/tree/cb2cf0cc7c5198d3364b9630e2c3d457f160790c#example-usage - - uses: Swatinem/rust-cache@v2.2.1 - with: - workspaces: "./server -> target" - # buf CLIがビルドに必要 - uses: bufbuild/buf-setup-action@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Cargo fmt - run: cargo fmt --all -- --check - working-directory: ./server + - name: Save sccache + id: restore-sccache + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + /home/runner/.cache/sccache + ~/.cargo/bin/sccache + key: sccache-${{ env.SCCACHE_VERSION }}-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + sccache-${{ env.SCCACHE_VERSION }}- + + - if: ${{ steps.restore-sccache.outputs.cache-hit == false }} + name: Install sccache + uses: actions-rs/cargo@v1 + with: + command: install + args: --version=${{ env.SCCACHE_VERSION }} --force sccache + + - name: Start sccache server + run: sccache --start-server - name: Cargo build run: cargo build working-directory: ./server - - name: Clippy check - uses: LoliGothick/clippy-check@v0.2.10 + - uses: LoliGothick/clippy-check@v0.2.11 with: token: ${{ secrets.GITHUB_TOKEN }} - options: --all-features --manifest-path ./server/Cargo.toml + deny: warnings + working-directory: ./server - name: Cargo test run: cargo test --all-features working-directory: ./server + + - name: Print sccache stats + run: sccache --show-stats + - name: Stop sccache server + run: sccache --stop-server || true