-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
211 lines (183 loc) · 6.1 KB
/
Taskfile.yml
File metadata and controls
211 lines (183 loc) · 6.1 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
version: "3"
vars:
BINARY_NAME: wfkit
BINARY_DIR: bin
RELEASE_DIR: releases
MAIN_PKG: ./cmd/wfkit
VERSION:
sh: node -p "require('./npm/package.json').version"
GO_LDFLAGS: "-X wfkit/internal/version.Version={{.VERSION}}"
tasks:
default:
desc: "Clean and build the application"
cmds:
- task: clean
- task: build
dev:
desc: "Run application with live reloading using air"
cmds:
- go run github.com/air-verse/air@latest
clean:
desc: "Clean build and release directories"
cmds:
- rm -rf {{.BINARY_DIR}} {{.RELEASE_DIR}}
fmt:
desc: "Format Go code"
cmds:
- go fmt ./...
lint:
desc: "Run golangci-lint"
cmds:
- golangci-lint run ./...
test:
desc: "Run tests"
cmds:
- go test -v ./...
version:check:
desc: "Validate that release metadata is consistent"
cmds:
- node -e "const version=require('./npm/package.json').version; if(!/^\\d+\\.\\d+\\.\\d+(-.+)?$/.test(version)){console.error('Invalid npm/package.json version:', version); process.exit(1)}; console.log('Version OK:', version)"
version:current:
desc: "Print the current release version"
cmds:
- node -p "require('./npm/package.json').version"
version:bump:
desc: "Bump npm/package.json version. Usage: task version:bump TYPE=patch"
preconditions:
- sh: test -n "{{.TYPE}}"
msg: "TYPE is required. Use patch, minor, major, or an exact semver version."
cmds:
- node scripts/bump-version.mjs {{.TYPE}}
- task: version:check
version:patch:
desc: "Bump the patch version"
cmds:
- task: version:bump
vars: { TYPE: patch }
version:minor:
desc: "Bump the minor version"
cmds:
- task: version:bump
vars: { TYPE: minor }
version:major:
desc: "Bump the major version"
cmds:
- task: version:bump
vars: { TYPE: major }
release:verify:
desc: "Run the checks required before cutting a release"
cmds:
- task: version:check
- node --test npm/install.test.js
- go test ./...
release:prepare:
desc: "Bump the release version and create a release commit. Usage: task release:prepare TYPE=patch"
preconditions:
- sh: test -n "{{.TYPE}}"
msg: "TYPE is required. Use patch, minor, major, or an exact semver version."
- sh: git diff --quiet && git diff --cached --quiet
msg: "Working tree must be clean before preparing a release."
cmds:
- task: version:bump
vars: { TYPE: "{{.TYPE}}" }
- git add npm/package.json
- 'node -e "const { execFileSync } = require(''node:child_process''); const version = require(''./npm/package.json'').version; execFileSync(''git'', [''commit'', ''-m'', ''chore: release v'' + version], { stdio: ''inherit'' });"'
release:patch:
desc: "Verify, bump the patch version, and create a release commit"
cmds:
- task: release:verify
- task: release:prepare
vars: { TYPE: patch }
release:minor:
desc: "Verify, bump the minor version, and create a release commit"
cmds:
- task: release:verify
- task: release:prepare
vars: { TYPE: minor }
release:major:
desc: "Verify, bump the major version, and create a release commit"
cmds:
- task: release:verify
- task: release:prepare
vars: { TYPE: major }
hooks:install:
desc: "Install local git hooks used by this repository"
cmds:
- mkdir -p .git/hooks
- 'printf ''#!/bin/sh\n\nnode scripts/validate-release-commit.mjs "$1"\n'' > .git/hooks/commit-msg'
- chmod 755 .git/hooks/commit-msg
- 'printf ''#!/bin/sh\n\nnode scripts/guard-main-push.mjs\n'' > .git/hooks/pre-push'
- chmod 755 .git/hooks/pre-push
play:init:
desc: "Test 'wfkit init' inside the playground directory"
cmds:
- mkdir -p playground/test-project
- cd playground/test-project && go run ../../{{.MAIN_PKG}} init --name test-project
play:clean:
desc: "Clean all test projects in the playground directory"
cmds:
- rm -rf playground/*
build:
desc: "Build Go application for current OS and architecture"
sources:
- "**/*.go"
- "go.mod"
- "go.sum"
generates:
- "{{.BINARY_DIR}}/{{.BINARY_NAME}}"
cmds:
- mkdir -p {{.BINARY_DIR}}
- go build -v -ldflags "{{.GO_LDFLAGS}}" -o {{.BINARY_DIR}}/{{.BINARY_NAME}} {{.MAIN_PKG}}
- ln -sf {{.USER_WORKING_DIR}}/{{.BINARY_DIR}}/{{.BINARY_NAME}} $(go env GOPATH)/bin/{{.BINARY_NAME}}
cross-compile:
desc: "Cross-compile using Docker"
preconditions:
- sh: docker info > /dev/null 2>&1
msg: "Docker daemon is not running. Please start Docker."
cmds:
- mkdir -p {{.BINARY_DIR}}
- docker run --rm -v {{.USER_WORKING_DIR}}:/src -w /src golang:1.24.0 go build -v -ldflags "{{.GO_LDFLAGS}}" -o {{.BINARY_DIR}}/{{.BINARY_NAME}} {{.MAIN_PKG}}
release:
internal: true
requires:
vars: [OS, ARCH]
vars:
EXT: '{{if eq .OS "windows"}}.exe{{else}}{{end}}'
OUT: "{{.RELEASE_DIR}}/{{.OS}}/{{.BINARY_NAME}}-{{.OS}}-{{.ARCH}}{{.EXT}}"
sources:
- "**/*.go"
- "go.mod"
- "go.sum"
generates:
- "{{.OUT}}"
cmds:
- mkdir -p {{.RELEASE_DIR}}/{{.OS}}
- GOOS={{.OS}} GOARCH={{.ARCH}} go build -v -ldflags "{{.GO_LDFLAGS}}" -o {{.OUT}} {{.MAIN_PKG}}
release-darwin:
desc: "Build release for macOS (amd64 and arm64)"
cmds:
- task: release
vars: { OS: darwin, ARCH: amd64 }
- task: release
vars: { OS: darwin, ARCH: arm64 }
release-linux:
desc: "Build release for Linux (amd64 and arm64)"
cmds:
- task: release
vars: { OS: linux, ARCH: amd64 }
- task: release
vars: { OS: linux, ARCH: arm64 }
release-windows:
desc: "Build release for Windows (amd64 and arm64)"
cmds:
- task: release
vars: { OS: windows, ARCH: amd64 }
- task: release
vars: { OS: windows, ARCH: arm64 }
release-all:
desc: "Build releases for all supported platforms"
deps:
- version:check
- release-darwin
- release-linux
- release-windows