Repository navigation
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
363 lines (326 loc) · 11.3 KB
/
Copy pathTaskfile.yaml
File metadata and controls
363 lines (326 loc) · 11.3 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# SPDX-License-Identifier: Apache-2.0
version: 3
output: prefixed
vars:
# license-eye (github.com/apache/skywalking-eyes) version for lint:license and
# license:fix; the only place it is pinned. CI runs `task lint:license`.
LICENSE_EYE_VERSION: v0.9.0
PROJECT_NAME: appcli
ARCH: [amd64, arm64]
OS: [linux, darwin, windows]
LDFLAGS: "-w -s"
# LDFLAGS: ""
env:
CGO_ENABLED: 0
APP_DAEMON_LOG_LEVEL: trace
APP_DAEMON_LOG_INCLUDE_CALLER: false
tasks:
default:
desc: "Clean, lint, and build all Go programs"
cmds:
- task: clean
- task: vendor
- task: lint
- task: build
clean:
desc: "Remove all generated files"
cmds:
- task: clean:dist
- task: clean:bin
- task: clean:test
clean:dist:
desc: "Remove all distribution files"
internal: true
cmds:
- rm -rvf dist
clean:bin:
desc: "Remove all binary files"
internal: true
cmds:
- rm -rvf bin
clean:test:
desc: "Remove all test files"
internal: true
cmds:
- rm -vf cover.out
clean:cache:
desc: "Remove all Go build caches"
cmds:
- go clean -cache -testcache
lint:
desc: "Run linters on all Go files and check SPDX license headers"
cmds:
- task: lint:format
- task: lint:vet
- task: lint:golangci
- task: lint:license
lint:format:
internal: true
desc: "Run go fmt on all Go files"
cmds:
- go fmt ./...
lint:vet:
internal: true
desc: "Run go vet on all Go files"
cmds:
- go vet -atomic -defers -assign -bools -buildtag -framepointer -lostcancel -loopclosure -nilfunc -shift -stdmethods -stringintconv -structtag ./...
lint:golangci:
internal: true
desc: "Run golangci-lint with the project's .golangci.yml"
cmds:
- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2
- "$(go env GOPATH)/bin/golangci-lint run --timeout=5m ./..."
lint:license:
desc: "Check SPDX license headers and Helm template header style (CI runs this task)"
cmds:
- task: tool:license-eye
- "$(go env GOPATH)/bin/license-eye -c .licenserc.yaml header check"
- cmd: |
lb='{'
want="$lb$lb- /* SPDX-License-Identifier: Apache-2.0 */ -}}"
bad=$(find charts -path '*/templates/*' -type f ! -exec sh -c 'head -n 1 "$1" | grep -qF -- "$2"' _ {} "$want" \; -print 2>/dev/null || true)
if [ -n "$bad" ]; then echo "Helm templates must start with $want:"; echo "$bad"; exit 1; fi
license:fix:
desc: "Add missing SPDX license headers (Helm templates need a manual Go-template comment)"
cmds:
- task: tool:license-eye
- "$(go env GOPATH)/bin/license-eye -c .licenserc.yaml header fix"
tool:license-eye:
internal: true
desc: "Install license-eye {{.LICENSE_EYE_VERSION}}"
cmds:
- go install github.com/apache/skywalking-eyes/cmd/license-eye@{{.LICENSE_EYE_VERSION}}
vendor:
desc: "Update Go modules and vendor directory"
cmds:
- cmd: echo "Tidying up Go modules"
silent: true
- cmd: go mod tidy
silent: true
- cmd: echo "Updating vendor directory"
silent: true
- cmd: go mod vendor
silent: true
generate:
desc: "Run all go:generate directives (version metadata, etc.)"
cmds:
- cmd: go generate ./...
silent: true
sbom:
desc: "Generate CycloneDX SBOMs (bin/sbom.json + bin/sbom.xml) for the CLI module and GPG-sign each output"
deps:
- vendor
cmds:
- cmd: |
set -e
mkdir -p bin
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.12.0
"$(go env GOPATH)/bin/cyclonedx-gomod" app -json=true -licenses -output bin/sbom.json -main cmd/appcli
"$(go env GOPATH)/bin/cyclonedx-gomod" app -licenses -output bin/sbom.xml -main cmd/appcli
# SBOMs are themselves manifests; sign them directly so consumers can verify the
# dependency listing offline. Signing is best-effort locally — the workflow
# imports a GPG key before running this task.
if gpg --list-secret-keys --with-colons 2>/dev/null | grep -q '^sec'; then
gpg --batch --yes --detach-sign --armor --output bin/sbom.json.asc bin/sbom.json
gpg --batch --yes --detach-sign --armor --output bin/sbom.xml.asc bin/sbom.xml
else
echo "warning: no GPG signing key configured; skipping SBOM signature" >&2
fi
silent: true
hash:
desc: "Generate per-binary SHA-256 hashes (writes bin/<binary>.sha256 per binary)"
dir: bin
cmds:
- cmd: |
set -e
rm -f *.sha256
found=0
for f in {{.PROJECT_NAME}}-*; do
case "$f" in
*.sha256|*.asc) continue ;;
esac
[ -f "$f" ] || continue
shasum -a 256 "$f" > "${f}.sha256"
cat "${f}.sha256"
found=1
done
if [ "$found" -eq 0 ]; then
echo "no binaries matching '{{.PROJECT_NAME}}-*' found in bin/ — run 'task build' first" >&2
exit 1
fi
silent: true
sign:
desc: "GPG-sign each SHA256 hash file (writes bin/<binary>.sha256.asc per binary). Depends on task hash. Binaries themselves are NOT signed — the signed hash transitively pins the binary."
deps:
- hash
dir: bin
cmds:
- cmd: |
set -e
rm -f *.asc
found=0
for hash_file in {{.PROJECT_NAME}}-*.sha256; do
[ -f "$hash_file" ] || continue
gpg --batch --yes --detach-sign --armor --output "${hash_file}.asc" "$hash_file"
found=1
done
if [ "$found" -eq 0 ]; then
echo "no .sha256 files matching '{{.PROJECT_NAME}}-*.sha256' found in bin/ — run 'task hash' first" >&2
exit 1
fi
silent: true
build:
desc: "Build all Go programs"
cmds:
- task: build:cli:all
build:cli:all:
internal: true
desc: "Build the {{.PROJECT_NAME}} CLI"
cmds:
- task: build:cli:all:os
build:cli:all:os:
internal: true
desc: "Build the {{.PROJECT_NAME}} CLI for all configured operating systems"
cmds:
- for:
var: OS
task: build:cli:all:arch
vars:
GOOS: "{{.ITEM}}"
build:cli:all:arch:
internal: true
desc: "Build the {{.PROJECT_NAME}} CLI for all configured architectures"
cmds:
- for:
var: ARCH
task: build:cli
vars:
GOOS: "{{.GOOS}}"
GOARCH: "{{.ITEM}}"
build:cli:
internal: true
desc: "Build the {{.PROJECT_NAME}} CLI for the given OS/arch"
env:
GOOS: "{{coalesce .GOOS OS}}"
GOARCH: "{{coalesce .GOARCH ARCH}}"
cmds:
- cmd: echo "Building {{.PROJECT_NAME}} for ${GOOS}/${GOARCH}"
silent: true
- task: generate
- cmd: go build -o bin/{{.PROJECT_NAME}}-${GOOS}-${GOARCH} -ldflags="{{.LDFLAGS}}" -trimpath ./cmd/appcli
silent: true
- cmd: chmod +x bin/{{.PROJECT_NAME}}-${GOOS}-${GOARCH}
silent: true
build:container:
desc: "Build the {{.PROJECT_NAME}} container"
deps:
- task: build:cli
vars:
GOOS: linux
cmds:
- docker buildx build --load -t {{.PROJECT_NAME}}:latest .
test:
desc: "Run all tests"
env:
CGO_ENABLED: 1
cmds:
- go test -parallel 4 -cover -coverprofile cover.out -race -v ./...
run:
desc: "Run the {{.PROJECT_NAME}} programs (defaults to the serve subcommand)"
cmds:
- task: run:serve
run:serve:
desc: "Run the {{.PROJECT_NAME}} daemon example via the serve subcommand"
env:
GOOS: "{{OS}}"
GOARCH: "{{ARCH}}"
cmds:
- task: vendor
- task: build:cli
- cmd: echo "Running {{.PROJECT_NAME}} serve for ${GOOS}/${GOARCH}"
silent: true
- cmd: ./bin/{{.PROJECT_NAME}}-${GOOS}-${GOARCH} serve
silent: true
run:copy:
desc: "Run the {{.PROJECT_NAME}} one-shot example: copies README.md to /tmp/copy.md"
env:
GOOS: "{{OS}}"
GOARCH: "{{ARCH}}"
cmds:
- task: vendor
- task: build:cli
- cmd: echo "Running {{.PROJECT_NAME}} copy for ${GOOS}/${GOARCH}"
silent: true
- cmd: ./bin/{{.PROJECT_NAME}}-${GOOS}-${GOARCH} copy README.md /tmp/copy.md
silent: true
run:container:
desc: "Run the {{.PROJECT_NAME}} container (prints --help)"
deps:
- build:container
cmds:
- docker run --rm -it {{.PROJECT_NAME}}:latest --help
# ---------------------------------------------------------------------------
# Multi-arch container publishing. Used by the release workflow's publishCmd.
# ---------------------------------------------------------------------------
container:registry:
internal: true
desc: "Print the canonical container image registry/repository path"
cmds:
- cmd: printf 'ghcr.io/servercurio/go-cli-starter'
silent: true
container:build:multiarch:
desc: "Build and push a multi-arch (linux/amd64,linux/arm64) container image to GHCR. Reads VERSION from internal/version/version.txt; release workflow runs `docker login ghcr.io` first."
deps:
- task: build:cli
vars:
GOOS: linux
GOARCH: amd64
- task: build:cli
vars:
GOOS: linux
GOARCH: arm64
cmds:
- cmd: |
set -e
mkdir -p bin
VERSION="$(cat internal/version/version.txt | tr -d '[:space:]')"
if [ -z "$VERSION" ]; then
echo "internal/version/version.txt is empty — refusing to push an unversioned image" >&2
exit 1
fi
REPO="ghcr.io/servercurio/go-cli-starter"
docker buildx build \
--platform linux/amd64,linux/arm64 \
--provenance=true \
--sbom=false \
--push \
-t "${REPO}:${VERSION}" \
-t "${REPO}:latest" \
-f Dockerfile .
# Capture the manifest-list digest for downstream attestation steps.
docker buildx imagetools inspect "${REPO}:${VERSION}" --format '{{`{{ .Manifest.Digest }}`}}' > bin/container-image.digest
echo "container image: ${REPO}:${VERSION}@$(cat bin/container-image.digest)"
silent: true
container:sbom:
desc: "Generate CycloneDX SBOMs (bin/container-sbom.{json,xml}) for the published container image using syft"
cmds:
- cmd: |
set -e
if ! command -v syft >/dev/null 2>&1; then
echo "syft not found on PATH — install via release tarball (https://github.com/anchore/syft/releases) before running this task" >&2
exit 1
fi
VERSION="$(cat internal/version/version.txt | tr -d '[:space:]')"
REPO="ghcr.io/servercurio/go-cli-starter"
syft "${REPO}:${VERSION}" -o cyclonedx-json=bin/container-sbom.json -o cyclonedx-xml=bin/container-sbom.xml
silent: true
container:sbom:sign:
desc: "GPG-sign the container SBOM files (bin/container-sbom.{json,xml}.asc)"
cmds:
- cmd: |
set -e
for f in bin/container-sbom.json bin/container-sbom.xml; do
[ -f "$f" ] || { echo "$f missing — run 'task container:sbom' first" >&2; exit 1; }
gpg --batch --yes --detach-sign --armor --output "${f}.asc" "$f"
done
silent: true