Skip to content

Commit

Permalink
feat(ci): sccache
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki WADA committed Apr 12, 2023
1 parent 24b1f4d commit 5309f69
Showing 1 changed file with 51 additions and 13 deletions.
64 changes: 51 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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:
Expand All @@ -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/[email protected]
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/[email protected]
- uses: LoliGothick/[email protected]
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

0 comments on commit 5309f69

Please sign in to comment.