feat(ci): add caching for Cargo registries and binaries in CI workflows #102
Workflow file for this run
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: CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
permissions: | |
contents: write | |
checks: write | |
pull-requests: write | |
env: | |
CARGO_TERM_COLOR: always | |
SQLX_OFFLINE: true | |
LANG: en_US.UTF-8 | |
CARGO_HOME: ${{ github.workspace }}/.cargo | |
jobs: | |
build: | |
name: Build and Test | |
container: | |
image: rust:latest | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache Cargo registries and git checkouts | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.CARGO_HOME }}/.cargo/registry | |
${{ env.CARGO_HOME }}/.cargo/git | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo installed binaries | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.CARGO_HOME }}/.cargo/bin | |
key: ${{ runner.os }}-cargo-bin-${{ hashFiles('.github/workflows/*.yml') }} | |
- name: Add Cargo bin to PATH | |
run: echo "PATH=$PATH:${{ env.CARGO_HOME }}/.cargo/bin" >> $GITHUB_ENV | |
- name: Prep OS | |
run: | | |
apt-get update && apt-get install -y jq | |
- name: Create .env file | |
run: cp .env.template .env | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
with: | |
cache-on-failure: true | |
- name: Install Cargo Tools | |
run: | | |
rustup target add wasm32-unknown-unknown | |
cargo install --locked --jobs "$(nproc)" trunk wasm-bindgen-cli wasm-opt sqlx-cli | |
- name: Build | |
run: cargo build | |
- name: Run tests | |
run: cargo test | |
- name: Build frontend | |
working-directory: frontend | |
run: | | |
TRUNK_DIR=${{ env.CARGO_HOME }}/.cargo/bin | |
TRUNK_DIR=$(realpath $TRUNK_DIR) | |
echo "Running trunk from $TRUNK_DIR" | |
$TRUNK_DIR/trunk build --release | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: frontend/dist/ | |
retention-days: 7 |