-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathTaskfile.yml
More file actions
159 lines (146 loc) · 6.01 KB
/
Copy pathTaskfile.yml
File metadata and controls
159 lines (146 loc) · 6.01 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
version: "3"
# Every check runs in the toolchain image built from hack/dev.Dockerfile, one
# stage per check, so the host needs only docker and task and CI runs the exact
# same tool versions. It is also the only way the checks see the whole tree:
# much of internal/nvmlnative is behind a `linux && cgo` build tag, which a host
# toolchain on macOS excludes from the build entirely, so a host linter reports
# success without having read those files at all.
#
# The Go version comes from go.mod, so the toolchain cannot drift from what the
# module declares.
tasks:
fmt:
desc: format code and scripts
cmds:
# the formatters write in place, so the working tree is bind-mounted
# rather than exported from a stage: the stage has no sources of its own.
# The container runs as the invoking user so nothing comes back
# root-owned, and a named volume keeps the Go and linter caches between
# runs instead of recompiling the world every time.
- >-
docker buildx build -f hack/dev.Dockerfile
--build-arg GO_VERSION="$(sed -n 's/^go //p' go.mod)"
--target fmt --load --tag nvidia-gpu-exporter-tools:local .
- "{{.FMT}} sh -c 'go mod tidy && go fix ./...'"
# unfixable findings are reported by lint, not by fmt
- "{{.FMT}} golangci-lint run --fix --issues-exit-code 0 ./..."
- "{{.FMT}} golangci-lint fmt ./..."
# tracked files only: a bare find would also rewrite scratch directories
# and any other worktree checked out under this one
- git ls-files '*.sh' | xargs {{.FMT}} shfmt -w -i 2 -ci -sr
vars:
FMT: >-
docker run --rm -u "$(id -u):$(id -g)"
-e GOFLAGS=-mod=mod -e HOME=/tmp
-e GOCACHE=/tmp/go-build -e GOMODCACHE=/tmp/go-mod
-e GOLANGCI_LINT_CACHE=/tmp/golangci-lint
-v nvidia-gpu-exporter-fmt-cache:/tmp
-v "$PWD":/src -w /src nvidia-gpu-exporter-tools:local
lint:
desc: lint everything (code, docs, scripts, dashboards, release config)
cmds:
- task: lint:go
- task: lint:assets
- task: lint:dashboard
- task: lint:release
lint:go:
desc: lint go code and module tidiness
cmds:
- task: stage
vars: {TARGET: lint-go-mod-tidy}
- task: stage
vars: {TARGET: lint-golangci-lint}
# never runs without a GPU, but it must keep compiling
- task: stage
vars: {TARGET: lint-gpu-tagged-test}
lint:assets:
desc: lint markdown and shell scripts
cmds:
- task: stage
vars: {TARGET: lint-markdown}
- task: stage
vars: {TARGET: lint-shell}
lint:dashboard:
desc: lint the Grafana dashboards against grafana.com best practices
cmds:
- task: stage
vars: {TARGET: lint-dashboard}
lint:release:
desc: validate the release configuration
cmds:
- task: stage
vars: {TARGET: lint-goreleaser}
test:
desc: run the unit and integration tests
cmds:
- task: stage
vars: {TARGET: unit-tests}
# `task test` already replays every fuzz target's seed corpus, which is where
# the regression value sits. This drives the actual search instead, one target
# at a time because -fuzz only ever fuzzes one.
#
# It bind-mounts the working tree the way fmt does, rather than running as a
# stage: a discovered failure is written to testdata/fuzz/ and has to survive
# into the tree, which a stage that copies the sources cannot do. The cache
# volume also keeps the generated corpus between runs, so successive sessions
# build on each other's coverage instead of starting cold.
test:fuzz:
desc: 'search for new fuzz failures (FUZZTIME=30s per target)'
vars:
FUZZTIME: '{{.FUZZTIME | default "30s"}}'
FUZZ: >-
docker run --rm -u "$(id -u):$(id -g)"
-e GOFLAGS=-mod=mod -e HOME=/tmp
-e GOCACHE=/tmp/go-build -e GOMODCACHE=/tmp/go-mod
-v nvidia-gpu-exporter-fmt-cache:/tmp
-v "$PWD":/src -w /src nvidia-gpu-exporter-tools:local
cmds:
- >-
docker buildx build -f hack/dev.Dockerfile
--build-arg GO_VERSION="$(sed -n 's/^go //p' go.mod)"
--target fmt --load --tag nvidia-gpu-exporter-tools:local .
- |
set -eu
for pkg in $({{.FUZZ}} go list ./...); do
# a listing failure means the package does not compile, which has to
# surface rather than read as "no fuzz targets here"
listed="$({{.FUZZ}} go test -list 'Fuzz' "$pkg")"
for target in $(printf '%s\n' "$listed" | grep '^Fuzz' || true); do
echo "==> $pkg $target ({{.FUZZTIME}})"
{{.FUZZ}} go test "$pkg" -run '^$' -fuzz "^${target}\$" -fuzztime '{{.FUZZTIME}}'
done
done
# The dashboard images in the README are generated, not screen-captured by
# hand. Every run photographs live demo data, so the pictures differ each
# time even when nothing changed: refresh them when a dashboard changes, and
# read the image diff.
screenshots:
desc: regenerate the dashboard images in docs/grafana (needs the dev stack)
cmds:
- ./hack/compose/screenshots.sh
chart:docs:
desc: regenerate the chart README from the values.yaml comments
cmds:
# renovate: depName=jnorwood/helm-docs datasource=docker
- docker run --rm -u "$(id -u):$(id -g)" -v "$PWD":/helm-docs jnorwood/helm-docs:v1.14.2
# builds one check stage; every check goes through here so the build
# invocation exists in exactly one place
stage:
internal: true
cmds:
- >-
docker buildx build -f hack/dev.Dockerfile
--build-arg GO_VERSION="$(sed -n 's/^go //p' go.mod)"
--target {{.TARGET}} .
release:
desc: release
vars:
NEXT:
# renovate: depName=caarlos0/svu datasource=docker
# run from the primary checkout: a linked worktree's .git points at a
# common directory outside this mount
sh: docker run --rm -v "$PWD":/src -w /src caarlos0/svu:3.4.1 next
cmds:
- git tag -a {{.NEXT}} -m "{{.NEXT}}"
- echo {{.NEXT}}
- git push origin {{.NEXT}}