Add scripts-to-rule-them-all scaffold (refs #1)
All checks were successful
check / check (push) Successful in 6s
All checks were successful
check / check (push) Successful in 6s
Bring the repo into conformance with the scripts-to-rule-them-all (STRTA) scaffold. The real logic that lived inline in the Makefile now lives in POSIX-sh entrypoints under script/, and the Makefile's standard targets are thin @script/NAME shims. - script/: bootstrap, setup, projectname, test, lint, fmt, fmt-check, check, docker, precommit, install-precommit, cibuild. All are executable #!/bin/sh entrypoints; the go mod tidy guard from the old inline hooks recipe moved into script/precommit. - Makefile: the nine standard targets (bootstrap, setup, test, lint, fmt, fmt-check, check, docker, hooks) are now thin shims; the repo-specific sfdupes/build/clean targets and the CGO_ENABLED export are preserved. - .gitea/workflows/check.yml: run script/cibuild instead of a bare docker build. - Dockerfile: run make check (and the build) as an unprivileged builder user rather than root. We should never build or run as root, and doing so also lets the permission-denied tests run legitimately: root bypasses the chmod(0) that TestScanHardlinkRunFailsTogether relies on, which made the in-image make check fail. HOME and the Go caches point at the user's home so go build/test and golangci-lint can write. make check passes locally and docker build . is green (the in-image non-root make check passes, including the hardlink permission test).
This commit is contained in:
37
Makefile
37
Makefile
@@ -6,7 +6,10 @@ BINARY := sfdupes
|
||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
||||
LDFLAGS := -X main.Version=$(VERSION)
|
||||
|
||||
.PHONY: sfdupes build test lint fmt fmt-check check docker hooks clean
|
||||
.PHONY: sfdupes build bootstrap setup test lint fmt fmt-check check docker hooks clean
|
||||
|
||||
# Standard targets are thin shims; the implementations live in script/
|
||||
# per the scripts-to-rule-them-all pattern.
|
||||
|
||||
# Default target: build the binary. Phony so go build (which has its
|
||||
# own build cache) always decides what to recompile.
|
||||
@@ -15,36 +18,32 @@ sfdupes:
|
||||
|
||||
build: sfdupes
|
||||
|
||||
bootstrap:
|
||||
@script/bootstrap
|
||||
|
||||
setup:
|
||||
@script/setup
|
||||
|
||||
test:
|
||||
@go test -timeout 30s -cover ./... || \
|
||||
{ echo "--- Rerunning with -v for details ---"; \
|
||||
go test -timeout 30s -v ./...; exit 1; }
|
||||
@script/test
|
||||
|
||||
lint:
|
||||
golangci-lint run --config .golangci.yml ./...
|
||||
@script/lint
|
||||
|
||||
fmt:
|
||||
gofmt -s -w .
|
||||
@script/fmt
|
||||
|
||||
fmt-check:
|
||||
@files="$$(gofmt -l -s .)"; if [ -n "$$files" ]; then \
|
||||
echo "gofmt: files not formatted:"; echo "$$files"; exit 1; fi
|
||||
@script/fmt-check
|
||||
|
||||
check: test lint fmt-check
|
||||
check:
|
||||
@script/check
|
||||
|
||||
docker:
|
||||
docker build -t $(BINARY) .
|
||||
|
||||
# Hooks are shared between the main checkout and all worktrees, so
|
||||
# resolve the common git dir instead of assuming .git is a directory.
|
||||
HOOKS_DIR := $(shell git rev-parse --git-common-dir)/hooks
|
||||
@script/docker
|
||||
|
||||
hooks:
|
||||
@printf '#!/bin/sh\nset -e\n' > $(HOOKS_DIR)/pre-commit
|
||||
@printf 'go mod tidy\ngo fmt ./...\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@printf 'git diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@printf 'make check\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@chmod +x $(HOOKS_DIR)/pre-commit
|
||||
@script/install-precommit
|
||||
|
||||
clean:
|
||||
rm -f $(BINARY) files.dat
|
||||
|
||||
Reference in New Issue
Block a user