-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.dist.yml
More file actions
197 lines (170 loc) · 6.23 KB
/
Copy pathTaskfile.dist.yml
File metadata and controls
197 lines (170 loc) · 6.23 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
# https://taskfile.dev
version: "3"
includes:
demo: ./taskfiles/Taskfile.demo.yml
docs: ./taskfiles/Taskfile.docs.yml
md: ./taskfiles/Taskfile.md.yml
lint:
taskfile: ./taskfiles/Taskfile.lint.yml
flatten: true
silent: true
vars:
# The leading v is stripped so a local build and a release agree on how a
# version is spelled: goreleaser injects {{ .Version }}, and the release
# workflow hands the images metadata-action's version output — both of which
# are the tag without it. The fallback is captured before the strip so that a
# tree git cannot describe at all yields "dev" rather than an empty version.
LABELSYNC_VERSION:
sh: described=$(git describe --tags --always --dirty="-dev" 2>/dev/null || echo "dev"); echo "${described#v}"
# env:
# BUILDKIT_PROGRESS: plain
tasks:
dc:
desc: Run a docker compose command
internal: true
vars:
FIXUID:
sh: echo ${FIXUID:-$(id -u)}
FIXGID:
sh: echo ${FIXGID:-$(id -g)}
cmds:
- FIXUID={{ .FIXUID }} FIXGID={{ .FIXGID }} docker compose {{ .SUB_CMD }} {{ .CLI_ARGS }}
dc:build:
desc: Run docker compose build
cmds:
- task: dc
vars:
SUB_CMD: --profile=* build
dc:run:*:
desc: Run a one-off docker compose command
vars:
SERVICE: '{{ index .MATCH 0 }}'
RUN_FLAGS: '{{ .RUN_FLAGS | default "" }}'
USER_FLAG: '{{ (ne (.NON_ROOT | default "true") "false") | ternary " --user $(id -u):$(id -g)" "" }}'
COMPOSE_SERVICES:
sh: COMPOSE_PROFILES="*" docker compose config --services
cmds:
- task: dc
vars:
SUB_CMD: 'run --rm {{ .RUN_FLAGS }} {{ .USER_FLAG }} {{ .SERVICE }} {{ .SUB_CMD }}'
CLI_ARGS: '{{ .CLI_ARGS }}'
requires:
vars:
- name: SERVICE
enum:
ref: .COMPOSE_SERVICES | splitLines | compact
dc:shell:
desc: Shell into a docker compose service
cmds:
- task: dc
vars:
SUB_CMD: "run --tty --rm go-builder /bin/bash"
CLI_ARGS: "{{.CLI_ARGS}}"
build:
desc: Build Labelsync
cmds:
- task: lint
- >-
docker buildx bake --file compose.yml
--set "go-binary.output=type=local,dest=."
--set "go-binary.args.GOARCH={{ARCH}}"
--set "go-binary.args.GOOS={{OS}}"
--set "go-binary.args.LABELSYNC_VERSION={{.LABELSYNC_VERSION}}"
go-binary
images:
desc: Build both container images locally, tagged :dev
summary: |
Builds the two images the release workflow publishes, from the same
Dockerfile stages, and loads them into the local docker:
ghcr.io/specsnl/labelsync:dev the scratch image, `binary` stage
ghcr.io/specsnl/labelsync/debian:dev the debian image, `debian` stage
`task release:dry-run` cannot do this: the goreleaser service has no
docker socket, and the images do not go through goreleaser at all.
Host platform only. --load writes into the docker image store, which holds
one platform per tag, so the multi-platform manifest list is the one part
of the published result that only a real release produces.
cmds:
- task: image
vars: { TARGET: binary, IMAGE: "ghcr.io/specsnl/labelsync" }
- task: image
vars: { TARGET: debian, IMAGE: "ghcr.io/specsnl/labelsync/debian" }
- docker run --rm ghcr.io/specsnl/labelsync:dev version
- docker run --rm ghcr.io/specsnl/labelsync/debian:dev version
image:
desc: Build one container image locally
internal: true
cmds:
- >-
docker buildx build .
--target {{ .TARGET }}
--tag {{ .IMAGE }}:dev
--build-arg LABELSYNC_VERSION={{ .LABELSYNC_VERSION }}
--load
requires:
vars: [TARGET, IMAGE]
tidy:check:
desc: Check that go.mod and go.sum are tidy
summary: |
Fails, without writing anything, when `go mod tidy` would change go.mod or go.sum.
Run `task tidy` to apply what it reports.
cmds:
- task: dc:run:go-builder
vars:
SUB_CMD: "go mod tidy -diff"
tidy:
desc: Run go mod tidy
cmds:
- task: dc:run:go-builder
vars:
SUB_CMD: "go mod tidy"
test:
desc: Run go tests
cmds:
- task: dc:run:go-builder
vars:
SUB_CMD: "go test -race -tags=integration ./..."
test:update:
desc: Rewrite the golden files from what the tests produce now
summary: |
Runs the tests with -update in every package that defines the flag, which
rewrites that package's testdata/*.golden files from the current output.
Then read the diff. A golden that changed is either the change you meant
to make or a regression, and the file is the only thing that says which.
The package list is discovered rather than hardcoded: any test file that
declares an -update flag puts its package in. Nothing to remember when a
new golden suite lands.
cmds:
- task: dc:run:go-builder
vars:
# Single-quoted so the command substitution runs in the container
# rather than on the host. -F makes the pattern a literal string, so
# the ( and the . in flag.Bool("update" need no regex escaping; the
# \" survive because bash leaves a backslash alone inside "..." unless
# it precedes $ ` " \ or a newline.
SUB_CMD: >-
bash -c 'go test $(grep -rlF --include="*_test.go" "flag.Bool(\"update\"" . | xargs -n1 dirname | sort -u) -update'
checkall:
desc: Run every check — the tidy check, golangci-lint, the Go tests, and markdownlint
summary: |
The full local check sequence: tidy:check, lint, test, md:check.
Every step reports; none of them writes. Run this before opening a pull request.
cmds:
- task: tidy:check
- task: lint
- task: test
- task: md:check
release:dry-run:
desc: Build a snapshot release locally without publishing
cmds:
- task: dc:run:goreleaser
vars:
SUB_CMD: release --snapshot --clean
cleanup:
desc: Cleanup workspace
summary: |
Cleanup of almost all gitignored files, untracked files and development containers.
The following files/dirs are excluded: none
cmds:
- git clean
-xd
--force