-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
executable file
·171 lines (142 loc) · 3.97 KB
/
Copy pathTaskfile.yml
File metadata and controls
executable file
·171 lines (142 loc) · 3.97 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
version: "3"
vars:
LINTER_VER: "v2.13.1"
GOMODCACHE:
sh: go env GOMODCACHE
GOCACHE:
sh: go env GOCACHE
GOSUMCACHE:
sh: echo "$(go env GOPATH)/pkg/sumdb"
# Root module + all local submodules that are part of the project.
# Examples are included because they depend on unpublished local modules.
MODULE_DIRS:
sh: |
{
printf '.\n'
find ./extra ./examples -name go.mod -print |
while IFS= read -r mod; do
dirname "$mod"
done
} | sort -u
# Coverage is aggregated for production modules only. Example modules are
# still linted and tested, but do not affect the library coverage metric.
COVERAGE_MODULE_DIRS:
sh: |
{
printf '.\n'
find ./extra -name go.mod -print |
while IFS= read -r mod; do
dirname "$mod"
done
} | sort -u | tr '\n' ' '
env:
# The workspace resolves unpublished local modules, including examples,
# against the current checkout instead of released module versions.
GOWORK: "{{.ROOT_DIR}}/go.work"
tasks:
init-workspace:
desc: "Initialize or reset the local Go workspace"
cmds:
- bash .github/scripts/create-go-workspace.sh --with-examples
run:
desc: "Run lint and race tests for all modules"
cmds:
- task: lint
- task: test-race
lint:
desc: "Lint all modules"
cmds:
- for: { var: MODULE_DIRS }
task: _run-linter
vars:
WORK_DIR: "/app/{{.ITEM}}"
test:
desc: "Run tests for all modules"
cmds:
- for: { var: MODULE_DIRS }
task: _run-tests
vars:
WORK_DIR: "{{.ITEM}}"
test-race:
desc: "Run tests with the race detector for all modules"
cmds:
- for: { var: MODULE_DIRS }
task: _run-race-tests
vars:
WORK_DIR: "{{.ITEM}}"
coverage:
desc: "Run tests and print total coverage for production modules"
cmds:
- |
set -eu
root="{{.ROOT_DIR}}"
output="$root/coverage.out"
profiles="$(mktemp -d)"
cleanup() {
rm -rf "$profiles"
}
trap cleanup EXIT
printf 'mode: atomic\n' > "$output"
profile_index=0
for module in {{.COVERAGE_MODULE_DIRS}}; do
echo "==> $module"
profile="$profiles/$profile_index.out"
profile_index=$((profile_index + 1))
(
cd "$root/$module"
GOWORK="$root/go.work" go test \
-mod=readonly \
-count=1 \
-covermode=atomic \
-coverprofile="$profile" \
./...
)
tail -n +2 "$profile" >> "$output"
done
GOWORK="$root/go.work" go tool cover -func="$output" | grep total
coverage:html:
desc: "Generate HTML coverage report"
deps:
- coverage
cmds:
- go tool cover -html=coverage.out -o coverage.html
_run-tests:
internal: true
requires:
vars:
- WORK_DIR
dir: "{{.ROOT_DIR}}/{{.WORK_DIR}}"
cmds:
- echo "==> {{.WORK_DIR}}"
- go test -mod=readonly -v -count=1 ./...
_run-race-tests:
internal: true
requires:
vars:
- WORK_DIR
dir: "{{.ROOT_DIR}}/{{.WORK_DIR}}"
cmds:
- echo "==> {{.WORK_DIR}}"
- go test -mod=readonly -race -v -count=1 ./...
_run-linter:
internal: true
requires:
vars:
- WORK_DIR
cmds:
- echo "==> {{.WORK_DIR}}"
- mkdir -p "{{.GOSUMCACHE}}"
- >
docker run --rm
-u $(id -u):$(id -g)
-v {{.ROOT_DIR}}:/app
-v {{.GOMODCACHE}}:/go/pkg/mod
-v {{.GOSUMCACHE}}:/go/pkg/sumdb
-v {{.GOCACHE}}:/go/build-cache
-e GOMODCACHE=/go/pkg/mod
-e GOCACHE=/go/build-cache
-e GOLANGCI_LINT_CACHE=/go/build-cache/golangci-lint
-e GOWORK=/app/go.work
-w {{.WORK_DIR}}
golangci/golangci-lint:{{.LINTER_VER}}
golangci-lint run --timeout 5m --modules-download-mode readonly