-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTaskfile.yml
More file actions
549 lines (487 loc) · 15.6 KB
/
Taskfile.yml
File metadata and controls
549 lines (487 loc) · 15.6 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# Commands to build, run, and package the app
#
# See https://taskfile.dev/ for instructions on how to use Taskfile.yml
#
# Run `task` to see the list of tasks
version: '3'
vars:
BINARY_NAME: photofield
DOCKER_REPO: ghcr.io/smilyorg/photofield
DOCKER_REPO_LOCAL: localhost:5000/photofield
PPROF_URL: http://localhost:8080/debug/pprof
BUILD_OS_ARCH:
- darwin/amd64
- darwin/arm64
- linux/386
- linux/amd64
- linux/arm
- linux/arm64
- linux/loong64
- linux/ppc64le
- linux/riscv64
- linux/s390x
- openbsd/amd64
- openbsd/arm64
- windows/386
- windows/amd64
- windows/arm64
DOCKER_ARCH:
- linux/amd64
- linux/arm64
DOCKER_ANNOTATIONS: >-
--annotation 'index:org.opencontainers.image.source=https://github.com/smilyorg/photofield'
--annotation 'index:org.opencontainers.image.description=A non-invasive local photo viewer with a focus on speed and simplicity'
--annotation 'index:org.opencontainers.image.licenses=MIT'
VERSION:
sh: git describe --tags --match "v*" --always --dirty
tasks:
default:
cmds:
- task --list
- echo ""
- echo "Common tasks:"
- "echo ' task dev: Run the API and UI in watch mode'"
- "echo ' task watch: Run the API in watch mode'"
- "echo ' task ui: Run the UI in watch mode'"
- "echo ' task docs: Run the docs frontend in development mode'"
- "echo ' task e2e: Run end-to-end tests in watch mode'"
- "echo ' task release:local: Build, package, and create a local Docker image'"
silent: true
commit:analyze:
desc: Analyze git state for LLM commit assistant (current branch and staged changes)
cmds:
- echo "Current branch:" $(git branch --show-current)
- echo ""
- echo "=== STAGED FILES ==="
- git diff --cached --stat || echo "No staged changes"
- echo ""
- echo "=== STAGED CHANGES ==="
- git diff --cached || echo "No staged changes"
silent: true
added:
desc: Create a new changelog entry for added features
cmds: [changie new -k Added -e]
deprecated:
desc: Create a new changelog entry for deprecated features
cmds: [changie new -k Deprecated -e]
removed:
desc: Create a new changelog entry for removed features
cmds: [changie new -k Removed -e]
fixed:
desc: Create a new changelog entry for bug fixes
cmds: [changie new -k Fixed -e]
security:
desc: Create a new changelog entry for security updates
cmds: [changie new -k Security -e]
breaking:
desc: Create a new changelog entry for breaking changes
cmds: [changie new -k 'Breaking Changes' -e]
release:
desc: Create a new release (batch changelog, tag, and prepare for push)
cmds:
- cmd: git diff-index --quiet HEAD -- || { echo "Working directory is not clean. Please commit or stash your changes."; exit 1; }
silent: true
- cmd: git branch --show-current | grep -q '^main$' || { echo "Must be on main branch to release."; exit 1; }
silent: true
- changie batch auto
- code --wait .changes/$(changie latest).md
- changie merge
- git add CHANGELOG.md .changes
- git commit -m "Release $(changie latest)"
- git tag -a $(changie latest) -m "Release $(changie latest)"
- cmd: |
echo ""
echo "✓ Release $(changie latest) created and tagged"
echo ""
echo "Next steps:"
echo " 1. Review with git show HEAD"
echo " 2. Push with task release:push"
echo " 3. Or undo with task release:undo"
silent: true
release:push:
desc: Push the release commit and tag to origin
cmds:
- git push
- git push --tags
- cmd: |
echo ""
echo "✓ Release pushed to origin"
echo " GitHub Actions should now build and publish the release"
silent: true
release:undo:
desc: Undo the last release (removes commit and tag locally)
cmds:
- cmd: git diff-index --quiet HEAD -- || { echo "Working directory is not clean. Cannot undo."; exit 1; }
silent: true
- git tag -d $(changie latest)
- git reset --hard HEAD~1
- cmd: |
echo ""
echo "✓ Release undone (commit and tag removed)"
echo " Note - If you already pushed, you'll need to force push to remove from remote"
silent: true
release:version:
desc: Display the version of the latest release
cmds:
- echo {{ .VERSION }}
silent: true
release:changelog:
desc: Display the changelog for the latest release
cmds:
- tail -n +2 .changes/$(changie latest).md
silent: true
release:title:
desc: Get the title of the latest release
vars:
CHANGELOG_HEAD:
sh: head -n 1 .changes/$(changie latest).md
cmds:
- echo "{{ regexReplaceAll "## \\[(.*?)\\] - (.*?)( - )?(.*)" .CHANGELOG_HEAD "${1} - ${4}" }}"
silent: true
package:
desc: Build and package the application for all platforms
cmds:
- task: build:deps
- task: build:release:all
- task: archive:all
- task: checksums
release:local:
desc: Build, package, and create a local Docker image
cmds:
- task: package
- task: docker
release:local:multiarch:
desc: Build and create a multi-architecture local Docker image
cmds:
- task: package
- task: docker:multiarch:push:local
check:
cmds:
- task: tidy
- git diff --exit-code go.mod go.sum
- task: gen
- git diff --exit-code
tidy: go mod tidy
gen: go generate -x
struct:
desc: Analyze struct layout for a given struct name
vars:
COMMIT: a36776054d7900fa9b0c2eb334dc64b55aa0723c
cmds:
- go run honnef.co/go/tools/cmd/structlayout@{{.COMMIT}} -json {{.CLI_ARGS}} | go run honnef.co/go/tools/cmd/structlayout-pretty@{{.COMMIT}}
deps:
deps:
- assets
- build:deps
build:deps:
desc: Build UI and docs frontends
deps:
- build:docs
- build:ui
build:docs:
desc: Build the docs frontend
dir: docs
cmds:
- npm install
- npm run docs:build
build:ui:
desc: Build the UI frontend
dir: ui
cmds:
- npm install
- npm run build -- --clearScreen=false -l warn
build:
desc: Build the API
sources:
- '**/*.go'
- 'go.mod'
- '**/*.yaml'
- '**/*.syso'
cmds:
- go build
db:
desc: Run database migrations using "golang-migrate"
cmds:
- migrate -database sqlite://data/photofield.cache.db -path db/migrations {{.CLI_ARGS}}
db:add:
desc: Add a new database migration
cmds:
- migrate create -ext sql -dir db/migrations -seq {{.CLI_ARGS}}
dbt:
desc: Run thumbs database migrations
cmds:
- migrate -database sqlite://data/photofield.thumbs.db -path db/migrations-thumbs {{.CLI_ARGS}}
dbt:add:
desc: Add a new thumbs database migration
cmds:
- migrate create -ext sql -dir db/migrations-thumbs -seq {{.CLI_ARGS}}
assets:dir:
dir: data/geo
internal: true
assets:
desc: Download optional reverse geocoding assets
deps: [assets:dir]
vars:
GPKG_FILE:
sh: grep -o 'data/geo/.*gpkg' embed-geo.go | cut -d / -f 3
GPKG_VER:
sh: grep -e '// tinygpkg-data release:' embed-geo.go | cut -d ' ' -f 4
generates:
- "data/geo/{{.GPKG_FILE}}"
status:
- test -f "data/geo/{{.GPKG_FILE}}"
cmds:
- silent: true
cmd: |
gpkg_path="data/geo/{{ .GPKG_FILE }}"
echo "downloading tinygpkg-data/{{ .GPKG_VER }}/{{ .GPKG_FILE }}"
wget -q -O "$gpkg_path" https://github.com/SmilyOrg/tinygpkg-data/releases/download/{{ .GPKG_VER }}/{{ .GPKG_FILE }}
echo "downloaded to $PWD/$gpkg_path"
dev:
desc: Run the API and UI in watch mode
deps:
- watch
- ui
ui:
desc: Run the UI in watch mode
dir: ui
cmds:
- npm run dev
watch:
desc: Run the API in watch mode
cmds:
- watchexec --exts go -r task build:run
build:run:
desc: Build and run the API
cmds:
- task: build
- task: run
run:dir:
dir: data
internal: true
run:
desc: Run the built API
deps: [run:dir]
cmds:
- ./photofield
run:embed:
desc: Run the built API with embedded UI and docs
deps: [build:deps]
env: { PHOTOFIELD_API_PREFIX: /api }
cmds:
- go build -tags embedui,embeddocs
- ./photofield
run:ui:
desc: Run the built API with embedded UI
deps: [build:ui]
env: { PHOTOFIELD_API_PREFIX: /api }
cmds:
- go build -tags embedui
- ./photofield
run:geo:
desc: Run the built API with embedded reverse geocoding assets
deps: [assets]
env: { PHOTOFIELD_API_PREFIX: /api }
cmds:
- go build -tags embedgeo
- ./photofield
run:docker:
desc: Build & Run in Docker
cmds:
- task: build:deps
- task: build:release
- task: docker
- docker run --rm -p 8080:8080 -v $PWD/testdata/thumbs/:/app/thumbs {{.DOCKER_REPO}}:{{ .VERSION }}
bench:
desc: Run benchmarks for a specified collection
cmds:
- ./photofield -bench -test.benchtime 1s -test.count 6 -bench.collection {{.CLI_ARGS}}
grafana:export:
desc: Export Grafana configuration
cmds:
- cmd: hamara export --host=localhost:9091 --key=$GRAFANA_API_KEY > docker/grafana/provisioning/datasources/default.yaml
prof:cpu:
desc: Profile CPU usage
vars:
SECONDS: '{{default "10" .CLI_ARGS}}'
cmds:
- "go tool pprof -http=: {{ .PPROF_URL }}/profile?seconds={{.SECONDS}}"
prof:heap:
desc: Profile heap usage
cmds:
- "go tool pprof -http=: {{ .PPROF_URL }}/heap"
prof:reload:
desc: Profile reload performance
cmds:
- "go test -benchmem -benchtime 10s '-run=^$' -bench '^BenchmarkReload$' photofield"
prof:trace:
desc: Generate a trace for profiling
cmds:
- curl -s -o trace.out {{ .PPROF_URL }}/trace?seconds={{ default "10" .CLI_ARGS }}
monitor:
desc: Run monitoring services
cmds:
- docker compose up prometheus grafana pyroscope
test:reload:
desc: Run reload leak tests
cmds:
- mkdir -p profiles/
- go test -v '-run=^TestReloadLeaks$' photofield
- go tool pprof -http ':' -diff_base profiles/reload-before.pprof profiles/reload-after.pprof
test:
desc: Run all go tests
cmds:
- go test -v -race -cover ./...
watch:test:
desc: Run go tests in watch mode
cmds:
- watchexec --exts go,yaml -r -- go test {{.CLI_ARGS}}
docs:
desc: Run the docs frontend in development mode
dir: docs
cmds:
- npm run docs:dev
e2e:
desc: Run end-to-end tests in watch mode
dir: e2e
cmds:
- npm run watch
e2e:install:
desc: Install Playwright browsers
dir: e2e
cmds:
- npm install
- npx playwright install --with-deps
e2e:ci:
desc: Run end-to-end tests on CI
dir: e2e
env:
CI: "true"
cmds:
- npm run test
build:release:
desc: Build the release binary for GOOS and GOARCH (current platform by default)
vars:
DEFAULT_OUTPUT: "dist/bin/{{.BINARY_NAME}}_{{.VERSION}}_{{ coalesce .GOOS OS }}_{{ coalesce .GOARCH ARCH }}{{ if eq (coalesce .GOOS OS) \"windows\" }}.exe{{ end }}"
OUTPUT: "{{ coalesce .OUTPUT .DEFAULT_OUTPUT }}"
generates:
- "{{.OUTPUT}}"
cmds:
- |
set -eou pipefail
echo "build {{.OUTPUT}}"
VERSION={{.VERSION}}
COMMIT=$(git rev-parse HEAD)
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
BUILT_BY=$(whoami)
GOOS={{.GOOS}} GOARCH={{.GOARCH}} CGO_ENABLED=0 go build \
-ldflags "-X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$DATE -X main.builtBy=$BUILT_BY" \
-tags embedui,embeddocs,embedgeo \
-o "{{.OUTPUT}}" \
|| echo "build failed for {{.OUTPUT}}"
silent: true
build:release:all:
desc: Build the release binary for all supported platforms
deps:
- for:
var: BUILD_OS_ARCH
split: ","
task: build:release
vars:
GOOS: "{{(.ITEM | split \"/\")._0}}"
GOARCH: "{{(.ITEM | split \"/\")._1}}"
archive:all:
desc: Archive all release binaries
deps:
- for:
var: BUILD_OS_ARCH
split: ","
task: archive
vars:
GOOS: "{{(.ITEM | split \"/\")._0}}"
GOARCH: "{{(.ITEM | split \"/\")._1}}"
archive:dir:
dir: dist/archives
internal: true
archive:
desc: Archive the release binary for GOOS and GOARCH (current platform by default)
vars:
INPUT: "dist/bin/{{.BINARY_NAME}}_{{.VERSION}}_{{ coalesce .GOOS OS }}_{{ coalesce .GOARCH ARCH }}{{ if eq (coalesce .GOOS OS) \"windows\" }}.exe{{ end }}"
OUTPUT: "dist/archives/{{.BINARY_NAME}}_{{.VERSION}}_{{ coalesce .GOOS OS }}_{{ coalesce .GOARCH ARCH }}.zip"
sources:
- "{{.INPUT}}"
generates:
- "{{.OUTPUT}}"
deps:
- task: archive:dir
cmds:
- echo "archive {{.OUTPUT}}"
- go run ./cmd/zip "{{.OUTPUT}}" "{{.INPUT}}"
silent: true
checksums:
desc: Generate checksums for all archives
dir: dist/archives
cmds:
- go run ../../cmd/sha256 *.zip > checksums.txt
docker:
desc: Build a Docker image with the latest git tag
vars:
TAGS: >-
{{- if (regexMatch "^v[0-9]+\\.[0-9]+\\.[0-9]+$" .VERSION) }}
{{- $versionParts := regexFindAll "[0-9]+" .VERSION 3 }}
{{- $major := index $versionParts 0 }}
{{- $minor := index $versionParts 1 }}
{{- $patch := index $versionParts 2 }}
-t {{.DOCKER_REPO}}:latest
-t {{.DOCKER_REPO}}:v{{$major}}
-t {{.DOCKER_REPO}}:v{{$major}}.{{$minor}}
-t {{.DOCKER_REPO}}:v{{$major}}.{{$minor}}.{{$patch}}
{{- else if (regexMatch "^v[0-9]+\\.[0-9]+\\.[0-9]+" .VERSION) }}
-t {{.DOCKER_REPO}}:{{.VERSION}}
{{- else }}
{{- end }}
preconditions:
- sh: test -n "{{.TAGS}}"
msg: "Git tag must be in the format vMAJOR.MINOR.PATCH* for docker build: {{.VERSION}}"
cmds:
- |
VERSION={{.VERSION}}
COMMIT=$(git rev-parse HEAD)
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
BUILT_BY=$(whoami)
LDFLAGS="-X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$DATE -X main.builtBy=$BUILT_BY"
docker build --build-arg LDFLAGS="$LDFLAGS" {{.TAGS | replace "\n" " "}} {{.EXTRA_ARGS}} .
docker:multiarch:
desc: Build multi-architecture Docker images
deps:
- task: docker
vars:
EXTRA_ARGS: >-
--platform {{ join "," .DOCKER_ARCH }}
{{.EXTRA_ARGS}}
DOCKER_REPO: "{{.DOCKER_REPO}}"
docker:multiarch:push:
desc: Build and push multi-architecture Docker images to GitHub Container Registry
deps:
- task: docker:multiarch
vars:
EXTRA_ARGS: >-
--iidfile .docker-image-id
--push {{ .DOCKER_ANNOTATIONS }}
{{.EXTRA_ARGS}}
DOCKER_REPO: "{{.DOCKER_REPO}}"
docker:multiarch:local:init:
desc: Initialize local Docker buildx builder
cmds:
- docker buildx create --name photofield-builder --driver docker-container
docker:multiarch:local:push:
desc: Build and push multi-architecture Docker images to local registry
preconditions:
- sh: curl localhost:5000/v2/_catalog
msg: "Local Docker registry is not running. Run 'docker compose up -d registry' to start it."
cmds:
- task: docker:multiarch:push
vars:
DOCKER_REPO: "{{.DOCKER_REPO_LOCAL}}"
EXTRA_ARGS: >-
--builder photofield-builder