Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (63 loc) · 3.21 KB
/
Copy pathMakefile
File metadata and controls
82 lines (63 loc) · 3.21 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
############################# Main targets #############################
# Install all tools, run all possible checks and tests (long but comprehensive).
all: clean test
# Delete all build artifacts
clean: clean-test-output
########################################################################
.PHONY: clean
##### Variables ######
COLOR := "\e[1;36m%s\e[0m\n"
RED := "\e[1;31m%s\e[0m\n"
ALL_SRC := $(shell find . -name "*.go")
ALL_SRC += go.mod
UNIT_TEST_DIRS ?= ./...
LINT_DIRS ?= ./...
MAIN_BRANCH ?= main
TEST_OUTPUT_ROOT ?= $(CURDIR)/reports
# REPORT=true switches test output to `go test -json` plus a coverage profile,
# written under TEST_OUTPUT_ROOT for CI to pick up.
REPORT ?= false
UNIT_REPORT_FLAGS := $(if $(filter true,$(REPORT)),-v -json -coverprofile=$(TEST_OUTPUT_ROOT)/unit-coverage.out)
UNIT_REPORT_REDIRECT := $(if $(filter true,$(REPORT)),> $(TEST_OUTPUT_ROOT)/unit-report.json)
INTEGRATION_REPORT_FLAGS := $(if $(filter true,$(REPORT)),-v -json -coverprofile=$(TEST_OUTPUT_ROOT)/integration-coverage.out)
INTEGRATION_REPORT_REDIRECT := $(if $(filter true,$(REPORT)),> $(TEST_OUTPUT_ROOT)/integration-report.json)
##### Binaries #####
##### Tests #####
clean-test-output:
@printf $(COLOR) "Delete test output..."
@rm -rf $(TEST_OUTPUT_ROOT)
@go clean -testcache
unit-test: clean-test-output
@printf $(COLOR) "Run unit tests..."
@mkdir -p $(TEST_OUTPUT_ROOT)
@CGO_ENABLED=$(CGO_ENABLED) go test $(UNIT_TEST_FLAGS) $(UNIT_REPORT_FLAGS) $(UNIT_TEST_DIRS) $(COMPILED_TEST_ARGS) $(UNIT_REPORT_REDIRECT)
integration-test:
@printf $(COLOR) "Run integration tests..."
@mkdir -p $(TEST_OUTPUT_ROOT)
@CGO_ENABLED=$(CGO_ENABLED) go test -tags=test_dep -timeout 300s ./tests/integration/... $(INTEGRATION_TEST_FLAGS) $(INTEGRATION_REPORT_FLAGS) $(INTEGRATION_REPORT_REDIRECT)
test: unit-test integration-test
##### Linting / formatting #####
# --build-tags=test_dep is needed so golangci-lint can typecheck tests/integration,
# which is gated behind that build tag.
lint:
@printf $(COLOR) "Run golangci-lint..."
@golangci-lint run --build-tags=test_dep $(LINT_DIRS)
# Lint only changes introduced since this branch diverged from $(MAIN_BRANCH).
lint-branch:
@printf $(COLOR) "Run golangci-lint on changes since merge-base with $(MAIN_BRANCH)..."
@golangci-lint run --build-tags=test_dep --new-from-rev=$$(git merge-base HEAD $(MAIN_BRANCH)) $(LINT_DIRS)
fmt:
@printf $(COLOR) "Format with golangci-lint..."
@golangci-lint fmt $(LINT_DIRS)
# Format only Go files changed since this branch diverged from $(MAIN_BRANCH).
fmt-branch:
@printf $(COLOR) "Format Go files changed since merge-base with $(MAIN_BRANCH)..."
@files=$$(git diff --name-only --diff-filter=d $$(git merge-base HEAD $(MAIN_BRANCH)) -- '*.go'); \
if [ -n "$$files" ]; then golangci-lint fmt $$files; else printf $(COLOR) "No changed Go files."; fi
.PHONY: lint lint-branch fmt fmt-branch
##### Run server #####
start: start-sqlite-file
start-sqlite: temporal-auto-scaled-workers
./temporal-auto-scaled-workers --config-file config/development-sqlite.yaml start
start-sqlite-file: temporal-auto-scaled-workers
./temporal-auto-scaled-workers --config-file config/development-sqlite-file.yaml start