-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
252 lines (252 loc) · 6.27 KB
/
Taskfile.yml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Code generated by task taskfile:gen; DO NOT EDIT.
env:
GO111MODULE: auto
GOFLAGS: -mod=mod
GOPRIVATE: github.com/ghostsquad
GOPROXY: https://proxy.golang.org,direct
JSONNET_PATH: vendor
tasks:
build:
cmds:
- |
docker buildx build \
--tag {{.PUSH_IMAGE}} \
--build-arg GOLANG_BUILDER_IMAGE={{.GOLANG_BUILDER_IMAGE}} \
--build-arg DEBIAN_IMAGE={{.DEBIAN_IMAGE}} \
{{trim .BUILD_ARGS}} \
.
deps:
- task: go:version:verify
label: build with {{.BUILD_ARGS}}
run: once
vars:
BUILD_ARGS: '{{.BUILD_ARGS}}'
PUSH_IMAGE: '{{.PUSH_IMAGE | default .APP_IMAGE}}'
download:
cmds:
- go mod download
run: once
git:status:dirty:
cmds:
- '[ -z "$(git status --porcelain=v1 2>/dev/null)" ]'
run: once
go:version:get:
cmds:
- echo {{.CURRENT_GO_VERSION}}
run: once
go:version:set:
cmds:
- go mod edit --go={{.GO_VERSION_SHORT}}
- asdf install golang {{.GO_VERSION}}
- asdf local golang {{.GO_VERSION}}
- go mod tidy
run: once
vars:
GO_VERSION: '{{.CLI_ARGS | default .EXPECTED_GO_VERSION}}'
GO_VERSION_SHORT: |
{{slice (.GO_VERSION | splitList ".") 0 2 | join "."}}
go:version:update:
cmds:
- task: go:version:set
vars:
GO_VERSION:
sh: asdf latest golang
run: once
go:version:verify:
cmds:
- task: go:version:set
- task: git:status:dirty
run: once
http:metrics:
cmds:
- http localhost:8080/metrics
run: once
install-tools:
cmds:
- cmd: echo Installing tools from tools.go
silent: true
- asdf install
- |
cat hack/tools.go | grep _ | awk -F'"' '{print $2}' | xargs -tI % go install %
deps:
- download
run: once
jb:install:
cmds:
- jb install --jsonnetpkg-home='vendor' {{.CLI_ARGS}}
run: once
jb:update:
cmds:
- jb update --jsonnetpkg-home='vendor' {{.CLI_ARGS}}
run: once
k3d:config:gen:
cmds:
- |
mkdir -p '{{.USERHOME}}/.k3d/images'
- |
jsonnet --tla-str USERHOME='{{.USERHOME}}' ./environments/default/k3d.jsonnet | dasel -f - -r json -w yaml --pretty > ./environments/default/k3d.yml
- |
echo "# Code generated by task taskfile:gen; DO NOT EDIT." \
| cat - ./environments/default/k3d.yml \
| sponge ./environments/default/k3d.yml
deps:
- jb:install
run: once
k3d:up:
cmds:
- k3d cluster create --config ./environments/default/k3d.yml
- |
echo "edit /etc/hosts with 127.0.0.1 registry.localhost"
deps:
- k3d:config:gen
run: once
passthru:
cmds:
- '{{.CLI_ARGS}}'
run: once
publish:
cmds:
- task: build
vars:
BUILD_ARGS: |
--platform linux/amd64 \
--push
run: once
publish:k3d:
cmds:
- task: build
vars:
BUILD_ARGS: |
--platform linux/amd64 \
--push
PUSH_IMAGE: '{{.K3D_APP_IMAGE}}'
run: once
run:
cmds:
- go run ./cmd/app/...
run: once
taskfile:gen:
cmds:
- jsonnet {{.JSONNET_INPUT_FILE}} | dasel -f - -r json -w yaml --pretty > '{{.OUTPUT_FILE}}'
- |
echo "# Code generated by task taskfile:gen; DO NOT EDIT." \
| cat - '{{.OUTPUT_FILE}}' \
| sponge '{{.OUTPUT_FILE}}'
deps:
- jb:install
run: once
vars:
JSONNET_INPUT_FILE: taskfile.jsonnet
OUTPUT_FILE: Taskfile.yml
test:all:
cmds:
- task: test:unit
- task: test:race
- task: test:bench
run: once
test:all:ci:
cmds:
- task: test:unit:ci
- task: test:race:ci
- task: test:bench:ci
run: once
test:bench:
cmds:
- gotestsum --format short-verbose -- -count=1 -bench=. -run=^$$
deps:
- install-tools
run: once
test:bench:ci:
cmds:
- gotestsum --junitfile reports/bench-tests.xml -- -count=1 -bench=. -run=^$$
deps:
- install-tools
run: once
test:integration:
cmds:
- |
APP_IMAGE='{{.APP_IMAGE}}' \
docker-compose \
--file {{.DOCKERFILE}} \
up \
--exit-code-from test \
--abort-on-container-exit \
;
deps:
- task: build
vars:
BUILD_ARGS: --output=type=docker
env:
SUBJECT_HOSTPORT: 8080
run: once
vars:
DOCKERFILE: '{{.DOCKERFILE | default "docker-compose.tests.integration.yml"}}'
test:integration:k3d:
cmds:
- |
./hack/test.sh 'localhost' '9080'
run: once
test:race:
cmds:
- gotestsum --format short-verbose -- -count=1 -race
deps:
- install-tools
run: once
test:race:ci:
cmds:
- gotestsum --junitfile reports/race-tests.xml -- -count=1 -race
deps:
- install-tools
run: once
test:unit:
cmds:
- gotestsum --format short-verbose -- -count=1
deps:
- install-tools
run: once
test:unit:ci:
cmds:
- gotestsum --junitfile reports/unit-tests.xml -- -count=1
deps:
- install-tools
run: once
tk:
cmds:
- tk {{.CLI_ARGS}}
run: once
tk:apply:
cmds:
- tk apply --tla-str tag={{.GIT_COMMIT}} {{.CLI_ARGS}}
run: once
tk:show:
cmds:
- tk show --tla-str tag={{.GIT_COMMIT}} {{.CLI_ARGS}}
run: once
# TODO Var order matters, but since this file is dynamically generated from jsonnet, we lose ordering
# Regenerating based on this file will result in problems.
# !!! Don't forget to fix the ordering in Taskfile.yml in the interm
# https://github.com/go-task/task/issues/1051
vars:
USERHOME: '{{env "HOME"}}'
GIT_BRANCH:
sh: |
if [ "${CI:-}" == "true" ]; then
echo "${GITHUB_REF_NAME}";
else
git branch --show-current; fi
GIT_COMMIT:
sh: git rev-parse HEAD
GIT_COMMIT_SHORT:
sh: git rev-parse --short=8 HEAD
DEBIAN_VERSION: 11.5
DEBIAN_VERSION_CODENAME: bullseye
DEBIAN_IMAGE: debian:{{.DEBIAN_VERSION}}-slim
CURRENT_GO_VERSION:
sh: asdf current golang | awk '{ print $2 }'
EXPECTED_GO_VERSION: 1.20.2
EXPECTED_GO_VERSION_SHORT: |
{{slice (.EXPECTED_GO_VERSION | splitList ".") 0 2 | join "."}}
GOLANG_BUILDER_IMAGE: golang:{{.CURRENT_GO_VERSION}}-{{.DEBIAN_VERSION_CODENAME}}
APP_IMAGE: docker.io/ghostsquad/currency-converter-practice:{{.GIT_COMMIT}}
K3D_APP_IMAGE: registry.localhost:5001/ghostsquad/currency-converter-practice:{{.GIT_COMMIT}}
version: "3"