-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
291 lines (240 loc) · 7.45 KB
/
Taskfile.yaml
File metadata and controls
291 lines (240 loc) · 7.45 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
version: "3"
vars:
OWNER: anchore
PROJECT: quill
# static file dirs
TOOL_DIR: .tool
TMP_DIR: .tmp
RESULTS_DIR: test/results
# TOOLS
BINNY: "{{ .TOOL_DIR }}/binny"
GOSIMPORTS: "{{ .TOOL_DIR }}/gosimports"
GOLANGCI_LINT: "{{ .TOOL_DIR }}/golangci-lint"
BOUNCER: "{{ .TOOL_DIR }}/bouncer"
CHRONICLE: "{{ .TOOL_DIR }}/chronicle"
GLOW: "{{ .TOOL_DIR }}/glow"
GORELEASER: "{{ .TOOL_DIR }}/goreleaser"
# used for changelog generation
CHANGELOG: CHANGELOG.md
NEXT_VERSION: VERSION
# used for snapshot builds
OS:
sh: uname -s | tr '[:upper:]' '[:lower:]'
ARCH:
sh: |
[ "$(uname -m)" = "x86_64" ] && echo "amd64_v1" || echo "$(uname -m)"
PROJECT_ROOT:
sh: echo $PWD
SNAPSHOT_DIR: ./snapshot
SNAPSHOT_BIN: "{{ .PROJECT_ROOT }}/{{ .SNAPSHOT_DIR }}/{{ .OS }}-build_{{ .OS }}_{{ .ARCH }}/{{ .PROJECT }}"
SNAPSHOT_CMD: "{{ .GORELEASER }} release --config {{ .TMP_DIR }}/goreleaser.yaml --clean --snapshot --skip=publish --skip=sign"
BUILD_CMD: "{{ .GORELEASER }} build --config {{ .TMP_DIR }}/goreleaser.yaml --clean --snapshot --single-target"
RELEASE_CMD: "{{ .GORELEASER }} release --clean --release-notes {{ .CHANGELOG }}"
# unit test coverage threshold (in % coverage)
COVERAGE_THRESHOLD: 25
tasks:
default:
# desc: Run all validation tasks
aliases:
- pr-validations
- validations
cmds:
- task: static-analysis
- task: test
- task: build
static-analysis:
desc: Run all static analysis tasks
cmds:
- task: check-go-mod-tidy
- task: lint
- task: check-licenses
test:
desc: Run all levels of test
cmds:
- task: unit
## Bootstrap tasks #################################
binny:
internal: true
# desc: Get the binny tool
generates:
- "{{ .BINNY }}"
status:
- "test -f {{ .BINNY }}"
cmd: "curl -sSfL https://get.anchore.io/binny | sh -s -- -b .tool"
silent: true
tools:
desc: Install all tools needed for CI and local development
deps: [binny]
aliases:
- bootstrap
generates:
- ".binny.yaml"
- "{{ .TOOL_DIR }}/*"
status:
- "{{ .BINNY }} check -v"
cmd: "{{ .BINNY }} install -v"
silent: true
update-tools:
desc: Update pinned versions of all tools to their latest available versions
deps: [binny]
generates:
- ".binny.yaml"
- "{{ .TOOL_DIR }}/*"
cmd: "{{ .BINNY }} update -v"
silent: true
list-tools:
desc: List all tools needed for CI and local development
deps: [binny]
cmd: "{{ .BINNY }} list"
silent: true
list-tool-updates:
desc: List all tools that are not up to date relative to the binny config
deps: [binny]
cmd: "{{ .BINNY }} list --updates"
silent: true
tmpdir:
silent: true
generates:
- "{{ .TMP_DIR }}"
cmd: "mkdir -p {{ .TMP_DIR }}"
## Static analysis tasks #################################
format:
desc: Auto-format all source code
deps: [tools]
cmds:
- gofmt -w -s .
- "{{ .GOSIMPORTS }} -local github.com/anchore -w ."
- go mod tidy
lint-fix:
desc: Auto-format all source code + run golangci lint fixers
deps: [tools]
cmds:
- task: format
- "{{ .GOLANGCI_LINT }} run --tests=false --fix"
lint:
desc: Run gofmt + golangci lint checks
vars:
BAD_FMT_FILES:
sh: gofmt -l -s .
BAD_FILE_NAMES:
sh: "find . | grep -e ':' || true"
deps: [tools]
cmds:
# ensure there are no go fmt differences
- cmd: 'test -z "{{ .BAD_FMT_FILES }}" || (echo "files with gofmt issues: [{{ .BAD_FMT_FILES }}]"; exit 1)'
silent: true
# ensure there are no files with ":" in it (a known bad case in the go ecosystem)
- cmd: 'test -z "{{ .BAD_FILE_NAMES }}" || (echo "files with bad names: [{{ .BAD_FILE_NAMES }}]"; exit 1)'
silent: true
# run linting
- "{{ .GOLANGCI_LINT }} run --tests=false"
# ensure there are no gosimports differences
- cmd: '[ -z "$({{ .GOSIMPORTS }} -local github.com/anchore -d .)" ] || (echo "gosimports needs to be fixed" && false)'
silent: true
check-go-mod-tidy:
# desc: Ensure go.mod and go.sum are up to date
cmds:
- .github/scripts/go-mod-tidy-check.sh && echo "go.mod and go.sum are tidy!"
check-licenses:
# desc: Ensure licenses are valid
deps: [tools]
cmds:
- "{{ .BOUNCER }} check ./..."
## Testing tasks #################################
unit:
desc: Run all unit tests
vars:
TEST_PKGS:
sh: "go list ./... | grep -v {{ .OWNER }}/{{ .PROJECT }}/test | tr '\n' ' '"
cmds:
- cmd: "mkdir -p {{ .TMP_DIR }}"
silent: true
- "go test -coverprofile {{ .TMP_DIR }}/unit-coverage-details.txt {{ .TEST_PKGS }}"
- cmd: ".github/scripts/coverage.py {{ .COVERAGE_THRESHOLD }} {{ .TMP_DIR }}/unit-coverage-details.txt"
silent: true
## Test-fixture-related tasks #################################
fingerprints:
desc: Create all test cache input fingerprints
cmds:
- cmd: "cd test/install && make cache.fingerprint"
install-test:
desc: Run install.sh tests
cmds:
- cmd: "cd test/install && make"
install-test-cache-save:
# desc: Save install test cache
cmds:
- cmd: "cd test/install && make save"
install-test-cache-load:
# desc: Load install test cache
cmds:
- cmd: "cd test/install && make load"
## Code generation tasks #################################
update-apple-certs:
desc: Update the apple certs checked into the repo
cmds:
- go generate ./quill/pki/apple
## Build-related tasks #################################
changelog:
desc: Generate a changelog
deps: [tools]
generates:
- "{{ .CHANGELOG }}"
- "{{ .NEXT_VERSION }}"
cmds:
- "{{ .CHRONICLE }} -vvv -n --version-file {{ .NEXT_VERSION }} > {{ .CHANGELOG }}"
- "{{ .GLOW }} {{ .CHANGELOG }}"
snapshot:
desc: Create a snapshot release
aliases:
- build
deps: [tools, tmpdir]
cmds:
- cmd: |
cat .goreleaser.yaml > {{ .TMP_DIR }}/goreleaser.yaml
echo "dist: {{ .SNAPSHOT_DIR }}" >> {{ .TMP_DIR }}/goreleaser.yaml
- "{{ .SNAPSHOT_CMD }}"
cli:
desc: Run CLI tests
cmds:
- "chmod 755 {{ .SNAPSHOT_BIN }}"
- "{{ .SNAPSHOT_BIN }} version"
- "go test -count=1 -timeout=15m -v ./test/cli"
## Release tasks #################################
release:
desc: Create a release
interactive: true
deps: [tools]
cmds:
- cmd: .github/scripts/trigger-release.sh
silent: true
ci-release:
# desc: "[CI only] Create a release"
deps: [tools]
cmds:
- task: ci-check
- "{{ .CHRONICLE }} -vvv > {{ .CHANGELOG }}"
- cmd: "cat {{ .CHANGELOG }}"
silent: true
- "{{ .RELEASE_CMD }}"
ci-check:
# desc: "[CI only] Are you in CI?"
cmds:
- cmd: .github/scripts/ci-check.sh
silent: true
## Cleanup tasks #################################
clean:
desc: Remove previous builds, result reports, and test cache
cmds:
- "rm -rf {{ .RESULTS_DIR }}/*"
- task: clean-snapshot
- task: clean-dist
clean-snapshot:
# desc: Remove snapshot build artifacts
cmds:
- "rm -rf {{ .SNAPSHOT_DIR }} {{ .TMP_DIR }}/goreleaser.yaml"
clean-dist:
# desc: Remove distribution artifacts
cmds:
- "rm -rf dist {{ .TMP_DIR }}/goreleaser.yaml"
- "rm -f {{ .CHANGELOG }} {{ .NEXT_VERSION }}"