brewlog/.github/workflows/deploy.yml
Jon Seager 02235426c4
ci: speed up pipeline with cargo caching and merged jobs
Merge separate lint and test jobs into a single check job so clippy's
compilation artifacts are reused by tests. Add actions/cache for the
Cargo target directory and registry to enable incremental builds across
runs. Drop unnecessary fetch-depth: 0 from CI jobs.
2026-02-15 11:29:45 +00:00

93 lines
2.7 KiB
YAML

name: Deploy
on:
push:
branches: ["main"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install nix
uses: DeterminateSystems/nix-installer-action@main
- name: Setup Nix cache
uses: nix-community/cache-nix-action@main
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
- name: Cache Cargo artifacts
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-check
restore-keys: |
cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-
cargo-${{ runner.os }}-
- name: Check formatting
run: nix develop -c cargo fmt --check
- name: Clippy
run: nix develop -c cargo clippy
- name: Run tests
run: nix develop -c cargo test -- --show-output
deploy:
name: Deploy
runs-on: ubuntu-latest
needs:
- check
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install nix
uses: DeterminateSystems/nix-installer-action@v21
- name: Setup Nix cache
uses: nix-community/cache-nix-action@main
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container
run: |
nix build -L .#brewlog-container
- name: Upload container to ghcr.io
run: |
docker load < result
version=$(cat Cargo.toml | nix run nixpkgs#tomlq -- -r .package.version)
docker tag "brewlog:${version}" "ghcr.io/jnsgruk/brewlog:$(git rev-parse --short HEAD)"
docker push "ghcr.io/jnsgruk/brewlog:$(git rev-parse --short HEAD)"
docker tag "brewlog:${version}" "ghcr.io/jnsgruk/brewlog:latest"
docker push "ghcr.io/jnsgruk/brewlog:latest"
- name: Deploy site
run: |
nix run nixpkgs#flyctl -- deploy -i "ghcr.io/jnsgruk/brewlog:$(git rev-parse --short HEAD)"
env:
FLY_ACCESS_TOKEN: ${{ secrets.FLY_API_TOKEN }}