# Generated by `starci compile` from pi-gamebook.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:
  check:
    name: "check"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /bun.lock
            /index.ts
            /omp.ts
            /package.json
            /rules
            /src
            /test
            /tsconfig.json
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-check-c6f009914a378669-${{ hashFiles('bun.lock', 'bun.lock/**', 'index.ts', 'index.ts/**', 'omp.ts', 'omp.ts/**', 'package.json', 'package.json/**', 'rules', 'rules/**', 'src', 'src/**', 'test', 'test/**', 'tsconfig.json', 'tsconfig.json/**') }}
      - name: "Cache: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/bun
          key: starci-cache-bun-${{ github.run_id }}
          restore-keys: starci-cache-bun-
      - name: "check"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            bun install --frozen-lockfile && bun run check
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
            oven/bun:1 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: |
            /bun.lock
            /index.ts
            /omp.ts
            /package.json
            /rules
            /src
            /test
            /tsconfig.json
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-test-bbcb3fc8d6ed8a2d-${{ hashFiles('bun.lock', 'bun.lock/**', 'index.ts', 'index.ts/**', 'omp.ts', 'omp.ts/**', 'package.json', 'package.json/**', 'rules', 'rules/**', 'src', 'src/**', 'test', 'test/**', 'tsconfig.json', 'tsconfig.json/**') }}
      - name: "Cache: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/bun
          key: starci-cache-bun-${{ github.run_id }}
          restore-keys: starci-cache-bun-
      - name: "test"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            bun install --frozen-lockfile && bun test
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
            oven/bun:1 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"
