Run all linting in Docker via Dockerfile.lint (closes #90)
check / check (push) Successful in 1m47s

script/lint now only builds the new Dockerfile.lint, which copies the
repo into the pinned golangci-lint image and runs the linter as a build
step, so a successful build is a clean lint. It builds with --no-cache,
because a cached build runs no linter, and removes the image it tagged
when it exits. The main Dockerfile lint stage calls golangci-lint
directly, since make lint now needs Docker. Nothing installs or runs
golangci-lint on the host any more: bootstrap and the Makefile drop the
install, and script/fmt drops golangci-lint run --fix. The gofmt check
script/lint repeated stays in script/fmt-check.

Model: opus-5-5
This commit is contained in:
2026-10-04 03:35:28 +00:00
parent d00982b329
commit 7dcae7b471
7 changed files with 36 additions and 30 deletions
+11 -8
View File
@@ -1,17 +1,20 @@
#!/bin/sh
# script/lint: run the linter.
# script/lint: run golangci-lint, in Docker only. Builds Dockerfile.lint,
# whose build runs the linter, so a successful build is a clean lint.
# --no-cache because a cached build runs no linter. The image is removed
# afterwards, whatever the outcome.
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
main() {
cd "$ROOT"
golangci-lint run
if [ -n "$(gofmt -l .)" ]; then
echo "gofmt: files need formatting:" >&2
gofmt -l . >&2
exit 1
fi
# Tagged per run, so concurrent runs never remove each other's image.
image="$("$SCRIPT_DIR/projectname")-lint:$$"
# A failed build leaves no image, so there is nothing to remove then.
trap 'docker image rm "$image" >/dev/null 2>&1 || true' EXIT INT TERM
docker build --no-cache -f Dockerfile.lint -t "$image" .
}
main "$@"