Skip to content

Commit 028b77c

Browse files
committed
fix(build): pin betteralign to v0.13.0, restore struct-alignment build
Revert removing betteralign. Instead pin it to v0.13.0. v0.14.0 regressed -fix (GoReleaser v2 migration + "honor -fix in shipped binary") and intermittently corrupts multi-struct files that carry per-field doc comments (duplicated/dropped Scanner fields), which broke the release build. Reproduced at 1/50 on linux/amd64 under GOMAXPROCS=4; v0.13.0 is clean at 0/150 and v0.12.0 at 0/50. prod again runs betteralign -fix on a throwaway copy; setup-prod installs the pinned version; the Dockerfile restores the setup-prod step. Also drop the only-new-issues escape hatch from the lint check so the full golangci-lint ruleset gates every PR.
1 parent 912d9d4 commit 028b77c

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

.github/workflows/lint.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ jobs:
6262
- name: Run golangci-lint (check)
6363
uses: golangci/golangci-lint-action@v9
6464
with:
65-
# only-new-issues gates newly changed code without failing on the ~37 pre-existing
66-
# findings in code that predates linting here. Drop this once the backlog is cleared
67-
# to enforce the full ruleset repo-wide.
6865
args: --timeout=5m
69-
only-new-issues: true
7066
install-mode: goinstall
7167
version: latest

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ RUN apk add git make \
55

66
WORKDIR /src
77

8+
# Install the pinned build tool (betteralign) via the Makefile so its version lives in one
9+
# place. setup-prod skips the lint/format tools `make setup` installs — those run in CI, not
10+
# the image build. Copied alone so this layer caches until the Makefile changes.
11+
COPY Makefile ./
12+
RUN make setup-prod
13+
814
# Cache Go modules separately so this layer is reused until go.mod/go.sum change.
915
COPY go.mod go.sum ./
1016
RUN go mod download

Makefile

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ GOPRIVATE := github.com/globalcyberalliance
77
LDFLAGS := -s -w
88
GOBUILD = GOPRIVATE=$(GOPRIVATE) CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)"
99

10+
# betteralign is PINNED. v0.14.0 regressed -fix (GoReleaser v2 migration + "honor -fix in
11+
# shipped binary") and intermittently corrupts multi-struct files with per-field doc comments,
12+
# which broke the release build. v0.13.0 is the last release carrying all the correctness fixes
13+
# (v0.9.0 multi-struct rewrite loss + data race, v0.12.0 comment-handling hardening) before that
14+
# regression. Do NOT bump to @latest without re-validating against pkg/scanner.
15+
BETTERALIGN_VERSION := v0.13.0
16+
1017
# VERSION is optional. The binary carries a default version baked into the source
1118
# (cmd/dss/main.go). Passing VERSION= (e.g. a release tag from CI) overrides it via
1219
# -ldflags -X. A passed-but-empty VERSION= is stripped and ignored so we never embed
@@ -20,28 +27,28 @@ endif
2027
need = command -v $(1) >/dev/null 2>&1 || { echo "$(1) not found — run 'make setup'"; exit 1; }
2128

2229
.DEFAULT_GOAL := dev
23-
.PHONY: dev prod optimize clean clean-all format lint lint-fix nil test benchmark tidy setup help
30+
.PHONY: dev prod clean clean-all format lint lint-fix nil test benchmark tidy setup-prod setup help
2431

25-
dev: ## Default: fast local build, compiles in-place
32+
dev: ## Default: fast local build, no struct alignment, compiles in-place
2633
@$(call need,$(GO))
2734
@echo "Building $(BIN)..."
2835
@mkdir -p bin
2936
@$(GOBUILD) -o $(BIN) $(CMD)
3037

31-
prod: ## Production release build (stripped, trimmed, reproducible)
38+
prod: ## Production binary: struct-aligned, optimized (working tree untouched)
3239
@$(call need,$(GO))
33-
@echo "Building $(BIN)..."
34-
@mkdir -p bin
35-
@$(GOBUILD) -o $(BIN) $(CMD)
36-
37-
optimize: ## Rewrite structs for optimal field alignment — run manually, review the diff, commit
38-
# Struct alignment is deliberately kept OFF the build path. betteralign -fix mutates source
39-
# and can intermittently corrupt files, so it must never gate a build; run it by hand and let
40-
# `go build`/review catch any bad rewrite. `|| true` because betteralign exits non-zero simply
41-
# when it has findings, even after a successful fix.
4240
@$(call need,betteralign)
41+
@echo "Preparing build directory..."
42+
@rm -rf bin build && mkdir -p bin build
43+
@cp -r cmd go.mod go.sum pkg build/
4344
@echo "Optimizing struct field alignment..."
44-
@betteralign -fix ./... || true
45+
# betteralign exits non-zero whenever it has findings (even after -fix succeeds, and when
46+
# already aligned), so `|| true` is required — alignment is best-effort here, not a gate.
47+
# The version is pinned (see BETTERALIGN_VERSION) because @latest corrupts source.
48+
@cd build && betteralign -fix ./... >/dev/null 2>&1 || true
49+
@echo "Building $(BIN)..."
50+
@cd build && $(GOBUILD) -o ../$(BIN) $(CMD)
51+
@rm -rf build
4552

4653
clean: ## Remove build artifacts
4754
@echo "Cleaning..."
@@ -80,12 +87,15 @@ benchmark: ## Run benchmarks
8087
tidy: ## Tidy go.mod / go.sum
8188
@$(GO) mod tidy
8289

83-
setup: ## Install dev tools (gofumpt, nilaway, golangci-lint, betteralign)
90+
setup-prod: ## Install build-time tools only (pinned betteralign — needed by `make prod`)
91+
@echo "Installing build tools..."
92+
@$(GO) install github.com/dkorunic/betteralign/cmd/betteralign@$(BETTERALIGN_VERSION)
93+
94+
setup: setup-prod ## Install all dev tools (build + gofumpt, nilaway, golangci-lint)
8495
@echo "Installing dev tools..."
8596
@$(GO) install mvdan.cc/gofumpt@latest
8697
@$(GO) install go.uber.org/nilaway/cmd/nilaway@latest
8798
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
88-
@$(GO) install github.com/dkorunic/betteralign/cmd/betteralign@latest
8999

90100
help: ## Show this help
91101
@grep -hE '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'

0 commit comments

Comments
 (0)