-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
183 lines (150 loc) · 6.29 KB
/
Makefile
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
PROJECT := enduro
MAKEDIR := hack/make
SHELL := /bin/bash
.DEFAULT_GOAL := help
.PHONY: *
DBG_MAKEFILE ?=
ifeq ($(DBG_MAKEFILE),1)
$(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)")
$(warning ***** $(shell date))
else
# If we're not debugging the Makefile, don't echo recipes.
MAKEFLAGS += -s
endif
include hack/make/bootstrap.mk
include hack/make/dep_goa.mk
include hack/make/dep_golangci_lint.mk
include hack/make/dep_gomajor.mk
include hack/make/dep_goreleaser.mk
include hack/make/dep_gosec.mk
include hack/make/dep_gotestsum.mk
include hack/make/dep_hugo.mk
include hack/make/dep_jq.mk
include hack/make/dep_mockgen.mk
include hack/make/dep_temporal_cli.mk
define NEWLINE
endef
IGNORED_PACKAGES := \
github.com/artefactual-labs/enduro/hack/% \
github.com/artefactual-labs/enduro/%/fake \
github.com/artefactual-labs/enduro/ui \
github.com/artefactual-labs/enduro/internal/api/design \
github.com/artefactual-labs/enduro/internal/api/gen/% \
github.com/artefactual-labs/enduro/internal/batch/fake \
github.com/artefactual-labs/enduro/internal/collection/fake \
github.com/artefactual-labs/enduro/internal/pipeline/fake \
github.com/artefactual-labs/enduro/internal/watcher/fake
PACKAGES := $(shell go list ./...)
TEST_PACKAGES := $(filter-out $(IGNORED_PACKAGES),$(PACKAGES))
TEST_IGNORED_PACKAGES := $(filter $(IGNORED_PACKAGES),$(PACKAGES))
export PATH:=$(GOBIN):$(PATH)
run: # @HELP Builds and run the enduro binary.
run: build
./build/enduro
build: # @HELP Builds the enduro binary.
build: GO ?= $(shell which go)
build: BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%T%z)
build: GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
build: LD_FLAGS ?= '-X "main.buildTime=$(BUILD_TIME)" -X main.gitCommit=$(GIT_COMMIT)'
build: GO_FLAGS ?= -ldflags=$(LD_FLAGS)
build:
mkdir -p ./build
$(GO) build -trimpath -o build/enduro $(GO_FLAGS) -v
deps: $(GOMAJOR) # @HELP Lists available module dependency updates.
gomajor list
gosec: # @HELP Run gosec security scanner.
gosec: $(GOSEC)
gosec \
-exclude-dir=hack \
-exclude-dir=internal/api/gen \
-exclude-dir=ui \
./...
test: # @HELP Run all tests and output a summary using gotestsum.
test: TFORMAT ?= short
test: GOTEST_FLAGS ?=
test: COMBINED_FLAGS ?= $(GOTEST_FLAGS) $(TEST_PACKAGES)
test: $(GOTESTSUM)
gotestsum --format=$(TFORMAT) -- $(COMBINED_FLAGS)
test-race: # @HELP Run all tests with the race detector.
test-race:
$(MAKE) test GOTEST_FLAGS="-race"
test-ci: # @HELP Run all tests in CI with coverage and the race detector.
test-ci:
$(MAKE) test GOTEST_FLAGS="-race -coverprofile=covreport -covermode=atomic"
list-tested-packages: # @HELP Print a list of packages being tested.
list-tested-packages:
$(foreach PACKAGE,$(TEST_PACKAGES),@echo $(PACKAGE)$(NEWLINE))
list-ignored-packages: # @HELP Print a list of packages ignored in testing.
list-ignored-packages:
$(foreach PACKAGE,$(TEST_IGNORED_PACKAGES),@echo $(PACKAGE)$(NEWLINE))
lint: # @HELP Lints the code using golangci-lint.
lint: $(GOLANGCI_LINT)
golangci-lint run -v --timeout=5m --fix
gen-goa: # @HELP Generates Goa assets.
gen-goa: $(GOA)
goa gen github.com/artefactual-labs/enduro/internal/api/design -o internal/api
@$(MAKE) gen-goa-json-pretty
gen-goa-json-pretty: goa_http_dir = "internal/api/gen/http"
gen-goa-json-pretty: json_files = $(shell find $(goa_http_dir) -type f -name "*.json" | sort -u)
gen-goa-json-pretty: $(JQ)
@for f in $(json_files); \
do (cat "$$f" | jq -S '.' >> "$$f".sorted && mv "$$f".sorted "$$f") \
&& echo "Formatting $$f with jq" || exit 1; \
done
clean: # @HELP Cleans temporary files.
clean:
rm -rf ./build ./dist
release-test-config: # @HELP Tests the goreleaser config.
release-test-config: $(GORELEASER)
goreleaser --snapshot --skip-publish --clean
release-test: # @HELP Tests the release with goreleaser.
release-test: $(GORELEASER)
goreleaser --skip-publish
website: # @HELP Serves the website for development.
website: $(HUGO)
hugo serve --source=website/
ui: # @HELP Builds the UI.
ui:
npm --prefix=ui install
npm --prefix=ui run build
ui-dev:
ui-dev: # @HELP Serves the UI for development.
npm --prefix=ui run dev
ui-client: # @HELP Generates the UI client using openapi-generator-cli.
ui-client:
rm -rf $(CURDIR)/ui/src/client
docker container run --rm --user $(shell id -u):$(shell id -g) --volume $(CURDIR):/local openapitools/openapi-generator-cli:v6.6.0 \
generate \
--input-spec /local/internal/api/gen/http/openapi3.json \
--generator-name typescript-fetch \
--output /local/ui/src/openapi-generator/ \
-p "generateAliasAsModel=false" \
-p "withInterfaces=true" \
-p "supportsES6=true"
echo "@@@@ Please, review all warnings generated by openapi-generator-cli above!"
db: # @HELP Opens the MySQL CLI.
db:
docker compose exec --user=root mysql mysql -hlocalhost -uroot -proot123
flush: # @HELP Flushes the enduro database.
flush:
docker compose exec --user=root mysql mysql -hlocalhost -uroot -proot123 -e "drop database enduro"
docker compose exec --user=root mysql mysql -hlocalhost -uroot -proot123 -e "create database enduro"
gen-mock: # @HELP Generates mocks with mockgen.
gen-mock: $(MOCKGEN)
mockgen -typed -destination=./internal/batch/fake/mock_batch.go -package=fake github.com/artefactual-labs/enduro/internal/batch Service
mockgen -typed -destination=./internal/collection/fake/mock_collection.go -package=fake github.com/artefactual-labs/enduro/internal/collection Service
mockgen -typed -destination=./internal/pipeline/fake/mock_pipeline.go -package=fake github.com/artefactual-labs/enduro/internal/pipeline Service
mockgen -typed -destination=./internal/watcher/fake/mock_watcher.go -package=fake github.com/artefactual-labs/enduro/internal/watcher Service
mockgen -typed -destination=./internal/watcher/fake/mock_watcher_unit.go -package=fake github.com/artefactual-labs/enduro/internal/watcher Watcher
temporal: # @HELP Runs a development instance of Temporal.
temporal: PORT := 55555
temporal: LOG_LEVEL := warn
temporal: $(TEMPORAL_CLI)
temporal server start-dev --namespace=default --port=$(PORT) --headless --log-format=pretty --log-level=$(LOG_LEVEL)
help: # @HELP Prints this message.
echo "TARGETS:"
grep -E '^.*: *# *@HELP' Makefile \
| awk ' \
BEGIN {FS = ": *# *@HELP"}; \
{ printf " %-30s %s\n", $$1, $$2 }; \
'