Skip to content

go

The go archetype is for Go CLI applications: dotty, evolve and gh-claude. It formats, lints, tests, builds and releases a single binary. A Go repo with a docs site needs no second archetype: common's docs-build and serve are always there, and ci and pr end with docs-build.

# mise.toml
[tools]
go = "1.27.2"
"go:golang.org/x/vuln/cmd/govulncheck" = "1.8.0"

[vars]
app = "dotty"
app_pkg = "./cmd"

[task_config]
includes = [".mise/common/tasks.toml", ".mise/archetypes/go/tasks.toml"]
# Makefile
include .mise/archetypes/go/include.mk

Required pins

The library pins neither go nor govulncheck, so each repo tracks its own Go at its own cadence:

  • go: the repo's Go toolchain.
  • go:golang.org/x/vuln/cmd/govulncheck: govulncheck publishes no binaries and must be compiled by the same Go the repo builds with, so it rides with the go pin.

golangci-lint, gotestsum, goreleaser and syft come from the shared pins. If the repo's Go outpaces the shared golangci-lint, override "aqua:golangci/golangci-lint" in the root [tools].

Tasks

Task What it does
fmt go fmt ./... and golangci-lint run --fix, then prose format, then license headers.
lint license check, golangci-lint + govulncheck per GOOS, containers, shell, workflows, prose.
test gotestsum with -race -covermode=atomic, writing coverage/coverage.out and coverage/junit.xml.
build CGO_ENABLED=0 go build -trimpath with version metadata stamped in via -ldflags.
ci lint, test, build, docs-build.
pr tidy, fmt, lint, test, build, docs-build, commit.
tidy Delete go.sum, then go mod tidy.
fuzz Fuzz one target (FUZZ, FUZZTIME, FUZZ_PKG).
snapshot goreleaser release --snapshot --clean --skip=sign,notarize.
release goreleaser release --clean. Needs a vX.Y.Z tag and credentials.

Build metadata

build stamps three variables into the binary, at the same import path GoReleaser uses on tagged releases:

-X <version_pkg>.Version=<git describe --tags --always --dirty>
-X <version_pkg>.Commit=<git rev-parse --short HEAD>
-X <version_pkg>.BuildDate=<UTC timestamp>

version_pkg defaults to <module>/internal/version. The output binary is named by app, defaulting to the repository directory's name, and built from app_pkg, defaulting to .. Every value can be overridden per run:

make build VERSION=1.2.3
make build APP=dotty-dev BUILD_TAGS=withui
make build LDFLAGS="-s -w"   # replaces the whole ldflags string

Multi-platform lint and test

Set goos to a space-separated GOOS list for a cross-platform CLI:

[vars]
goos = "linux darwin windows"
  • lint runs golangci-lint and govulncheck once per entry, because both type-check the build for the GOOS they run under. A platform-specific file is only analysed when its platform is in the list. Every platform runs before the task exits, so one gate reports every platform's findings.
  • test runs the full suite on the host's GOOS, plus a compile-only go test -c pass for every other entry, since cross-compiled test binaries can't execute. That still fails on a platform-specific test file that no longer builds.

Empty (the default) means the host's GOOS only. GOOS in the environment overrides the list per run: make test GOOS=windows.

Fuzzing

make fuzz FUZZ=FuzzParse FUZZTIME=1m FUZZ_PKG=./internal/parse

go test -fuzz accepts a single package only, so FUZZ_PKG must name one. With no FUZZ, the pattern matches every fuzz test in the package, which only works when there's exactly one. Most repos redefine fuzz with their own default target (see Extending & overriding).

Releases

snapshot builds a local release (binaries, archives, SBOMs via syft) without publishing anything. It skips two steps that would misfire locally:

  • sign: cosign keyless signing needs the GitHub Actions OIDC token, so it only works in the release workflow.
  • notarize: a repo with a notarize.macos block enables it whenever MACOS_SIGN_P12 is exported, and a developer who has the org's signing material in their shell shouldn't Developer ID-sign and notarize a throwaway snapshot by accident.

Real releases run in CI: the reusable release workflow calls mise run release --draft and publishes the draft once every asset has landed. Override release in the repo to add release steps; they must leave the git tree clean.

Docs

The archetype deliberately leaves docs to the repo, because regenerating a CLI reference is app-specific. A typical repo-local task builds the binary, regenerates the reference, then builds the site with common's docs-build:

[tasks.docs]
description = "regenerate the CLI reference and build the docs site"
dir = "{{cwd}}"
run = [{ task = "build" }, "./dotty docs --out docs/cli --format markdown", { task = "docs-build" }]
pr: docs

There's no e2e task. The reusable CI's e2e job is opt-in, and a repo that opts in defines its own.

Knobs

Knob Default Env override Meaning
app the repo directory's name APP Output binary name.
app_pkg . APP_PKG Main package to build.
build_tags empty BUILD_TAGS Extra build tags (for example withui).
version_pkg <module>/internal/version VERSION_PKG Package declaring Version/Commit/BuildDate.
goos the host's GOOS GOOS GOOS list that lint and test cover.

Per-run only: VERSION, COMMIT, DATE, LDFLAGS, MODULE, FUZZ, FUZZTIME, FUZZ_PKG.

Source

archetypes/go/tasks.toml
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# go — archetype for a Go CLI application (dotty, evolve, gh-claude).
#
# Include AFTER common/tasks.toml in the consumer's root mise.toml:
#   [task_config]
#   includes = [".mise/common/tasks.toml", ".mise/archetypes/go/tasks.toml"]
#
# Required root [tools] pins — the library pins neither, so each repo tracks
# its own Go at its own cadence:
#   go = "1.27.1"
#   "go:golang.org/x/vuln/cmd/govulncheck" = "1.6.0"   # go install'ed by that Go
# govulncheck must be compiled by the same Go the repo builds with, which is
# why it rides with the go pin rather than the shared config. golangci-lint,
# gotestsum, goreleaser and syft come from the shared pins (prebuilt
# binaries); override golangci-lint in root [tools] if the repo's Go outpaces
# it.
#
# Structural knobs come from [vars] in the consumer's root mise.toml (app,
# app_pkg, build_tags, version_pkg, goos); per-invocation values (VERSION,
# COMMIT, DATE, LDFLAGS, MODULE, FUZZ, FUZZTIME, FUZZ_PKG, GOOS) are environment variables
# with defaults computed inside the scripts — `make build VERSION=x` still
# works because make exports command-line variables to recipe subshells, and
# the go knobs also accept env (`make build APP=x`) for muscle-memory parity.
#
# `docs` is intentionally left to the repo — regenerating a CLI reference is
# app-specific (`./<app> docs …`). A repo defines a `docs` task in its root
# mise.toml [tasks] and appends it to the gate (`pr: docs` in its Makefile, or
# a redefined `pr` task); common's `docs-build` and `serve` (zensical via the
# shared uv pin) are there to call. ci and pr end with docs-build, which skips
# without a zensical.toml; build stays the binary alone, since CI runs it as
# its own job and the release workflow builds the site in a job of its own. No `e2e` here: the reusable CI's e2e job is opt-in and no Go
# repo opts in; a repo that does defines its own e2e task.

[tidy]
description = "tidy the go module graph"
dir = "{{cwd}}"
run = ["rm -f go.sum", "go mod tidy"]

# Auto-fix pass wired into the `fmt` rollup.
[go-fmt]
hide = true
dir = "{{cwd}}"
run = ["go fmt ./...", "golangci-lint run --fix"]

# Check-mode pass wired into the `lint` rollup: golangci-lint + govulncheck
# once per GOOS in the goos knob (see scripts/lint.sh). govulncheck stays here
# (not only in CI) so the local lint gate and the CI gate check the same things.
[go-lint]
hide = true
dir = "{{cwd}}"
env = { TOOLCHAIN_GOOS = "{{vars.goos}}" }
run = "{{config_root}}/.mise/archetypes/go/scripts/lint.sh"

# gotestsum + race detector + coverage profile → coverage/ on the host's GOOS,
# plus a compile-only pass per additional GOOS in the goos knob (see
# scripts/test.sh).
[go-test]
hide = true
dir = "{{cwd}}"
env = { TOOLCHAIN_GOOS = "{{vars.goos}}" }
run = "{{config_root}}/.mise/archetypes/go/scripts/test.sh"

# Version metadata stamped into the binary via -ldflags (see scripts/build.sh).
# The knob defaults reach the script as TOOLCHAIN_* so the plain APP/APP_PKG/…
# spellings stay free for per-invocation env overrides.
[go-build]
hide = true
dir = "{{cwd}}"
env = { TOOLCHAIN_APP = "{{vars.app}}", TOOLCHAIN_APP_PKG = "{{vars.app_pkg}}", TOOLCHAIN_BUILD_TAGS = "{{vars.build_tags}}", TOOLCHAIN_VERSION_PKG = "{{vars.version_pkg}}" }
run = "{{config_root}}/.mise/archetypes/go/scripts/build.sh"

# --skip=sign: cosign keyless signing needs the GitHub Actions OIDC token, so it
# only works in the release workflow — locally it would fail or prompt.
# --skip=notarize: a repo with a notarize.macos block enables it whenever
# MACOS_SIGN_P12 is exported, so a developer who has the org's signing material
# in their shell does not Developer ID-sign and notarize a throwaway snapshot by
# accident (run goreleaser by hand for a deliberate end-to-end test).
# GoReleaser shells out to syft for SBOMs; syft is on PATH via the pins.
[snapshot]
description = "build a local release snapshot (binaries + archives, no publish, signing, or notarization)"
dir = "{{cwd}}"
run = "goreleaser release --snapshot --clean --skip=sign,notarize"

# The reusable release workflow runs `mise run release --draft` (the release
# stays a draft until the workflow publishes it, last), with the org's signing
# and notarization material in the environment. A repo that needs extra release
# steps overrides this task; whatever it runs must leave the git tree clean, or
# GoReleaser refuses to release.
[release]
description = "build and publish a release (needs a vX.Y.Z tag + creds)"
dir = "{{cwd}}"
run = "goreleaser release --clean"

# `go test -fuzz` accepts a single package only, so FUZZ_PKG must name one.
[fuzz]
description = "fuzz one target (FUZZ=FuzzName FUZZTIME=20s FUZZ_PKG=./pkg)"
dir = "{{cwd}}"
run = "{{config_root}}/.mise/archetypes/go/scripts/fuzz.sh"

# Canonical contract: sequential composites preserve the old serial-make
# ordering (fmt before lint; mutating passes never race).
[fmt]
description = "format go + prose, inject license headers"
run = [{ task = "go-fmt" }, { task = "fmt-prose" }, { task = "license" }]

[lint]
description = "all check-mode static analysis"
run = [
  { task = "license-check" },
  { task = "go-lint" },
  { task = "lint-containers" },
  { task = "lint-shell" },
  { task = "lint-workflows" },
  { task = "lint-prose" },
]

[build]
description = "build the application binary"
run = [{ task = "go-build" }]

[test]
description = "run the unit tests with coverage"
run = [{ task = "go-test" }]

[ci]
description = "the gates the reusable CI workflow runs"
run = [{ task = "lint" }, { task = "test" }, { task = "build" }, { task = "docs-build" }]

[pr]
description = "full local gate before a pull request"
run = [
  { task = "tidy" },
  { task = "fmt" },
  { task = "lint" },
  { task = "test" },
  { task = "build" },
  { task = "docs-build" },
  { task = "commit" },
]
archetypes/go/scripts/build.sh
#!/bin/sh
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# Build the application binary with version metadata stamped in via -ldflags.
# GoReleaser injects the same vars at the same import path on tagged releases.
#
# Structural defaults arrive as TOOLCHAIN_* (the library's app / app_pkg /
# build_tags / version_pkg vars); the plain spellings (APP, APP_PKG,
# BUILD_TAGS, VERSION_PKG) and the per-invocation VERSION, COMMIT, DATE,
# LDFLAGS, MODULE are environment overrides — `make build VERSION=x` works
# because make exports command-line variables to recipe subshells.
set -eu

app="${APP:-${TOOLCHAIN_APP:-}}"; app="${app:-$(basename "$PWD")}"
app_pkg="${APP_PKG:-${TOOLCHAIN_APP_PKG:-.}}"
module="${MODULE:-$(go list -m 2>/dev/null || true)}"
version="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo dev)}"
commit="${COMMIT:-$(git rev-parse --short HEAD 2>/dev/null || echo none)}"
date="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
version_pkg="${VERSION_PKG:-${TOOLCHAIN_VERSION_PKG:-}}"; version_pkg="${version_pkg:-$module/internal/version}"
build_tags="${BUILD_TAGS:-${TOOLCHAIN_BUILD_TAGS:-}}"
ldflags="${LDFLAGS:--s -w \
  -X $version_pkg.Version=$version \
  -X $version_pkg.Commit=$commit \
  -X $version_pkg.BuildDate=$date}"

if [ -n "$build_tags" ]; then
  CGO_ENABLED=0 go build -trimpath -tags "$build_tags" -ldflags "$ldflags" -o "$app" "$app_pkg"
else
  CGO_ENABLED=0 go build -trimpath -ldflags "$ldflags" -o "$app" "$app_pkg"
fi
archetypes/go/scripts/lint.sh
#!/bin/sh
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# Check-mode static analysis, once per GOOS in the goos knob: golangci-lint
# and govulncheck both type-check the build for the GOOS they run under, so a
# platform-specific file is only analysed when that platform is in the list.
# Every configured platform runs before the script exits, so one gate reports
# every platform's findings; the exit code is the first failure.
#
# The knob arrives as TOOLCHAIN_GOOS (space-separated); GOOS in the environment
# overrides it per invocation (`make lint GOOS=windows`, or a list). Empty =
# the host's GOOS only. GOOS is unset after resolving so a list value never
# reaches a go invocation: each pass sets it explicitly per entry.
set -eu

host_goos="$(GOOS='' go env GOHOSTOS)"
goos_list="${GOOS:-${TOOLCHAIN_GOOS:-}}"; goos_list="${goos_list:-$host_goos}"
unset GOOS

status=0
for os in $goos_list; do
  echo "==> lint (GOOS=$os)"
  GOOS="$os" golangci-lint run || status=$?
  GOOS="$os" govulncheck ./... || status=$?
done
exit "$status"
archetypes/go/scripts/test.sh
#!/bin/sh
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# Unit tests with the race detector and a coverage profile. -covermode=atomic
# is the race-safe counter mode -race requires. gotestsum runs the suite and
# writes a JUnit report in one pass (propagating the exit code a bare
# `go test | …` pipe would swallow). Codecov ingests the native Go profile
# directly; coverage/ is where the reusable CI workflow uploads from.
#
# That full run happens on the host's GOOS only: a cross-compiled test binary
# cannot execute, so every other entry in the goos knob gets a compile-only
# pass — `go test -c` for every package, binaries discarded — which still
# fails on a platform-specific test file that no longer builds.
#
# The knob arrives as TOOLCHAIN_GOOS (space-separated); GOOS in the environment
# overrides it per invocation (`make test GOOS=windows`, or a list). Empty =
# the host's GOOS only. GOOS is unset after resolving so a list value never
# reaches a go invocation: each pass sets it explicitly per entry.
set -eu

host_goos="$(GOOS='' go env GOHOSTOS)"
goos_list="${GOOS:-${TOOLCHAIN_GOOS:-}}"; goos_list="${goos_list:-$host_goos}"
unset GOOS

for os in $goos_list; do
  if [ "$os" = "$host_goos" ]; then
    echo "==> test (GOOS=$os)"
    mkdir -p coverage
    GOOS="$os" gotestsum --junitfile coverage/junit.xml -- \
      -race -covermode=atomic -coverprofile=coverage/coverage.out ./...
  else
    echo "==> test (GOOS=$os, compile only)"
    out="$(mktemp -d "${TMPDIR:-/tmp}/go-test-$os.XXXXXX")"
    GOOS="$os" go test -c -o "$out/" ./... || { rm -rf "$out"; exit 1; }
    rm -rf "$out"
  fi
done