-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (105 loc) · 5.02 KB
/
Makefile
File metadata and controls
134 lines (105 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This works because `go list ./...` excludes vendor directories by default in modern versions of Go (1.11+).
# No need for grep or additional filtering.
TEST ?= $$(go list ./...)
TESTARGS ?=
SHELL := /bin/bash
#GOOS=darwin
#GOOS=linux
#GOARCH=amd64
VERSION=test
export CGO_ENABLED=0
# Detect git worktree and set GOFLAGS accordingly.
# In worktrees, buildvcs fails because .git is in a different location.
IS_WORKTREE := $(shell [ "$$(git rev-parse --git-dir 2>/dev/null)" != "$$(git rev-parse --git-common-dir 2>/dev/null)" ] && echo true)
ifdef IS_WORKTREE
export GOFLAGS := -buildvcs=false
endif
readme: build
./build/atmos docs generate readme
build: build-default
version: version-default
# The following will lint only files in git. `golangci-lint run --new-from-rev=HEAD` should do it,
# but it's still including files not in git.
lint: deps lintroller gomodcheck custom-gcl
./custom-gcl run --new-from-rev=origin/main
# Build custom golangci-lint binary with lintroller plugin.
# Uses a temporary directory to prevent git corruption during pre-commit hooks
custom-gcl: tools/lintroller/.lintroller .custom-gcl.yml
@echo "Building custom golangci-lint binary with lintroller plugin..."
@GOFLAGS="-buildvcs=false" GOTOOLCHAIN=go$(shell go env GOVERSION | sed 's/^go//') golangci-lint custom
@echo "Custom golangci-lint binary built successfully: ./custom-gcl"
# Custom linter for Atmos-specific rules (t.Setenv misuse, os.Setenv in tests, os.MkdirTemp in tests).
.PHONY: lintroller
lintroller: tools/lintroller/.lintroller
@echo "Running lintroller (Atmos custom rules)..."
@test -x tools/lintroller/.lintroller || (echo "Error: lintroller binary not executable" && exit 1)
@tools/lintroller/.lintroller $(shell go list ./... | grep -v '/testdata')
tools/lintroller/.lintroller: tools/lintroller/*.go tools/lintroller/cmd/lintroller/*.go
@echo "Building lintroller..."
@cd tools/lintroller && go build -o .lintroller ./cmd/lintroller
@chmod +x tools/lintroller/.lintroller
@test -x tools/lintroller/.lintroller || (echo "Error: Failed to make lintroller executable" && exit 1)
# Check go.mod for replace/exclude directives that break go install.
.PHONY: gomodcheck
gomodcheck: tools/gomodcheck/.gomodcheck
@tools/gomodcheck/.gomodcheck go.mod
tools/gomodcheck/.gomodcheck: tools/gomodcheck/*.go
@echo "Building gomodcheck..."
@cd tools/gomodcheck && go build -o .gomodcheck .
@chmod +x tools/gomodcheck/.gomodcheck
@test -x tools/gomodcheck/.gomodcheck || (echo "Error: Failed to make gomodcheck executable" && exit 1)
build-linux: GOOS=linux
build-linux: build-default
build-default: deps
@echo "Building atmos $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH))"
env $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH)) go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/pkg/version.Version=$(VERSION)'"
build-windows: GOOS=windows
build-windows: deps
@echo "Building atmos for $(GOOS) ($(GOARCH))"
go build -o build/atmos.exe -v -ldflags "-X github.com/cloudposse/atmos/pkg/version.Version=$(VERSION)"
build-macos: GOOS=darwin
build-macos: build-default
version-linux: version-default
version-macos: version-default
version-default:
chmod +x ./build/atmos
./build/atmos version
version-windows: build-windows
./build/atmos.exe version
deps:
go mod download
testacc: deps
@echo "Running acceptance tests"
go test $(TEST) $(TESTARGS) -timeout 40m
# Run tests with subprocess coverage collection (Go 1.20+)
testacc-cover: deps
@scripts/collect-coverage.sh "$(TEST)" "$(TESTARGS)"
# Run acceptance tests with coverage report
testacc-coverage: testacc-cover
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run quick tests only (skip long-running tests >2 seconds)
test-short: deps
@echo "Running quick tests (skipping long-running tests)"
go test -short $(TEST) $(TESTARGS) -timeout 5m
# Run quick tests with coverage
test-short-cover: deps
@echo "Running quick tests with coverage (skipping long-running tests)"
@GOCOVERDIR=coverage go test -short -cover $(TEST) $(TESTARGS) -timeout 5m
# Regenerate all mocks using go:generate directives
generate-mocks:
@echo "Regenerating mocks using go:generate directives..."
@go generate ./pkg/auth/types/...
@go generate ./pkg/http/...
@echo "Mocks regenerated successfully"
# Check markdown links (requires lychee: brew install lychee)
link-check:
@command -v lychee >/dev/null 2>&1 || { echo "Install lychee: brew install lychee"; exit 1; }
lychee --config lychee.toml --root-dir "$(CURDIR)" '**/*.md'
# Run quick tests with race detector and shuffled order.
# This target is recommended for CI to catch data races and order-dependent failures.
# Usage: make test-race
test-race: deps
@echo "Running tests with -race -shuffle=on"
go test -race -shuffle=on $(TEST) $(TESTARGS) -timeout 10m
.PHONY: readme lint lintroller gomodcheck build version build-linux build-windows build-macos deps version-linux version-windows version-macos testacc testacc-cover testacc-coverage test-short test-short-cover test-race generate-mocks link-check