Repository navigation
Expand file tree
/
Copy pathMakefile.custom.mk
More file actions
63 lines (55 loc) · 4.11 KB
/
Copy pathMakefile.custom.mk
File metadata and controls
63 lines (55 loc) · 4.11 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
# Repo-specific make targets. The generated Makefile.gen.*.mk are owned by devctl.
# golangci-lint as CI runs it. goconst and gosec run in the generated pre-commit
# workflow (.github/workflows/zz_generated.pre-commit.yaml): it installs a pinned
# golangci-lint and runs the golangci-lint hook over the whole module, test files
# included, so another version or linter set on a laptop passes what CI fails.
# The version is read from that workflow, so the two cannot drift; the binary is
# installed under bin/ on first use by golangci-lint's install script of the same
# tag (checksum-verified). `lint` stays the generated target: this adds the binary
# as its prerequisite and puts it first on the recipe's PATH.
GOLANGCI_LINT_VERSION := $(shell awk '/binary: golangci-lint/ { want = 1 } want && /version:/ { gsub(/"/, "", $$2); print $$2; exit }' .github/workflows/zz_generated.pre-commit.yaml)
GOLANGCI_LINT_DIR := $(CURDIR)/bin/golangci-lint-v$(GOLANGCI_LINT_VERSION)
$(GOLANGCI_LINT_DIR)/golangci-lint:
@test -n "$(GOLANGCI_LINT_VERSION)" || { echo "no golangci-lint version in .github/workflows/zz_generated.pre-commit.yaml" >&2; exit 1; }
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/v$(GOLANGCI_LINT_VERSION)/install.sh \
| sh -s -- -b $(GOLANGCI_LINT_DIR) v$(GOLANGCI_LINT_VERSION)
lint: $(GOLANGCI_LINT_DIR)/golangci-lint
lint: export PATH := $(GOLANGCI_LINT_DIR):$(PATH)
# The generated `install` links with -extldflags -static on linux but leaves cgo
# on, so the net package resolves hosts through glibc's getaddrinfo, whose NSS
# modules cannot load into a static binary: every command that resolves a host
# crashes with SIGSEGV. The build-* targets and the release binaries are built
# with CGO_ENABLED=0 and use the pure-Go resolver; `install` does the same.
install: export CGO_ENABLED := 0
# The generated `test` links the same static way, and -race needs cgo, so it
# cannot take the pure-Go resolver the way `install` does: its test binaries
# link dynamically instead, and glibc's getaddrinfo loads its NSS modules.
test: EXTLDFLAGS :=
# Commit of giantswarm/kagent-upstream the kagent.api.v1alpha1 protos under
# hack/kagent-proto/ are copied from: the tag of the kagent line the platform
# release the lab follows resolved when they were last copied. Bump it, run
# `make generate-kagent`, and commit hack/kagent-proto/ and internal/kagent/gen/
# together.
KAGENT_PROTO_REPO ?= https://github.com/giantswarm/kagent-upstream.git
KAGENT_PROTO_COMMIT ?= 2d985278ba11a7f1de66be10f04af26cf5c53a4a
KAGENT_PROTO_FILES := common agent_templates agents sessions runtime system
# Tag of giantswarm/substrate whose ate-api-server protocol (ateapi.proto) the
# proofs that drive actors directly speak: the Substrate line's own copy, which
# carries the line's fields ahead of kagent's. The oldest release whose fields
# a proof uses; a server without one of them refuses it, and the proof says so.
SUBSTRATE_PROTO_REPO ?= https://github.com/giantswarm/substrate.git
SUBSTRATE_PROTO_TAG ?= v1.8.1
.PHONY: generate-kagent
generate-kagent: ## Refresh the kagent protos from KAGENT_PROTO_COMMIT, ateapi.proto from SUBSTRATE_PROTO_TAG, and regenerate internal/kagent/gen.
@tmp=$$(mktemp -d) && git clone -q --filter=blob:none --no-checkout $(KAGENT_PROTO_REPO) $$tmp \
&& git -C $$tmp checkout -q $(KAGENT_PROTO_COMMIT) -- proto/kagent/api/v1alpha1 \
&& for f in $(KAGENT_PROTO_FILES); do cp $$tmp/proto/kagent/api/v1alpha1/$$f.proto hack/kagent-proto/kagent/api/v1alpha1/; done \
&& rm -rf $$tmp
@tmp=$$(mktemp -d) && git clone -q --filter=blob:none --no-checkout --depth 1 --branch $(SUBSTRATE_PROTO_TAG) $(SUBSTRATE_PROTO_REPO) $$tmp \
&& git -C $$tmp checkout -q $(SUBSTRATE_PROTO_TAG) -- pkg/proto/ateapipb/ateapi.proto \
&& cp $$tmp/pkg/proto/ateapipb/ateapi.proto hack/kagent-proto/ \
&& rm -rf $$tmp
cd hack/kagent-proto && PATH="$$(go env GOPATH)/bin:$$PATH" buf generate
# The repo's pre-commit runs goimports over every Go file; protoc-gen-go
# groups imports differently, so the generated files are formatted once here.
go run golang.org/x/tools/cmd/goimports@v0.50.0 -local github.com/giantswarm/agentlab -w internal/kagent/gen