# Generated by `starci compile` from rust.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
#  - Passes are remembered in this repository's Actions cache, which GitHub
#    scopes by branch and evicts when old. starci's own store has neither
#    limit.

name: CI

on:
  push:
    branches: ['**']
    tags: ['**']
  pull_request:
  workflow_dispatch:

jobs:
  fmt:
    name: "fmt"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /Cargo.lock
            /Cargo.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-fmt-5ad6145ce9906c86-${{ hashFiles('Cargo.lock', 'Cargo.lock/**', 'Cargo.toml', 'Cargo.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "Cache: cargo-registry"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-registry
          key: starci-cache-cargo-registry-${{ github.run_id }}
          restore-keys: starci-cache-cargo-registry-
      - name: "Cache: cargo-target"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-target
          key: starci-cache-cargo-target-${{ github.run_id }}
          restore-keys: starci-cache-cargo-target-
      - name: "fmt"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            rustup component add rustfmt && cargo fmt --check
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/cargo-registry:/usr/local/cargo/registry" \
            -v "$RUNNER_TEMP/starci-cache/cargo-target:/workspace/target" \
            rust:1-slim-bookworm sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  clippy:
    name: "clippy"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /Cargo.lock
            /Cargo.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-clippy-9f4c64678c823d96-${{ hashFiles('Cargo.lock', 'Cargo.lock/**', 'Cargo.toml', 'Cargo.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "Cache: cargo-registry"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-registry
          key: starci-cache-cargo-registry-${{ github.run_id }}
          restore-keys: starci-cache-cargo-registry-
      - name: "Cache: cargo-target"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-target
          key: starci-cache-cargo-target-${{ github.run_id }}
          restore-keys: starci-cache-cargo-target-
      - name: "clippy"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            rustup component add clippy && cargo clippy --all-targets -- -D warnings
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/cargo-registry:/usr/local/cargo/registry" \
            -v "$RUNNER_TEMP/starci-cache/cargo-target:/workspace/target" \
            rust:1-slim-bookworm sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  test:
    name: "test"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /Cargo.lock
            /Cargo.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-test-4b5177ea80753245-${{ hashFiles('Cargo.lock', 'Cargo.lock/**', 'Cargo.toml', 'Cargo.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "Cache: cargo-registry"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-registry
          key: starci-cache-cargo-registry-${{ github.run_id }}
          restore-keys: starci-cache-cargo-registry-
      - name: "Cache: cargo-target"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-target
          key: starci-cache-cargo-target-${{ github.run_id }}
          restore-keys: starci-cache-cargo-target-
      - name: "test"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            cargo test --locked
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/cargo-registry:/usr/local/cargo/registry" \
            -v "$RUNNER_TEMP/starci-cache/cargo-target:/workspace/target" \
            rust:1-slim-bookworm sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  release-build:
    name: "release build"
    runs-on: ubuntu-latest
    needs: [fmt, clippy, test]
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /Cargo.lock
            /Cargo.toml
            /src
            /tests
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-release-build-f4d9509b82d7e2c2-${{ hashFiles('Cargo.lock', 'Cargo.lock/**', 'Cargo.toml', 'Cargo.toml/**', 'src', 'src/**', 'tests', 'tests/**') }}
      - name: "Cache: cargo-registry"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-registry
          key: starci-cache-cargo-registry-${{ github.run_id }}
          restore-keys: starci-cache-cargo-registry-
      - name: "Cache: cargo-target"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/cargo-target
          key: starci-cache-cargo-target-${{ github.run_id }}
          restore-keys: starci-cache-cargo-target-
      - name: "release build"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            cargo build --release --locked
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/cargo-registry:/usr/local/cargo/registry" \
            -v "$RUNNER_TEMP/starci-cache/cargo-target:/workspace/target" \
            rust:1-slim-bookworm sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
