-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
191 lines (169 loc) · 5.84 KB
/
Taskfile.yml
File metadata and controls
191 lines (169 loc) · 5.84 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
version: '3'
vars:
BINARY_NAME: noteleaf
BUILD_DIR: ./tmp
CMD_DIR: ./cmd
COVERAGE_FILE: coverage.out
COVERAGE_HTML: coverage.html
VERSION_PKG: github.com/stormlightlabs/noteleaf/internal/version
# Git version detection
GIT_COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "none"
GIT_TAG:
sh: git describe --tags --exact-match 2>/dev/null || echo ""
GIT_DESCRIBE:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
tasks:
default:
desc: Show available tasks
silent: true
cmds:
- task --list
test:
desc: Run all tests
cmds:
- go test ./...
coverage:
desc: Generate HTML coverage report
cmds:
- go test -coverprofile={{.COVERAGE_FILE}} ./...
- go tool cover -html={{.COVERAGE_FILE}} -o {{.COVERAGE_HTML}}
- echo "Coverage report generated at {{.COVERAGE_HTML}}"
cov:
desc: Show coverage in terminal
cmds:
- go test -coverprofile={{.COVERAGE_FILE}} ./...
- go tool cover -func={{.COVERAGE_FILE}}
build:
desc: Build binary (simple build without version injection)
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.CMD_DIR}}
- echo "Built {{.BUILD_DIR}}/{{.BINARY_NAME}}"
build:dev:
desc: Build binary with dev version (includes git commit hash and dev tools)
vars:
VERSION: "{{.GIT_DESCRIBE}}"
LDFLAGS: "-X {{.VERSION_PKG}}.Version={{.VERSION}} -X {{.VERSION_PKG}}.Commit={{.GIT_COMMIT}} -X {{.VERSION_PKG}}.BuildDate={{.BUILD_DATE}}"
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.CMD_DIR}}
- 'echo "Built {{.BUILD_DIR}}/{{.BINARY_NAME}} (version: {{.VERSION}})"'
build:rc:
desc: Build release candidate binary (requires git tag with -rc suffix, excludes dev tools)
vars:
VERSION: "{{.GIT_TAG}}"
LDFLAGS: "-X {{.VERSION_PKG}}.Version={{.VERSION}} -X {{.VERSION_PKG}}.Commit={{.GIT_COMMIT}} -X {{.VERSION_PKG}}.BuildDate={{.BUILD_DATE}}"
preconditions:
- sh: '[ -n "{{.GIT_TAG}}" ]'
msg: "No git tag found. Create a tag with 'git tag v1.0.0-rc1' first."
- sh: 'echo "{{.GIT_TAG}}" | grep -q "\-rc"'
msg: "Git tag must contain '-rc' for release candidate builds (e.g., v1.0.0-rc1)"
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -tags prod -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.CMD_DIR}}
- 'echo "Built {{.BUILD_DIR}}/{{.BINARY_NAME}} (version: {{.VERSION}})"'
build:prod:
desc: Build production binary (requires clean semver git tag, excludes dev tools)
vars:
VERSION: "{{.GIT_TAG}}"
LDFLAGS: "-X {{.VERSION_PKG}}.Version={{.VERSION}} -X {{.VERSION_PKG}}.Commit={{.GIT_COMMIT}} -X {{.VERSION_PKG}}.BuildDate={{.BUILD_DATE}}"
preconditions:
- sh: '[ -n "{{.GIT_TAG}}" ]'
msg: "No git tag found. Create a tag with 'git tag v1.0.0' first."
- sh: 'echo "{{.GIT_TAG}}" | grep -qE "^v?[0-9]+\.[0-9]+\.[0-9]+$"'
msg: "Git tag must be a clean semver version (e.g., v1.0.0 or 1.0.0) without prerelease suffix"
- sh: '[ -z "$(git status --porcelain)" ]'
msg: "Working directory must be clean (no uncommitted changes) for production builds"
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -tags prod -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.CMD_DIR}}
- 'echo "Built {{.BUILD_DIR}}/{{.BINARY_NAME}} (version: {{.VERSION}})"'
clean:
desc: Remove build artifacts and coverage files
cmds:
- rm -f {{.COVERAGE_FILE}} {{.COVERAGE_HTML}}
- rm -rf {{.BUILD_DIR}}
- echo "Cleaned build artifacts"
lint:
desc: Run linters (go vet and go fmt)
cmds:
- go vet ./...
- go fmt ./...
check:
desc: Run linters and coverage tests
cmds:
- task: lint
- task: cov
deps:
desc: Download and tidy dependencies
cmds:
- go mod download
- go mod tidy
run:
desc: Build and run the application
deps: [build]
cmds:
- '{{.BUILD_DIR}}/{{.BINARY_NAME}}'
status:
desc: Show Go version, module info, and dependencies
silent: true
cmds:
- echo "=== Go Version ==="
- go version
- echo ""
- echo "=== Module Info ==="
- go list -m
- echo ""
- echo "=== Dependencies ==="
- go list -m all
dev:
desc: Full development workflow (clean, lint, test, build)
cmds:
- task: clean
- task: lint
- task: test
- task: build
docs:generate:
desc: Generate documentation in all formats
cmds:
- go run tools/docgen.go -output website/docs/manual -format docusaurus
- go run tools/docgen.go -output docs/manual -format man
- echo "Documentation generated"
docs:man:
desc: Generate man pages
cmds:
- mkdir -p docs/manual
- go run tools/docgen.go -output docs/manual -format man
- echo "Man pages generated in docs/manual"
docs:serve:
desc: Start docusaurus development server
dir: website
cmds:
- npm run start
version:show:
desc: Display current version information
silent: true
cmds:
- echo "Version info:"
- 'echo " Git tag: {{.GIT_TAG}}"'
- 'echo " Git commit: {{.GIT_COMMIT}}"'
- 'echo " Git describe: {{.GIT_DESCRIBE}}"'
- 'echo " Build date: {{.BUILD_DATE}}"'
version:validate:
desc: Validate git tag format for releases
cmds:
- |
if [ -z "{{.GIT_TAG}}" ]; then
echo "No git tag found"
exit 1
fi
if echo "{{.GIT_TAG}}" | grep -qE "^v?[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$"; then
echo "Valid version tag: {{.GIT_TAG}}"
else
echo "Invalid version tag: {{.GIT_TAG}}"
echo "Expected format: v1.0.0 or v1.0.0-rc1"
exit 1
fi