Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
160 lines (138 loc) · 5.24 KB
/
Copy pathTaskfile.yml
File metadata and controls
160 lines (138 loc) · 5.24 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
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'
# Every check is a task, and CI runs these tasks inside the devcontainer's `ci` stage. So a red CI
# job reproduces locally with the same command, and changing what CI checks means editing this file.
# Local-only overrides, gitignored.
dotenv: ['.env']
run: once
set:
- errexit
- nounset
- pipefail
vars:
GOLANGCI_LINT: '{{.GOLANGCI_LINT | default "golangci-lint"}}'
BIN: bin/settings-image
# ONE version, from release-please's manifest, never from a tag (internal/buildinfo).
VERSION:
sh: jq -r '."."' .release-please-manifest.json
GIT_COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo unknown
GIT_DIRTY:
sh: test -z "$(git status --porcelain 2>/dev/null)" && echo 0 || echo 1
LDFLAGS: >-
-s -w
-X github.com/ConfigButler/settings-image/internal/buildinfo.version={{.VERSION}}
-X github.com/ConfigButler/settings-image/internal/buildinfo.gitCommit={{.GIT_COMMIT}}
-X github.com/ConfigButler/settings-image/internal/buildinfo.gitDirty={{.GIT_DIRTY}}
tasks:
default:
desc: List available tasks
cmds:
- task --list
silent: true
fmt:
desc: Format Go code (golangci-lint's formatters, the same ones lint checks)
cmds:
- '{{.GOLANGCI_LINT}} fmt'
vet:
desc: Run go vet
cmds:
- go vet ./...
test:
desc: Run the unit tests
deps: [vet]
cmds:
- go test ./... -coverprofile cover.out
build:
desc: Build the CLI into bin/, with the build metadata baked in
cmds:
- CGO_ENABLED=0 go build -trimpath -ldflags '{{.LDFLAGS}} -X github.com/ConfigButler/settings-image/internal/buildinfo.buildDate={{now | date "2006-01-02T15:04:05Z07:00"}}' -o {{.BIN}} ./cmd/settings-image
- ./{{.BIN}} version
dist:
desc: Cross-build the release binaries into dist/, with a sha256sums file (release.yml attaches them)
vars:
# The commit's time, not the clock's: two builds of one commit give the same bytes.
COMMIT_DATE:
sh: git log -1 --format=%cI 2>/dev/null || echo unknown
TARGETS: linux/amd64 linux/arm64 darwin/arm64
cmds:
- rm -rf dist && mkdir -p dist
- for: { var: TARGETS, split: ' ' }
cmd: >-
CGO_ENABLED=0 GOOS={{splitList "/" .ITEM | first}} GOARCH={{splitList "/" .ITEM | last}}
go build -trimpath -ldflags '{{.LDFLAGS}} -X github.com/ConfigButler/settings-image/internal/buildinfo.buildDate={{.COMMIT_DATE}}'
-o dist/settings-image_{{splitList "/" .ITEM | first}}_{{splitList "/" .ITEM | last}} ./cmd/settings-image
- cd dist && sha256sum settings-image_* > settings-image.sha256sums
# The binary must say which release it is: a broken ldflags path would ship "dev".
- ./dist/settings-image_linux_amd64 version | tee /dev/stderr | grep -qF 'version={{.VERSION}} '
lint:
desc: Run every linter (Go, go.mod, Dockerfiles, workflows, markdown)
deps:
- lint-golang
- lint-gomod
- lint-dockerfiles
- lint-actions
- lint-markdown
lint-golang:
desc: Run golangci-lint
sources:
# Not '**/*.go': that walks the gitignored external/ clones too, where a symlink loop
# (sealed-secrets' kube-libsonnet examples/*/lib -> ../../) grows until the OOM killer stops it.
- 'cmd/**/*.go'
- 'internal/**/*.go'
- 'pkg/**/*.go'
- .golangci.yml
- go.mod
- go.sum
cmds:
- '{{.GOLANGCI_LINT}} run'
lint-gomod:
desc: Check that go.mod and go.sum are tidy
# `-diff` reports what tidying would change and exits non-zero, without writing anything.
cmds:
- go mod tidy -diff
lint-dockerfiles:
desc: Lint Dockerfiles with hadolint
sources:
- .devcontainer/Dockerfile
- .hadolint.yaml
cmds:
- hadolint .devcontainer/Dockerfile
lint-actions:
desc: Lint GitHub Actions workflows with actionlint (and shellcheck, when installed)
sources:
- .github/workflows/*.yml
- action.yml
cmds:
- actionlint
- test/lint/action-expressions.sh action.yml
lint-markdown:
desc: Markdown structure (markdownlint-cli2), over every tracked file
# An explicit file list from git, never a recursive glob: it keeps gitignored trees out.
cmds:
- git ls-files -z '*.md' | xargs -0 -r markdownlint-cli2
cluster:
desc: Create (or reuse) the k3d cluster and registry for the mount test
cmds:
- test/mount/cluster.sh
cluster-down:
desc: Delete the k3d cluster and its registry
cmds:
- k3d cluster delete settings-image
- k3d registry delete k3d-settings-image-registry
test-mount:
desc: Push the examples and edge cases, mount them as image volumes in a pod, and check every file
deps: [cluster]
cmds:
- CGO_ENABLED=0 go build -o {{.BIN}} ./cmd/settings-image
- test/mount/run.sh
compare:
desc: Build one folder with every folder-to-registry tool and compare digests, shape and mounts
# This checkout's settings-image, ahead of any installed one: the comparison is of this code.
cmds:
- CGO_ENABLED=0 go build -o {{.BIN}} ./cmd/settings-image
- PATH="$PWD/bin:$PATH" compare/run.sh {{.CLI_ARGS}}
clean:
desc: Remove build output
cmds:
- rm -rf bin dist cover.out .task