open-code-review/Makefile
Kite fc5dc97841
Some checks are pending
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CI / test (push) Waiting to run
CI / windows (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Pages / build (push) Waiting to run
Deploy Pages / deploy (push) Blocked by required conditions
build: keep node_modules out of the Go package list via a module boundary (#1125)
`go list ./...` walks into pages/node_modules/flatted/golang/pkg/flatted, a
third-party Go package npm installs as a transitive dependency of the docs
site. It is measured like our own code, and its 0% coverage pulls the reported
total down by ~1.4 points, so `make coverage` fails on a clean tree as soon as
the docs dependencies are installed:

    before: total 89.9%  ->  FAIL: Coverage 89.9% is below 90% threshold
    after:  total 91.3%  ->  PASS: Coverage 91.3% meets 90% threshold

Rather than filter the package out per command, this puts pages/ in a module of
its own. `go list ./...` skips any subtree that carries its own go.mod, so every
tool that expands ./... is fixed at once: go test, go vet, go build,
govulncheck, and the coverage gate. A `grep -v /node_modules/` would instead
have to be repeated at each of the seven call sites that expand ./... today --
one in the Makefile, six in ci.yml -- and would silently fail to cover the ones
added later. As a result neither the Makefile's PACKAGES nor ci.yml needs to
change, including the CI coverage step, which calls `go test ./...` directly and
has the identical exposure whenever pages/node_modules is present in the
workspace -- a real possibility on the self-hosted runners, which reuse their
checkout directories.

pages/ holds no Go code of ours, so the boundary costs nothing today. The
Makefile does gain a comment pointing at it: PACKAGES otherwise shows no trace
of the invariant, and deleting pages/go.mod would quietly put the package back
in the list. The same comment records why the /extensions/ filter stays --
extensions/vscode has no Go code of ours either, but its eslint dependency
installs a second copy of flatted's.
2026-09-01 17:53:04 +08:00

121 lines
3.8 KiB
Makefile

.PHONY: build test clean run help fmt vet check coverage \
build-all dist sha256sum version-info \
build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 \
build-windows-amd64 build-windows-arm64 \
license-check license-add english-check
BINARY_NAME := opencodereview
GO := go
DIST_DIR := ./dist
# Version info — use git tag if available, fallback to short commit hash
GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "")
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= $(if $(GIT_TAG),$(GIT_TAG),v0.0.0-$(GIT_COMMIT))
LD_FLAGS := \
-X main.Version=$(VERSION) \
-X main.GitCommit=$(GIT_COMMIT) \
-X main.BuildDate=$(BUILD_DATE)
RELEASE_LD_FLAGS := -s -w $(LD_FLAGS)
define BUILD_PLATFORM
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 $(GO) build -ldflags "$(RELEASE_LD_FLAGS)" \
-o $(DIST_DIR)/$(BINARY_NAME)-$(1)-$(2)$(3) \
./cmd/opencodereview
endef
# ── Development targets ──────────────────────────────────────────────────────
build:
$(GO) build -ldflags "$(LD_FLAGS)" -o $(DIST_DIR)/$(BINARY_NAME) ./cmd/opencodereview
# No node_modules filter is needed for the docs site: pages/go.mod puts it in a
# module of its own, so `go list ./...` skips that subtree entirely -- see that
# file for why a module boundary is used instead of a per-command grep. Deleting
# it brings pages/node_modules/flatted/golang back into this list.
# The /extensions/ filter still earns its keep: extensions/vscode has no Go code
# of ours, but its eslint dependency installs another copy of flatted's.
PACKAGES := $(shell $(GO) list ./... | grep -v /extensions/)
test:
LC_ALL=C $(GO) test -v -race -count=1 $(PACKAGES)
COVERAGE_THRESHOLD := 90
coverage:
LC_ALL=C $(GO) test -count=1 -coverprofile=coverage.out $(PACKAGES)
$(GO) tool cover -func=coverage.out | grep total:
@COVERAGE=$$($(GO) tool cover -func=coverage.out | grep total: | awk '{print $$3}' | sed 's/%//'); \
if awk "BEGIN {exit !($$COVERAGE < $(COVERAGE_THRESHOLD))}"; then \
echo "FAIL: Coverage $${COVERAGE}% is below $(COVERAGE_THRESHOLD)% threshold"; \
exit 1; \
fi; \
echo "PASS: Coverage $${COVERAGE}% meets $(COVERAGE_THRESHOLD)% threshold"
clean:
rm -rf $(DIST_DIR) coverage.out
run: build
$(DIST_DIR)/$(BINARY_NAME) --staged
help: build
$(DIST_DIR)/$(BINARY_NAME) -h
fmt:
gofmt -s -w .
vet:
LC_ALL=C $(GO) vet $(PACKAGES)
check: license-check english-check
$(GO) mod tidy
gofmt -s -w .
LC_ALL=C $(GO) vet $(PACKAGES)
@echo "check passed"
license-check:
@bash scripts/verify-license.sh
english-check:
@$(GO) run scripts/verify-english-only.go
license-add:
@bash scripts/add-license.sh
# ── Cross-platform targets ───────────────────────────────────────────────────
build-linux-amd64:
$(call BUILD_PLATFORM,linux,amd64)
build-linux-arm64:
$(call BUILD_PLATFORM,linux,arm64)
build-darwin-amd64:
$(call BUILD_PLATFORM,darwin,amd64)
build-darwin-arm64:
$(call BUILD_PLATFORM,darwin,arm64)
build-windows-amd64:
$(call BUILD_PLATFORM,windows,amd64,.exe)
build-windows-arm64:
$(call BUILD_PLATFORM,windows,arm64,.exe)
build-all: build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 build-windows-amd64 build-windows-arm64
# Generate SHA256 checksums for all release binaries
sha256sum: build-all
cd $(DIST_DIR) && shasum -a 256 $(BINARY_NAME)-* | sort > sha256sum.txt
# Full release: clean → build all platforms → checksums
dist: clean build-all sha256sum
@echo $(VERSION) > $(DIST_DIR)/VERSION
version-info:
@echo "Version: $(VERSION)"
@echo "GitCommit: $(GIT_COMMIT)"
@echo "BuildDate: $(BUILD_DATE)"
@echo "LD_FLAGS: $(LD_FLAGS)"