-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
157 lines (128 loc) · 3.82 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
#
SHELL := /bin/bash
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
root_mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
export REPO_ROOT_DIR := $(realpath $(dir $(root_mkfile_path)))
export DOCKER_REPOSITORY ?= ghcr.io/floatme-corp/golflog
export DOCKER_DEVKIT_IMG ?= $(DOCKER_REPOSITORY):latest-devkit
export DOCKER_DEVKIT_PHONY_FILE ?= .docker-$(shell echo '$(DOCKER_DEVKIT_IMG)' | tr '/:' '.')
export DOCKER_DEVKIT_GITHUB_ARGS ?= \
$(if $(GITHUB_EVENT_PATH),--volume $(GITHUB_EVENT_PATH):$(GITHUB_EVENT_PATH)) \
--env CI \
--env-file <(env | grep '^GITHUB_') \
--env-file <(env | grep '^GIT_')
export DOCKER_DEVKIT_ARGS ?= \
--rm \
$(if $(INTERACTIVE),--tty) \
--interactive \
--env DEVKIT=true \
--volume $(REPO_ROOT_DIR):/code:Z \
--workdir /code \
$(DOCKER_DEVKIT_GITHUB_ARGS)
# NOTE(jkoelker) Comma must not appear in a funciton call, use a variable
# as suggested by the documentation.
# https://www.gnu.org/software/make/manual/html_node/Syntax-of-Functions.html
comma := ,
export DOCKER_DEVKIT_BUILDX_ARGS ?= \
$(if $(GITHUB_ACTIONS),--cache-from type=gha) \
$(if $(GITHUB_ACTIONS),--cache-to type=gha$(comma)mode=max)
# NOTE(jkoelker) Abuse ifeq and the junk variable to proxy docker image state
# to the target file
ifneq ($(shell command -v docker),)
ifeq ($(shell docker image ls --quiet "$(DOCKER_DEVKIT_IMG)"),)
export junk := $(shell rm -rf $(DOCKER_DEVKIT_PHONY_FILE))
endif
endif
$(DOCKER_DEVKIT_PHONY_FILE): $(shell find $(REPO_ROOT_DIR)/tools -type f -name '*'.go)
$(DOCKER_DEVKIT_PHONY_FILE): Dockerfile.devkit
docker buildx build \
$(DOCKER_DEVKIT_BUILDX_ARGS) \
--file $(REPO_ROOT_DIR)/Dockerfile.devkit \
--tag "$(DOCKER_DEVKIT_IMG)" \
$(REPO_ROOT_DIR) \
&& touch $(DOCKER_DEVKIT_PHONY_FILE)
.PHONY: devkit
devkit: $(DOCKER_DEVKIT_PHONY_FILE)
WHAT ?= /bin/bash -l
.PHONY: devkit.run
devkit.run: devkit
docker run \
$(DOCKER_DEVKIT_ARGS) \
"$(DOCKER_DEVKIT_IMG)" \
/bin/bash -c \
'git config --global safe.directory /code \
&& $(WHAT)'
.PHONY: dev
dev: devkit.run
.PHONY: shell
shell: devkit.run
.PHONY: clean
clean: clean-coverage
clean: clean-mocks
.PHONY: clean-coverage
clean-coverage:
rm -f coverage.out coverage.xml coverage.html
.PHONY: clean-mocks
clean-mocks:
rm -r mocks/build_info.go mocks/configurator.go
coverage.out: $(shell find $(REPO_ROOT_DIR) -type f -name '*'.go)
coverage.out: generate.host
coverage.out:
gotestsum \
--junitfile-testsuite-name=relative \
--junitfile-testcase-classname=short \
-- \
-covermode=atomic \
-coverprofile=coverage.out \
-race \
-short \
-v \
./...
coverage.html: coverage.out
coverage.html:
go tool cover -html=coverage.out -o coverage.html
.PHONY: goveralls
goveralls: coverage.out
goveralls:
# NOTE(jkoelker) Shenanigans to securly shuttle the token to goveralls
token="$$(mktemp)" && \
printenv "GITHUB_TOKEN" > "$${token}" && \
goveralls \
-repotokenfile="$${token}" \
-coverprofile=coverage.out \
-service=github && \
rm "$${token}"
.PHONY: lint.host-docker
lint.host-docker:
@echo "Linting Dockerfiles"
find $(REPO_ROOT_DIR)/ -name 'Dockerfile*' -exec hadolint {} +
@echo
.PHONY: lint.host-go
lint.host-go: generate.host
@echo "Linting Go files"
golangci-lint run --verbose
@echo
.PHONY: lint.host
lint.host: lint.host-docker
lint.host: lint.host-go
.PHONY: lint
lint: WHAT=make lint.host
lint: devkit.run
.PHONY: generate
generate: WHAT=make generate.host
generate: devkit.run
.PHONY: generate.host
generate.host: generate.host-mocks
.PHONY: generate.host-mocks
generate.host-mocks: mocks/configurator.go
generate.host-mocks: mocks/build_info.go
mocks/configurator.go: log.go
go generate log.go
mocks/build_info.go: log.go
go generate log.go
.PHONY: test
test: WHAT=make test.host
test: devkit.run
.PHONY: test.host
test.host: generate.host
test.host: coverage.html