-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (133 loc) · 5.41 KB
/
Copy pathMakefile
File metadata and controls
155 lines (133 loc) · 5.41 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
PACKAGE ?= ./internal/...
# LANGUAGE restricts test-backends to a single language backend. It is empty by default, which runs all of them.
LANGUAGE ?=
# The languages the harness can test are the runner directories, so adding a language is adding a directory and never
# editing a list. The name of a directory is at once the compose service, the backend the CLI generates with and the
# Ginkgo label which selects the language.
BACKEND_LANGUAGES := $(notdir $(patsubst %/,%,$(wildcard internal/backendtest/runners/*/)))
# BACKEND_LABEL is the Ginkgo label every language backend spec carries. It is what tells the two kinds of test run
# apart: test deselects it because those specs need docker and containers which have not run, and test-backends selects
# it and nothing else because it has just run them. Naming it once is what keeps the selection and the deselection from
# drifting apart.
BACKEND_LABEL := backends
# BACKEND_LABEL_FILTER selects the language backend specs, narrowed to a single language when LANGUAGE is set.
BACKEND_LABEL_FILTER := $(BACKEND_LABEL)$(if $(LANGUAGE), && $(LANGUAGE))
# The shell scripts shellcheck is run over.
SHELL_SCRIPTS := $(sort $(shell find internal scripts -name '*.sh'))
export CGO_ENABLED=0
.PHONY: all
all: build
.PHONY: generate
generate:
scripts/generate.sh
.PHONY: prepare
prepare: generate
mkdir -p ~/.cache/golangci-lint
go mod tidy
go fmt $(PACKAGE)
go vet $(PACKAGE)
docker run \
--tty \
--rm \
--volume ${PWD}:/app \
--workdir /app \
--user $$(id -u):$$(id -g) \
--volume $$(go env GOCACHE):/.cache/go-build \
--env GOCACHE=/.cache/go-build \
--volume $$(go env GOMODCACHE):/.cache/mod \
--env GOMODCACHE=/.cache/mod \
--volume ~/.cache/golangci-lint:/.cache/golangci-lint \
--env GOLANGCI_LINT_CACHE=/.cache/golangci-lint \
golangci/golangci-lint:v2.12.2 \
golangci-lint run --fix $(PACKAGE)
docker run \
--tty \
--rm \
--volume ${PWD}:/mnt \
--workdir /mnt \
koalaman/shellcheck:v0.11.0 \
$(SHELL_SCRIPTS)
.PHONY: build-examples
build-examples: build
go build ./cmd/golr
$(MAKE) -C examples build
.PHONY: build
build: prepare
go build ./cmd/golr
.PHONY: run
run: prepare
go run ./cmd/golr
.PHONY: test
test: prepare
go test $(PACKAGE) -args --ginkgo.label-filter='!$(BACKEND_LABEL)'
.PHONY: test-race
test-race: prepare
CGO_ENABLED=1 go test --race $(PACKAGE) -args --ginkgo.label-filter='!$(BACKEND_LABEL)'
.PHONY: test-coverage
test-coverage: prepare
mkdir -p tmp
rm -rf tmp/coverage
mkdir -p tmp/coverage
CGO_ENABLED=1 go test --race -coverpkg=./... -cover $(PACKAGE) -args -test.gocoverdir=$(CURDIR)/tmp/coverage --ginkgo.label-filter='!$(BACKEND_LABEL)'
@echo
@echo "========== Correct coverage over all packages =========="
go tool covdata percent -i=tmp/coverage
go tool covdata textfmt -i=tmp/coverage -o tmp/cover.out
go tool cover -html=tmp/cover.out -o tmp/cover.html
.PHONY: test-examples
test-examples: build-examples
$(MAKE) -C examples test
# test-backends proves that the code every language backend emits behaves like the reference implementation in Go. It
# is separate from test, because it generates, compiles and runs the code in a container per language, which needs
# docker and takes considerably longer than the unit tests. Which of the two runs a spec belongs to is the
# BACKEND_LABEL on the spec: test deselects it, this target selects it and nothing else, so the same package is covered
# by both targets without either running the other's specs.
#
# Producing the traces happens here and not in the suite. The container is a build step: which languages to run is
# exactly the LANGUAGE focus this file already has, and a shell loop expresses it without the suite needing setup nodes
# which run once per group.
#
# It depends on build because every container generates with the golr binary, which is mounted into all of them. That is
# what lets a container do the whole job on its own, so reproducing a failure by hand is one command.
#
# The work directory is emptied first, so a trace can never be left over from an earlier run of a case which no longer
# produces one. That failure would otherwise look like a pass. It is also created here rather than by docker, which
# creates a missing bind mount source as root and leaves the container unable to write to it.
.PHONY: test-backends
test-backends: build
rm -rf tmp/backendtest
mkdir -p tmp/backendtest
for language in $(if $(LANGUAGE),$(LANGUAGE),$(BACKEND_LANGUAGES)); do \
echo "==> running the corpus through the $$language container"; \
GOLR_UID=$$(id -u) GOLR_GID=$$(id -g) docker compose \
--file internal/backendtest/docker-compose.yaml \
--project-directory . \
run --rm --no-deps --no-TTY --build "$$language" || exit 1; \
done
go test ./internal/backendtest/... -args --ginkgo.label-filter='$(BACKEND_LABEL_FILTER)'
.PHONY: benchmark
benchmark: prepare
go test -bench=. -benchmem -run=^$$ $(PACKAGE)
.PHONY: clean
clean:
$(MAKE) -C examples clean
rm -rf tmp
rm -f golr
.PHONY: release-test
release-test:
goreleaser check
goreleaser healthcheck
goreleaser build --snapshot --clean
goreleaser release --snapshot --clean --skip=publish
.PHONY: release-notes
release-notes:
mkdir -p tmp
scripts/release-notes.sh > tmp/release-notes.md
@echo
@echo "========== Release notes =========="
@cat tmp/release-notes.md
.PHONY: release
release: release-test release-notes
release: export GITHUB_TOKEN ?= unknown
release:
goreleaser release --clean --release-notes tmp/release-notes.md