-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaskfile.yml
221 lines (202 loc) · 5.99 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
# This file is maintained by Tedium - manual edits will be overwritten!
version: "3"
includes:
local:
taskfile: taskfile.local.yml
optional: true
tasks:
deps:
cmds:
- task: deps-go-backend
- task: deps-js-frontend
deps-go:
cmds:
- task: deps-go-backend
deps-go-backend:
dir: '{{.ROOT_DIR}}/backend'
cmds:
- cmd: go mod tidy && go mod download --json
deps-js:
cmds:
- task: deps-js-frontend
deps-js-frontend:
dir: '{{.ROOT_DIR}}/frontend'
cmds:
- cmd: pnpm install --frozen-lockfile
gen:
cmds:
- task: gen-buf-proto
- task: gen-sqlc-sql
gen-buf:
cmds:
- task: gen-buf-proto
gen-buf-proto:
dir: '{{.ROOT_DIR}}/proto'
cmds:
- cmd: buf generate
gen-sqlc:
cmds:
- task: gen-sqlc-sql
gen-sqlc-sql:
dir: '{{.ROOT_DIR}}/sql'
cmds:
- cmd: sqlc generate
imgbuild:
cmds:
- task: imgbuild-root
imgbuild-root:
dir: '{{.ROOT_DIR}}'
deps:
- imgrefs-root
cmds:
- cmd: |-
set -euo pipefail
if command -v podman >/dev/null 2>&1; then
# Podman for building locally or in Tatsu CI
builder=podman
elif command -v docker >/dev/null 2>&1; then
# Docker for building in Circle CI
builder=docker
else
echo "Cannot find Podman or Docker" >&2
exit 1
fi
# First build to get visible logs
$builder build -f Containerfile .
# Second (cached) build to get the image ID
img=$($builder build -q -f Containerfile .)
if [[ -f .imgrefs ]]; then
cat .imgrefs | while read tag; do
$builder tag "$img" "${tag}"
echo "Tagged ${tag}"
done
fi
imgpush:
cmds:
- task: imgpush-root
imgpush-root:
dir: '{{.ROOT_DIR}}'
deps:
- imgrefs-root
cmds:
- cmd: |-
set -euo pipefail
if command -v podman >/dev/null 2>&1; then
# Podman for building locally or in Tatsu CI
builder=podman
elif command -v docker >/dev/null 2>&1; then
# Docker for building in Circle CI
builder=docker
else
echo "Cannot find Podman or Docker" >&2
exit 1
fi
if [[ -f .imgrefs ]]; then
cat .imgrefs | (grep -v "^localhost" || :) | while read tag; do
$builder push "${tag}"
echo "Pushed ${tag}"
done
else
echo "No .imgrefs file - nothing will be pushed"
exit 1
fi
imgrefs:
cmds:
- task: imgrefs-root
imgrefs-root:
dir: '{{.ROOT_DIR}}'
cmds:
- cmd: |-
set -euo pipefail
if [[ -f .imgrefs ]] && [[ ${CI+y} == "y" ]]; then
echo "Skipping re-computing tags"
exit 0
fi
if ! command -v git >/dev/null 2>&1; then
echo "Cannot find git" >&2
exit 1
fi
if ! git describe --tags >/dev/null 2>&1; then
echo "No git tags to descibe" >&2
exit 1
fi
if ! grep ".imgrefs" .gitignore >/dev/null 2>&1; then
echo ".gitignore must include .imgrefs to use the image builder tasks" >&2
exit 1
fi
img_name=$( (grep "LABEL image.name=" Containerfile || echo) | head -n 1 | cut -d '=' -f 2-)
img_registry=$( (grep "LABEL image.registry=" Containerfile || echo) | head -n 1 | cut -d '=' -f 2-)
version=$(git describe --tags)
is_exact_tag=$(git describe --tags --exact-match >/dev/null 2>&1 && echo y || echo n)
major_version=$(echo "${version}" | cut -d '.' -f 1)
latest_version_overall=$(git tag -l | sort -r -V | head -n 1)
latest_version_within_major=$(git tag -l | grep "^${major_version}" | sort -r -V | head -n 1)
echo -n "" > .imgrefs
if [[ ! -z "$img_name" ]]; then
echo "localhost/${img_name}" >> .imgrefs
echo "localhost/${img_name}:${version}" >> .imgrefs
if [[ ! -z "$img_registry" ]] && [[ ${CI+y} == "y" ]]; then
echo "${img_registry}/${img_name}:${version}" >> .imgrefs
if [[ "${is_exact_tag}" == "y" ]] && [[ "${version}" == "${latest_version_within_major}" ]]; then
echo "${img_registry}/${img_name}:${major_version}" >> .imgrefs
fi
if [[ "${is_exact_tag}" == "y" ]] && [[ "${version}" == "${latest_version_overall}" ]]; then
echo "${img_registry}/${img_name}:latest" >> .imgrefs
fi
fi
else
echo "Warning: no image name label; image will not be tagged" >&2
fi
echo "Image refs:"
cat .imgrefs | grep "." || echo "None"
lint:
cmds:
- task: lint-buf-proto
- task: lint-go-backend
- task: lint-js-frontend
lint-buf:
cmds:
- task: lint-buf-proto
lint-buf-proto:
dir: '{{.ROOT_DIR}}/proto'
cmds:
- cmd: buf format --diff --exit-code
- cmd: buf lint
lint-go:
cmds:
- task: lint-go-backend
lint-go-backend:
dir: '{{.ROOT_DIR}}/backend'
cmds:
- cmd: |-
fmt_diff=$(gofmt -e -s -d $(go list -f '{{ "{{.Dir}}" }}' ./... | grep -v /.go/ | grep -v /vendor/))
if [[ ! -z "$fmt_diff" ]]; then
echo "Format errors:"
echo "$fmt_diff"
exit 1
fi
lint-js:
cmds:
- task: lint-js-frontend
lint-js-frontend:
dir: '{{.ROOT_DIR}}/frontend'
cmds:
- cmd: pnpm lint
lintfix:
cmds:
- task: lintfix-buf-proto
- task: lintfix-go-backend
lintfix-buf:
cmds:
- task: lintfix-buf-proto
lintfix-buf-proto:
dir: '{{.ROOT_DIR}}/proto'
cmds:
- cmd: buf format --write
lintfix-go:
cmds:
- task: lintfix-go-backend
lintfix-go-backend:
dir: '{{.ROOT_DIR}}/backend'
cmds:
- cmd: gofmt -s -w .