go¶
The Go toolchain as a tool; builds for several platforms.
A Go module: vet and test once, then build for each platform it ships on. The toolchain is a tool, so the steps need nothing but a base image.
flowchart LR
s0["vet"]
s1["test"]
s2["build linux/amd64"]
s3["build linux/arm64"]
s4["build darwin/arm64"]
s0 --> s2
s1 --> s2
s0 --> s3
s1 --> s3
s0 --> s4
s1 --> s4
The steps this script plans for a push about which nothing is known. An arrow is a needs.
# A Go module: vet and test once, then build for each platform it ships on.
# The toolchain is a tool, so the steps need nothing but a base image.
golang = tool(
"go",
url = "https://go.dev/dl/go1.26.5.linux-{arch}.tar.gz",
sha256 = {
"amd64": "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053",
"arm64": "fe4789e92b1f33358680864bbe8704289e7bb5fc207d80623c308935bd696d49",
},
bin = ["go/bin"],
)
SOURCES = ["**/*.go", "go.mod", "go.sum"]
PLATFORMS = [("linux", "amd64"), ("linux", "arm64"), ("darwin", "arm64")]
def go(name, command, env = {}, needs = []):
return step(
name,
image = "debian:12-slim",
tools = [golang],
packages = ["ca-certificates"],
run = command,
env = dict(env, CGO_ENABLED = "0"),
inputs = SOURCES,
needs = needs,
# Go keeps its own record of which packages' tests are still valid.
# Keeping its caches between runs lets it skip those inside a step
# that does have to run.
caches = {"go-mod": "/root/go/pkg/mod", "go-build": "/root/.cache/go-build"},
)
def ci(ctx):
vet = go("vet", "go vet ./...")
test = go("test", "go test ./...")
builds = [
go(
"build {}/{}".format(goos, goarch),
"go build -o /dev/null ./...",
env = {"GOOS": goos, "GOARCH": goarch},
needs = [vet, test],
)
for goos, goarch in PLATFORMS
]
return [vet, test] + builds
# Generated by `starci compile` 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 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:
vet:
name: "vet"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/**/*.go
/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-vet-9996d1ce7b10c758-${{ hashFiles('**/*.go', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
- name: "Tool: go"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/go"
curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o "$RUNNER_TEMP/go.download"
echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053 $RUNNER_TEMP/go.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/go.download" -C "$RUNNER_TEMP/starci-tools/go"
- name: Image with ca-certificates
if: steps.passed.outputs.cache-hit != 'true'
run: |
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
- 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: go-mod"
if: steps.passed.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-cache/go-mod
key: starci-cache-go-mod-${{ github.run_id }}
restore-keys: starci-cache-go-mod-
- name: "vet"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go vet ./...
run: |
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 "$RUNNER_TEMP/starci-tools/go:/opt/starci/tools/go:ro" \
-v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
-v "$RUNNER_TEMP/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"
- 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: |
/**/*.go
/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-test-004be1ade613f38d-${{ hashFiles('**/*.go', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
- name: "Tool: go"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/go"
curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o "$RUNNER_TEMP/go.download"
echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053 $RUNNER_TEMP/go.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/go.download" -C "$RUNNER_TEMP/starci-tools/go"
- name: Image with ca-certificates
if: steps.passed.outputs.cache-hit != 'true'
run: |
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
- 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: go-mod"
if: steps.passed.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-cache/go-mod
key: starci-cache-go-mod-${{ github.run_id }}
restore-keys: starci-cache-go-mod-
- name: "test"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go test ./...
run: |
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 "$RUNNER_TEMP/starci-tools/go:/opt/starci/tools/go:ro" \
-v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
-v "$RUNNER_TEMP/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"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
build-linux-amd64:
name: "build linux/amd64"
runs-on: ubuntu-latest
needs: [vet, test]
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/**/*.go
/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-build-linux-amd64-a55131b9cd384415-${{ hashFiles('**/*.go', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
- name: "Tool: go"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/go"
curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o "$RUNNER_TEMP/go.download"
echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053 $RUNNER_TEMP/go.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/go.download" -C "$RUNNER_TEMP/starci-tools/go"
- name: Image with ca-certificates
if: steps.passed.outputs.cache-hit != 'true'
run: |
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
- 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: go-mod"
if: steps.passed.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-cache/go-mod
key: starci-cache-go-mod-${{ github.run_id }}
restore-keys: starci-cache-go-mod-
- name: "build linux/amd64"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go build -o /dev/null ./...
run: |
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 "$RUNNER_TEMP/starci-tools/go:/opt/starci/tools/go:ro" \
-v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
-v "$RUNNER_TEMP/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"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
build-linux-arm64:
name: "build linux/arm64"
runs-on: ubuntu-latest
needs: [vet, test]
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/**/*.go
/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-build-linux-arm64-44c855f8b8f1e01e-${{ hashFiles('**/*.go', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
- name: "Tool: go"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/go"
curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o "$RUNNER_TEMP/go.download"
echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053 $RUNNER_TEMP/go.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/go.download" -C "$RUNNER_TEMP/starci-tools/go"
- name: Image with ca-certificates
if: steps.passed.outputs.cache-hit != 'true'
run: |
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
- 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: go-mod"
if: steps.passed.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-cache/go-mod
key: starci-cache-go-mod-${{ github.run_id }}
restore-keys: starci-cache-go-mod-
- name: "build linux/arm64"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go build -o /dev/null ./...
run: |
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 "$RUNNER_TEMP/starci-tools/go:/opt/starci/tools/go:ro" \
-v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
-v "$RUNNER_TEMP/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"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
build-darwin-arm64:
name: "build darwin/arm64"
runs-on: ubuntu-latest
needs: [vet, test]
steps:
- uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
/**/*.go
/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-build-darwin-arm64-a8bd365e9e73d5b8-${{ hashFiles('**/*.go', 'go.mod', 'go.mod/**', 'go.sum', 'go.sum/**') }}
- name: "Tool: go"
if: steps.passed.outputs.cache-hit != 'true'
run: |
mkdir -p "$RUNNER_TEMP/starci-tools/go"
curl -fsSL 'https://go.dev/dl/go1.26.5.linux-amd64.tar.gz' -o "$RUNNER_TEMP/go.download"
echo "5c2c3b16caefa1d968a94c1daca04a7ca301a496d9b086e17ad77bb81393f053 $RUNNER_TEMP/go.download" | sha256sum -c -
tar -xf "$RUNNER_TEMP/go.download" -C "$RUNNER_TEMP/starci-tools/go"
- name: Image with ca-certificates
if: steps.passed.outputs.cache-hit != 'true'
run: |
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
- 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: go-mod"
if: steps.passed.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-cache/go-mod
key: starci-cache-go-mod-${{ github.run_id }}
restore-keys: starci-cache-go-mod-
- name: "build darwin/arm64"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go build -o /dev/null ./...
run: |
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 "$RUNNER_TEMP/starci-tools/go:/opt/starci/tools/go:ro" \
-v "$RUNNER_TEMP/starci-cache/go-build:/root/.cache/go-build" \
-v "$RUNNER_TEMP/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"
- name: Remember this pass
if: steps.passed.outputs.cache-hit != 'true'
run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
# 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]
Download: go.ci.star, GitHub Actions, CircleCI