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 mise uses: jdx/mise-action@v2 - name: Cache Cargo artifacts uses: actions/cache@v5 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: Install system dependencies run: sudo apt-get update && sudo apt-get install -y clang lld mold libssl-dev pkg-config - name: Ensure Rust components run: rustup component add rustfmt clippy - name: Check formatting run: cargo fmt -- --check - name: Clippy run: cargo clippy -- -D warnings - name: Run tests run: cargo test -- --show-output deploy: name: Deploy runs-on: ubuntu-latest needs: [check] steps: - name: Checkout uses: actions/checkout@v6 - name: Install mise uses: jdx/mise-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract version from Cargo.toml id: version run: echo "version=$(grep '^version = ' Cargo.toml | head -1 | cut -d'"' -f2)" >> "$GITHUB_OUTPUT" - name: Build and push container uses: docker/build-push-action@v6 with: context: . push: true tags: | ghcr.io/jnsgruk/brewlog:${{ github.sha }} ghcr.io/jnsgruk/brewlog:latest cache-from: type=gha cache-to: type=gha,mode=max - name: Deploy to Fly.io run: | flyctl deploy -i "ghcr.io/jnsgruk/brewlog:${{ github.sha }}" env: FLY_ACCESS_TOKEN: ${{ secrets.FLY_API_TOKEN }}