-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTaskfile.yaml
183 lines (155 loc) · 4.92 KB
/
Taskfile.yaml
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
version: "3"
vars:
TOOL_DIR: .tool
OWNER: anchore
PROJECT: grant
TMP_DIR: .tmp
SNAPSHOT_DIR: snapshot
CHANGELOG: CHANGELOG.md
NEXT_VERSION: VERSION
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
test:
desc: Run all levels of test
cmds:
- task: unit
## Bootstrap tasks #################################
binny:
internal: true
desc: Get the binny tool
generates:
- "{{ .TOOL_DIR }}/binny"
status:
- "test -f {{ .TOOL_DIR }}/binny"
# we just need a release of binny, doesn't matter which one (binny will update itself, this is just a bootstrap step)
cmd: "curl -sSfL https://raw.githubusercontent.com/{{ .OWNER }}/binny/main/install.sh | sh -s -- -b {{ .TOOL_DIR }}"
silent: true
tools:
desc: Install all tools needed for CI and local development
deps: [binny]
generates:
- "{{ .TOOL_DIR }}/binny"
- "{{ .TOOL_DIR }}/grant"
- "{{ .TOOL_DIR }}/task"
- "{{ .TOOL_DIR }}/gosimports"
- "{{ .TOOL_DIR }}/golangci-lint"
- "{{ .TOOL_DIR }}/chronicle"
- "{{ .TOOL_DIR }}/glow"
- "{{ .TOOL_DIR }}/goreleaser"
- "{{ .TOOL_DIR }}/bouncer"
status:
- "{{ .TOOL_DIR }}/binny check -v"
cmd: "{{ .TOOL_DIR }}/binny install -v"
silent: true
## Static analysis tasks #################################
format:
desc: Auto-format all source code
deps: [tools]
cmds:
- gofmt -w -s .
- "{{ .TOOL_DIR }}/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
- "{{ .TOOL_DIR }}/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 back 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
- "{{ .TOOL_DIR }}/golangci-lint run --tests=false"
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!"
## Testing tasks #################################
unit:
desc: Run all unit tests
vars:
TEST_PKGS:
sh: "go list ./... | grep -v {{ .OWNER }}/{{ .PROJECT }}/test | tr '\n' ' '"
# unit test coverage threshold (in % coverage)
COVERAGE_THRESHOLD: 8
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
## Build-related targets #################################
changelog:
desc: Generate a changelog
deps: [tools]
generates:
- "{{ .CHANGELOG }}"
- "{{ .NEXT_VERSION }}"
cmds:
- "{{ .TOOL_DIR }}/chronicle -vv -n --version-file {{ .NEXT_VERSION }} > {{ .CHANGELOG }}"
- "{{ .TOOL_DIR }}/glow {{ .CHANGELOG }}"
snapshot:
desc: Create a snapshot release
aliases:
- build
deps: [tools]
cmds:
- cmd: "mkdir -p {{ .TMP_DIR }}"
silent: true
- cmd: |
cat .goreleaser.yaml > {{ .TMP_DIR }}/goreleaser.yaml
echo "dist: {{ .SNAPSHOT_DIR }}" >> {{ .TMP_DIR }}/goreleaser.yaml
- cmd: "{{ .TOOL_DIR }}/goreleaser release --clean --skip=publish --skip=sign --snapshot --config {{ .TMP_DIR }}/goreleaser.yaml"
## Release targets #################################
release:
desc: Create a release
interactive: true
deps: [tools]
cmds:
- cmd: .github/scripts/trigger-release.sh
silent: true
## CI-only targets #################################
ci-check:
# desc: "[CI only] Are you in CI?"
cmds:
- cmd: .github/scripts/ci-check.sh
silent: true
ci-validate:
# desc: "[CI only] Run all CI validations"
cmds:
- task: ci-check
- task: default
ci-release:
# desc: "[CI only] Create a release"
deps: [tools]
cmds:
- task: ci-check
- "{{ .TOOL_DIR }}/chronicle -vvv > CHANGELOG.md"
- cmd: "cat CHANGELOG.md"
silent: true
- "{{ .TOOL_DIR }}/goreleaser release --clean --release-notes CHANGELOG.md"