-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (120 loc) · 4.25 KB
/
Makefile
File metadata and controls
136 lines (120 loc) · 4.25 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
135
136
.PHONY: test-all
test-all: lint test test-integration
VERSION ?= $(shell (git describe --tags --exact-match 2>/dev/null || echo dev) | sed 's/^v//')
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT) -X main.date=$(BUILD_DATE)
LATEST_E2E_LINK ?= .latest-e2e
.PHONY: lint
lint:
golangci-lint run -v
.PHONY: format fmt
format:
gofumpt -l -w .
golines -m 120 -w --base-formatter=gofumpt .
fmt: format
.PHONY: mod
mod:
go mod tidy
go mod vendor
.PHONY: build
build: mod
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o kongctl
.PHONY: build-ci
build-ci:
CGO_ENABLED=0 go build -mod=readonly -ldflags "$(LDFLAGS)" -o kongctl
# Kept typing this wrong
buld: build
.PHONY: build-docker
build-docker:
@set -eu; \
mkdir -p linux/amd64; \
rm -rf linux/amd64/kongctl; \
trap 'rm -rf linux/amd64/kongctl' 0; \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o linux/amd64/kongctl .; \
docker buildx build --platform linux/amd64 --load -t kongctl:$(VERSION) .
.PHONY: coverage
coverage:
go test -race -v -count=1 -coverprofile=coverage.out.tmp ./...
# ignoring generated code for coverage
grep -E -v 'generated.deepcopy.go' coverage.out.tmp > coverage.out
rm -f coverage.out.tmp
.PHONY: test
test:
go test -race -count=1 ./...
.PHONY: test-integration
test-integration:
go test -v -count=1 -tags=integration \
-race \
${GOTESTFLAGS} \
./test/integration/...
.PHONY: test-e2e
test-e2e:
@ART_DIR="$$KONGCTL_E2E_ARTIFACTS_DIR"; \
if [ -z "$$ART_DIR" ]; then \
ART_DIR=$$(mktemp -d 2>/dev/null || mktemp -d -t kongctl-e2e || echo .e2e_artifacts); \
else \
mkdir -p "$$ART_DIR"; \
run_id=$$(date +%Y%m%d-%H%M%S); \
ART_DIR="$$ART_DIR/$$run_id"; \
fi; \
mkdir -p "$$ART_DIR"; \
ART_DIR=$$(cd "$$ART_DIR" && pwd); \
( KONGCTL_E2E_ARTIFACTS_DIR="$$ART_DIR" go test -v -count=1 -tags=e2e $${GOTESTFLAGS} ./test/e2e/... ; echo $$? > "$$ART_DIR/.exit_code" ) | tee "$$ART_DIR/run.log"; \
code=$$(cat "$$ART_DIR/.exit_code"); rm -f "$$ART_DIR/.exit_code"; \
echo "E2E artifacts: $$ART_DIR"; \
ln -sfn "$$ART_DIR" "$(LATEST_E2E_LINK)" || true; \
exit $$code
.PHONY: test-e2e-scenarios
test-e2e-scenarios:
@ART_DIR="$$KONGCTL_E2E_ARTIFACTS_DIR"; \
if [ -z "$$ART_DIR" ]; then \
ART_DIR=$$(mktemp -d 2>/dev/null || mktemp -d -t kongctl-e2e || echo .e2e_artifacts); \
else \
mkdir -p "$$ART_DIR"; \
run_id=$$(date +%Y%m%d-%H%M%S); \
ART_DIR="$$ART_DIR/$$run_id"; \
fi; \
mkdir -p "$$ART_DIR"; \
ART_DIR=$$(cd "$$ART_DIR" && pwd); \
( KONGCTL_E2E_ARTIFACTS_DIR="$$ART_DIR" \
KONGCTL_E2E_SCENARIO="${SCENARIO}" \
KONGCTL_E2E_STOP_AFTER="${STOP_AFTER}" \
go test -v -count=1 -tags=e2e -run '^Test_Scenarios$$' $${GOTESTFLAGS} ./test/e2e ; \
echo $$? > "$$ART_DIR/.exit_code" ) | tee "$$ART_DIR/run.log"; \
code=$$(cat "$$ART_DIR/.exit_code"); rm -f "$$ART_DIR/.exit_code"; \
echo "E2E artifacts: $$ART_DIR"; \
ln -sfn "$$ART_DIR" "$(LATEST_E2E_LINK)" || true; \
exit $$code
.PHONY: scenario
scenario: test-e2e-scenarios
.PHONY: open-latest-e2e
open-latest-e2e:
@set -euo pipefail; \
if [ -L "$(LATEST_E2E_LINK)" ]; then \
readlink -f "$(LATEST_E2E_LINK)"; \
exit 0; \
fi; \
if [ -f .e2e_artifacts_dir ]; then \
awk 'NR==1 {print $$0}' .e2e_artifacts_dir; \
exit 0; \
fi; \
echo "no latest e2e artifacts found" >&2; \
exit 1
.PHONY: analyze-latest-e2e
analyze-latest-e2e:
@set -euo pipefail; \
ART_DIR=$$($(MAKE) -s open-latest-e2e 2>/dev/null) || { echo "latest e2e artifacts not found; run tests first" >&2; exit 1; }; \
if [ ! -d "$$ART_DIR" ]; then \
echo "artifacts dir $$ART_DIR not found" >&2; exit 1; \
fi; \
PROMPT_FILE="test/e2e/e2e_analysis_prompt.txt"; \
if [ ! -f "$$PROMPT_FILE" ]; then \
echo "prompt file $$PROMPT_FILE missing" >&2; exit 1; \
fi; \
PROMPT=$$(printf "%s\n\nLatest artifacts: %s (also via .latest-e2e)." "$$(cat "$$PROMPT_FILE")" "$$ART_DIR"); \
LATEST_E2E_DIR="$$ART_DIR" codex exec --sandbox read-only --cd "$(CURDIR)" "$$PROMPT"
.PHONY: reset-org
reset-org:
@echo "Resetting Konnect org (requires KONGCTL_E2E_KONNECT_PAT, optional KONGCTL_E2E_KONNECT_BASE_URL, KONGCTL_E2E_RESET)"
go run -tags e2e ./test/e2e/harness/cmd/reset-org --stage make-reset