# Generated by `starci compile` from polyglot.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:
#  - The script decides by which files a commit changed. A workflow file
#    cannot, so it does what the script does when nothing is known about the
#    changes, on every run.
#  - 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:
  python:
    name: "python"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-python-9cd9555497a86ebc-${{ hashFiles('**', '!.git/**') }}
      - name: "python"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            pip install -q ruff && ruff check .
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            python:3.13-slim 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"

  go:
    name: "go"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-go-a6ed0c0d4c4c1961-${{ hashFiles('**', '!.git/**') }}
      - name: "go"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            go vet ./... && go test ./...
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            golang:1.26 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"

  typescript:
    name: "typescript"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-typescript-20f160b2667a77d7-${{ hashFiles('**', '!.git/**') }}
      - name: "typescript"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            npm ci && npx tsc --noEmit
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            node:22-bookworm-slim 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"

  shell:
    name: "shell"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-shell-400dcea7cb647b17-${{ hashFiles('**', '!.git/**') }}
      - name: "shell"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            shellcheck $(find . -name '*.sh')
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            koalaman/shellcheck-alpine:stable 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"

  docker:
    name: "docker"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-docker-73caaf3580179f71-${{ hashFiles('**', '!.git/**') }}
      - name: "docker"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            hadolint $(find . -name Dockerfile)
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            hadolint/hadolint:latest-debian 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"
