# Generated by `starci compile --target circleci` from go.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 project's CircleCI cache, which expires.
#    starci's own store does not.

version: 2.1

jobs:
  vet:
    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' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-vet-9996d1ce7b10c758-{{ 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: "Tool: go"
          command: |
            mkdir -p "$HOME/starci-tools/go"
            curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o /tmp/go.download
            echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053  /tmp/go.download" | sha256sum -c -
            tar -xf "/tmp/go.download" -C "$HOME/starci-tools/go"
      - run:
          name: "Image with ca-certificates"
          command: |
            docker build -q -t starci-env-vet - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: go-mod"
          keys:
            - starci-cache-go-mod-
      - run:
          name: "vet"
          environment:
            STARCI_RUN: |-
              go vet ./...
          command: |
            image_path=$(docker image inspect starci-env-vet --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/go:/opt/starci/tools/go:ro" \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/go-mod:/root/go/pkg/mod" \
              -e "PATH=/opt/starci/tools/go/go/bin:$image_path" \
              -e 'CGO_ENABLED=0' \
              starci-env-vet 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: go-mod"
          key: starci-cache-go-mod-{{ .Revision }}
          paths:
            - ~/starci-cache/go-mod
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-vet-9996d1ce7b10c758-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  test:
    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' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-test-004be1ade613f38d-{{ 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: "Tool: go"
          command: |
            mkdir -p "$HOME/starci-tools/go"
            curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o /tmp/go.download
            echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053  /tmp/go.download" | sha256sum -c -
            tar -xf "/tmp/go.download" -C "$HOME/starci-tools/go"
      - run:
          name: "Image with ca-certificates"
          command: |
            docker build -q -t starci-env-test - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: go-mod"
          keys:
            - starci-cache-go-mod-
      - run:
          name: "test"
          environment:
            STARCI_RUN: |-
              go test ./...
          command: |
            image_path=$(docker image inspect starci-env-test --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/go:/opt/starci/tools/go:ro" \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/go-mod:/root/go/pkg/mod" \
              -e "PATH=/opt/starci/tools/go/go/bin:$image_path" \
              -e 'CGO_ENABLED=0' \
              starci-env-test 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: go-mod"
          key: starci-cache-go-mod-{{ .Revision }}
          paths:
            - ~/starci-cache/go-mod
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-test-004be1ade613f38d-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  build-linux-amd64:
    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' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-build-linux-amd64-a55131b9cd384415-{{ 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: "Tool: go"
          command: |
            mkdir -p "$HOME/starci-tools/go"
            curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o /tmp/go.download
            echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053  /tmp/go.download" | sha256sum -c -
            tar -xf "/tmp/go.download" -C "$HOME/starci-tools/go"
      - run:
          name: "Image with ca-certificates"
          command: |
            docker build -q -t starci-env-build-linux-amd64 - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: go-mod"
          keys:
            - starci-cache-go-mod-
      - run:
          name: "build linux/amd64"
          environment:
            STARCI_RUN: |-
              go build -o /dev/null ./...
          command: |
            image_path=$(docker image inspect starci-env-build-linux-amd64 --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/go:/opt/starci/tools/go:ro" \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/go-mod:/root/go/pkg/mod" \
              -e "PATH=/opt/starci/tools/go/go/bin:$image_path" \
              -e 'CGO_ENABLED=0' \
              -e 'GOARCH=amd64' \
              -e 'GOOS=linux' \
              starci-env-build-linux-amd64 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: go-mod"
          key: starci-cache-go-mod-{{ .Revision }}
          paths:
            - ~/starci-cache/go-mod
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-build-linux-amd64-a55131b9cd384415-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  build-linux-arm64:
    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' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-build-linux-arm64-44c855f8b8f1e01e-{{ 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: "Tool: go"
          command: |
            mkdir -p "$HOME/starci-tools/go"
            curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o /tmp/go.download
            echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053  /tmp/go.download" | sha256sum -c -
            tar -xf "/tmp/go.download" -C "$HOME/starci-tools/go"
      - run:
          name: "Image with ca-certificates"
          command: |
            docker build -q -t starci-env-build-linux-arm64 - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: go-mod"
          keys:
            - starci-cache-go-mod-
      - run:
          name: "build linux/arm64"
          environment:
            STARCI_RUN: |-
              go build -o /dev/null ./...
          command: |
            image_path=$(docker image inspect starci-env-build-linux-arm64 --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/go:/opt/starci/tools/go:ro" \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/go-mod:/root/go/pkg/mod" \
              -e "PATH=/opt/starci/tools/go/go/bin:$image_path" \
              -e 'CGO_ENABLED=0' \
              -e 'GOARCH=arm64' \
              -e 'GOOS=linux' \
              starci-env-build-linux-arm64 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: go-mod"
          key: starci-cache-go-mod-{{ .Revision }}
          paths:
            - ~/starci-cache/go-mod
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-build-linux-arm64-44c855f8b8f1e01e-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  build-darwin-arm64:
    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' '/go.mod' '/go.sum'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,glob)**/*.go' ':(top,literal)go.mod' ':(top,literal)go.sum' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-build-darwin-arm64-a8bd365e9e73d5b8-{{ 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: "Tool: go"
          command: |
            mkdir -p "$HOME/starci-tools/go"
            curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o /tmp/go.download
            echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053  /tmp/go.download" | sha256sum -c -
            tar -xf "/tmp/go.download" -C "$HOME/starci-tools/go"
      - run:
          name: "Image with ca-certificates"
          command: |
            docker build -q -t starci-env-build-darwin-arm64 - \<<'DOCKERFILE'
            FROM debian:12-slim
            RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
            DOCKERFILE
      - restore_cache:
          name: "Cache: go-build"
          keys:
            - starci-cache-go-build-
      - restore_cache:
          name: "Cache: go-mod"
          keys:
            - starci-cache-go-mod-
      - run:
          name: "build darwin/arm64"
          environment:
            STARCI_RUN: |-
              go build -o /dev/null ./...
          command: |
            image_path=$(docker image inspect starci-env-build-darwin-arm64 --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/go:/opt/starci/tools/go:ro" \
              -v "$HOME/starci-cache/go-build:/root/.cache/go-build" \
              -v "$HOME/starci-cache/go-mod:/root/go/pkg/mod" \
              -e "PATH=/opt/starci/tools/go/go/bin:$image_path" \
              -e 'CGO_ENABLED=0' \
              -e 'GOARCH=arm64' \
              -e 'GOOS=darwin' \
              starci-env-build-darwin-arm64 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: go-mod"
          key: starci-cache-go-mod-{{ .Revision }}
          paths:
            - ~/starci-cache/go-mod
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-build-darwin-arm64-a8bd365e9e73d5b8-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - vet
      - test
      - build-linux-amd64:
          requires: [vet, test]
      - build-linux-arm64:
          requires: [vet, test]
      - build-darwin-arm64:
          requires: [vet, test]
