# Generated by `starci compile` from wrapping-lint-actions.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:
  golangci-lint:
    name: "golangci-lint"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /**/*.go
            /.golangci.y*ml
            /go.mod
            /go.sum
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-golangci-lint-e0cd4dcdf1513864-${{ hashFiles('**/*.go', '.golangci.y*ml', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
      - name: "Cache: go-build"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/go-build
          key: starci-cache-go-build-${{ github.run_id }}
          restore-keys: starci-cache-go-build-
      - name: "Cache: golangci-lint"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/golangci-lint
          key: starci-cache-golangci-lint-${{ github.run_id }}
          restore-keys: starci-cache-golangci-lint-
      - name: "golangci-lint"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            cd . && golangci-lint run --timeout 5m
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
            -v "$RUNNER_TEMP/starci-cache/golangci-lint:/root/.cache/golangci-lint" \
            golangci/golangci-lint:v2.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"

  ruff:
    name: "ruff"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /**/*.py
            /pyproject.toml
            /ruff.toml
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-ruff-8d0fef5441d3e890-${{ hashFiles('**/*.py', 'pyproject.toml', 'pyproject.toml/**', 'ruff.toml', 'ruff.toml/**') }}
      - name: "ruff"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            ruff check .
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            ghcr.io/astral-sh/ruff:latest 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"

  shellcheck:
    name: "shellcheck"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /**/*.sh
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-shellcheck-c2c1f7958bbf3a1a-${{ hashFiles('**/*.sh') }}
      - name: "shellcheck"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            find . -name '*.sh' -not -path './vendor/*' -exec shellcheck --severity=warning {} +
        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"

  actionlint:
    name: "actionlint"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /.github/workflows
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-actionlint-fd7c0e54f7782df5-${{ hashFiles('.github/workflows', '.github/workflows/**') }}
      - name: "actionlint"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            actionlint
        run: |
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            rhysd/actionlint:latest 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"
