# Generated by `starci compile --target circleci` 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 reads ctx.changed_files, so its plan depends on the commit.
#    This file is the plan for a commit about which nothing is known, and is
#    the same for every push: steps the script would add or drop for a
#    particular branch or set of changed files are not represented.
#  - Passes are remembered in this project's CircleCI cache, which expires.
#    starci's own store does not.

version: 2.1

jobs:
  golangci-lint:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/**/*.go' '/.golangci.y*ml' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,glob).golangci.y*ml' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-golangci-lint-e0cd4dcdf1513864-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: golangci-lint"
          keys:
            - starci-cache-golangci-lint-
      - run:
          name: "golangci-lint"
          environment:
            STARCI_RUN: |-
              cd . && golangci-lint run --timeout 5m
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/golangci-lint:/root/.cache/golangci-lint" \
              golangci/golangci-lint:v2.1 sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: go-build"
          key: starci-cache-go-build-{{ .Revision }}
          paths:
            - ~/starci-cache/go-build
      - save_cache:
          name: "Save cache: golangci-lint"
          key: starci-cache-golangci-lint-{{ .Revision }}
          paths:
            - ~/starci-cache/golangci-lint
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-golangci-lint-e0cd4dcdf1513864-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  ruff:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/**/*.py' '/pyproject.toml' '/ruff.toml'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.py' ':(top,literal)pyproject.toml' ':(top,literal)ruff.toml' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-ruff-8d0fef5441d3e890-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "ruff"
          environment:
            STARCI_RUN: |-
              ruff check .
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              ghcr.io/astral-sh/ruff:latest sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-ruff-8d0fef5441d3e890-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  shellcheck:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/**/*.sh'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.sh' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-shellcheck-c2c1f7958bbf3a1a-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "shellcheck"
          environment:
            STARCI_RUN: |-
              find . -name '*.sh' -not -path './vendor/*' -exec shellcheck --severity=warning {} +
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              koalaman/shellcheck-alpine:stable sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-shellcheck-c2c1f7958bbf3a1a-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  actionlint:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/.github/workflows'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal).github/workflows' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-actionlint-fd7c0e54f7782df5-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "actionlint"
          environment:
            STARCI_RUN: |-
              actionlint
          command: |
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              rhysd/actionlint:latest sh -c "$STARCI_RUN"
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-actionlint-fd7c0e54f7782df5-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - golangci-lint
      - ruff
      - shellcheck
      - actionlint
