-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTaskfile.yaml
406 lines (375 loc) · 15.2 KB
/
Taskfile.yaml
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
version: '3'
output: 'group'
silent: true
# we are assuming that host os is always Linux
vars:
GO_VERSION_FULL: {sh: GOTOOLCHAIN=local+path go version}
GO_VERSION: '{{regexFind "[0-9]+\\.[0-9]+\\.?[0-9]*" (regexFind "go version go[0-9]+\\.[0-9]+\\.?[0-9]*[a-zA-Z0-9]* [^/]+/.*" .GO_VERSION_FULL)}}'
PRJ_NAME: 'fb2converter'
DEV_BUILD_DIR: 'build'
REL_BUILD_DIR: 'release'
REF_VER: '{{regexFind "refs/tags/v[0-9]+\\.[0-9]+\\.?[0-9]*[-a-zA-Z0-9+]*" (env "GITHUB_REF")}}'
TARGET_RELEASES: [linux-amd64, linux-arm64, linux-386, darwin-amd64, darwin-arm64, freebsd-amd64, freebsd-arm64, windows-amd64-.exe, windows-arm64-.exe, windows-386-.exe]
TATN: {sh: '{{if (env "TERM")}}tput setaf 4{{end}}'}
TOFF: {sh: '{{if (env "TERM")}}tput sgr0{{end}}'}
env:
CGO_ENABLED: '0'
GOPATH: '{{default (joinPath (default "/tmp" (env "TEMP")) "gopkg_fb2c") (env "GOPATH")}}'
GOTOOLCHAIN: 'local+path'
tasks:
default:
desc: Builds development version for host OS
aliases: [debug]
platforms: [linux]
deps:
- task: copy-file
vars: {SRC: 'scripts/git/pre-commit', DST: '.git/hooks/pre-commit'}
- task: copy-file
vars: {SRC: 'scripts/git/pre-push', DST: '.git/hooks/pre-push'}
- task: copy-file
vars: {SRC: 'kindlegen/linux/kindlegen', DST: '{{.DEV_BUILD_DIR}}/kindlegen'}
- task: generate-project-version
- task: get-dictionaries
- task: get-sentences
- task: generate-enums
cmds:
- task: go-build
vars: {FLAGS: 'debug', PACKAGE: './cmd/fb2c', TARGET: '{{.DEV_BUILD_DIR}}/fb2c'}
- task: lint
test:
desc: |
Runs available tests.
When invoked as usual runs tests for all packages where it can find "*_test.go" files, for example: "task test".
You can specify what tests to run by using PACKAGES environment variable, for example: "PACKAGES='./hyphenator,./processor' task test".
You can pass any additional parameters supported by "go test", for example: "PACKAGES='./hyphenator' task test -- -run=TestHyphenatorSpecial".
platforms: [linux]
deps: [generate-project-version, get-dictionaries, get-sentences, generate-enums]
vars:
TEST_DIR: "{{.ROOT_DIR}}/{{.DEV_BUILD_DIR}}/tests_results"
DIRS_WITH_TESTS:
sh: find -name '*_test.go' -printf "%h\n" | sort -u
PACKAGES: '{{default .DIRS_WITH_TESTS (replace "," "\n" (env "PACKAGES"))}}'
env:
# race instrumentation requires cgo
CGO_ENABLED: "1"
cmds:
- mkdir -p {{.TEST_DIR}}
- for: {var: PACKAGES}
cmd: |
echo
echo "{{.TATN}}{{clean .ITEM}} tests...{{.TOFF}}"
echo
go test -mod=mod -v -coverprofile='{{.TEST_DIR}}/test_{{replace "/" "_" (clean .ITEM)}}_coverage.out' {{.CLI_ARGS}} '{{.ITEM}}'
bench:
desc: |
Runs available benchmarks.
When invoked as usual runs benchmarks for all packages where it can find "*_test.go" files, for example: "task bench".
You can specify what packages to benchmark by using PACKAGES environment variable, for example: "PACKAGES='./cache,./service' task bench".
You can pass any additional parameters supported by "go test", for example: "PACKAGES='./marshallers/segdiffs' task bench -- -bench=BenchmarkBinary -benchmem".
platforms: [linux]
deps: [generate-project-version, get-dictionaries, get-sentences, generate-enums]
vars:
TEST_DIR: "{{.ROOT_DIR}}/{{.DEV_BUILD_DIR}}/tests_results"
DIRS_WITH_TESTS:
sh: find -name '*_test.go' -printf "%h\n" | sort -u
PACKAGES: '{{default .DIRS_WITH_TESTS (replace "," "\n" (env "PACKAGES"))}}'
env:
# some instrumentation requires cgo
CGO_ENABLED: "1"
cmds:
- mkdir -p {{.TEST_DIR}}
- for: {var: PACKAGES}
cmd: |
echo
echo "{{.TATN}}{{clean .ITEM}} benchmarks...{{.TOFF}}"
echo
go test -mod=mod -run=XXX_no_tests_XXX {{default "-bench=." .CLI_ARGS}} '{{.ITEM}}'
escape:
desc: |
Runs escape analisys on specified package.
You could specify anything in the project, for example "task escape -- ./marshallers/segdiffs".
If no package is specified assumes "./cmd/goliath".
platforms: [linux]
deps: [generate-project-version, get-dictionaries, get-sentences, generate-enums]
cmds:
- echo "{{.TATN}}Building binary with escape analisys enabled{{.TOFF}}"
- go build -mod=mod -gcflags 'all=-m' -o /dev/null {{default "./cmd/fb2c" .CLI_ARGS}}
method: none
release:
desc: Cross-builds release for all supported platforms
platforms: [linux]
deps: [generate-project-version, get-dictionaries, get-sentences]
cmds:
- mkdir -p '{{.REL_BUILD_DIR}}'
- for:
var: TARGET_RELEASES
task: release-for-platform-{{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}}
vars:
GOOS: '{{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}}'
GOARCH: '{{with $arch := split "-" .ITEM}}{{$arch._1}}{{end}}'
SUFFIX: '{{with $arch := split "-" .ITEM}}{{$arch._2}}{{end}}'
release-for-platform-windows:
internal: true
desc: Builds release for specified platform
requires:
vars: [GOOS, GOARCH, SUFFIX]
label: release-for-platform-windows-{{.GOOS}}-{{.GOARCH}}
vars:
BUILD_DIR: '{{.REL_BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}'
REL_NAME: '{{.REL_BUILD_DIR}}/fb2c-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: {SRC: 'kindlegen/{{.GOOS}}/kindlegen{{.SUFFIX}}', DST: '{{.BUILD_DIR}}/fb2converter/kindlegen{{.SUFFIX}}'}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{.BUILD_DIR}}/fb2converter/fb2c{{.SUFFIX}}'}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2epub', TARGET: '{{.BUILD_DIR}}/fb2epub/fb2epub{{.SUFFIX}}'}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2mobi', TARGET: '{{.BUILD_DIR}}/fb2mobi/fb2mobi{{.SUFFIX}}'}
- echo "{{.TATN}}Archiving release \"{{.REL_NAME}}.zip\"{{.TOFF}}"
- 7z a -r -bd -bso0 -tzip {{.REL_NAME}} ./{{.BUILD_DIR}}/*
status:
- test -f '{{.REL_NAME}}.zip'
release-for-platform-linux:
internal: true
desc: Builds release for specified platform
requires:
vars: [GOOS, GOARCH, SUFFIX]
label: release-for-platform-linux-{{.GOOS}}-{{.GOARCH}}
vars:
BUILD_DIR: '{{.REL_BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}'
REL_NAME: '{{.REL_BUILD_DIR}}/fb2c-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: {SRC: 'kindlegen/{{.GOOS}}/kindlegen', DST: '{{.BUILD_DIR}}/kindlegen'}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{.BUILD_DIR}}/fb2c'}
- echo "{{.TATN}}Archiving release \"{{.REL_NAME}}.zip\"{{.TOFF}}"
- 7z a -r -bd -bso0 -tzip {{.REL_NAME}} ./{{.BUILD_DIR}}/*
status:
- test -f '{{.REL_NAME}}.zip'
release-for-platform-darwin:
internal: true
desc: Builds release for specified platform
requires:
vars: [GOOS, GOARCH, SUFFIX]
label: release-for-platform-darwin-{{.GOOS}}-{{.GOARCH}}
vars:
BUILD_DIR: '{{.REL_BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}'
REL_NAME: '{{.REL_BUILD_DIR}}/fb2c-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: {SRC: 'kindlegen/{{.GOOS}}/kindlegen{{.SUFFIX}}', DST: '{{.BUILD_DIR}}/kindlegen{{.SUFFIX}}'}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{.BUILD_DIR}}/fb2c{{.SUFFIX}}'}
- echo "{{.TATN}}Archiving release \"{{.REL_NAME}}.zip\"{{.TOFF}}"
- 7z a -r -bd -bso0 -tzip {{.REL_NAME}} ./{{.BUILD_DIR}}/*
status:
- test -f '{{.REL_NAME}}.zip'
release-for-platform-freebsd:
internal: true
desc: Builds release for specified platform
requires:
vars: [GOOS, GOARCH, SUFFIX]
label: release-for-platform-freebsd-{{.GOOS}}-{{.GOARCH}}
vars:
BUILD_DIR: '{{.REL_BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}'
REL_NAME: '{{.REL_BUILD_DIR}}/fb2c-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: go-build
vars: {GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{.BUILD_DIR}}/fb2c{{.SUFFIX}}'}
- echo "{{.TATN}}Archiving release \"{{.REL_NAME}}.zip\"{{.TOFF}}"
- 7z a -r -bd -bso0 -tzip {{.REL_NAME}} ./{{.BUILD_DIR}}/*
status:
- test -f '{{.REL_NAME}}.zip'
generate-enums:
internal: true
desc: Generates fmt.Stringer interfaces for specified enum types
cmds:
- echo "{{.TATN}}Generating enums{{.TOFF}}"
- |
go tool stringer -linecomment \
-type OutputFmt,NotesFmt,TOCPlacement,TOCType,APNXGeneration,StampPlacement,CoverProcessing \
-output processor/enums_string.go \
processor/enums.go
sources:
- processor/enums.go
generates:
- processor/enums_string.go
lint:
desc: Lints the whole project
platforms: [linux]
cmds:
- echo "{{.TATN}}Linting project{{.TOFF}}"
- go tool staticcheck -f stylish -tests=false ./...
go-build:
internal: true
run: when_changed
desc: Builds binary using go toolchain
requires:
vars: [PACKAGE, TARGET, FLAGS]
label: go-build-{{.PACKAGE}}-{{.TARGET}}-{{.FLAGS}}
env: {GOOS: '{{default "linux" .GOOS}}', GOARCH: '{{default "amd64" .GOARCH}}'}
vars:
GOARGS: |
{{- if eq .FLAGS "debug" -}}
-mod=mod -gcflags 'all=-N -l'
{{- else if eq .FLAGS "release" -}}
-mod=vendor -trimpath
{{- else -}}
{{fail "go build flags could be \"debug\" or \"release\" only!"}}
{{- end -}}
cmds:
- echo "{{.TATN}}Building \"{{base .TARGET}}\" binary for \"$GOOS:$GOARCH\" from \"{{.PACKAGE}}\"{{.TOFF}}"
- go build {{.GOARGS}} -o '{{.TARGET}}' '{{.PACKAGE}}'
sources:
- ./**/*.go
generates:
- '{{.TARGET}}'
generate-project-version:
internal: true
desc: Generates "misc/version.go" file with version info to be used on runtime.
run: when_changed
vars:
VER: '{{if .REF_VER}}{{regexFind "[0-9]+\\.[0-9]+\\.?[0-9]*[-a-zA-Z0-9+]*" .REF_VER}}{{else}}0.0.0-dev{{end}}'
DIR: '{{.ROOT_DIR}}/misc'
FILE: '{{.ROOT_DIR}}/misc/version.go'
GIT_HASH:
sh: git rev-list -1 HEAD || true
GIT_STATUS:
sh: git diff --shortstat
cmds:
- echo "{{.TATN}}Version {{.VER}} {{.GIT_HASH}}{{if .GIT_STATUS}}*{{end}}{{.TOFF}}"
- mkdir -p {{.DIR}}
- |
cat << EOF > {{.FILE}}
package misc
func GetVersion() string {
return "{{.VER}}"
}
func GetGitHash() string {
return "{{.GIT_HASH}}{{if .GIT_STATUS}}*{{end}}"
}
EOF
- gofmt -w {{.FILE}}
sources:
- .git/index
generates:
- '{{.FILE}}'
get-dictionaries:
internal: true
run: once
desc: Get dictionary rules for all supported languages
vars:
DIR: 'static/dictionaries'
dir: '{{.DIR}}'
cmds:
- rm -f *.txt
- echo "{{.TATN}}Downloading dictionary patterns from \"ctan.math.utah.edu\"{{.TOFF}}"
- wget -q -r -l1 --no-parent -nd -A.pat.txt http://ctan.math.utah.edu/ctan/tex-archive/language/hyph-utf8/tex/patterns/txt
- wget -q -r -l1 --no-parent -nd -A.hyp.txt http://ctan.math.utah.edu/ctan/tex-archive/language/hyph-utf8/tex/patterns/txt
- gzip -q -f hyph-*.txt
status:
- find -type f -name 'hyph-*.txt.gz' | grep -q .
get-sentences:
internal: true
run: once
desc: Get NLTK training data
vars:
DIR: 'static/sentences'
dir: '{{.DIR}}'
cmds:
- rm -f *.json
- echo "{{.TATN}}Downloading NLTK training data from \"neurosnap/sentences\"{{.TOFF}}"
- curl -s -L https://api.github.com/repos/neurosnap/sentences/tarball | tar xz --wildcards '*/data/*.json' --strip-components=2
- gzip -q -f *.json
status:
- |
find -type f -name '*.json.gz' \
-not -name 'russian.json.gz' \
-not -name 'icelandic.json.gz' \
-not -name 'korean.json.gz' \
-not -name 'hungarian.json.gz' | grep -q .
go-modinit:
desc: Using current toolchain (re)initializes go.mod with provided module name, gets latest versions and runs tidy
aliases: [modinit]
prompt: This will replace your existing go.mod and go.sum if you have any. Do you want to continue?
requires:
vars: [GO_VERSION]
cmds:
- echo "{{.TATN}}Running go mod init for \"{{.PRJ_NAME}}\" with {{.GO_VERSION}}{{.TOFF}}"
- |
[ -f {{.ROOT_DIR}}/go.mod ] && rm {{.ROOT_DIR}}/go.mod || true
[ -f {{.ROOT_DIR}}/go.sum ] && rm {{.ROOT_DIR}}/go.sum || true
- go mod init {{.PRJ_NAME}}
- go mod edit -go {{.GO_VERSION}} -toolchain go{{.GO_VERSION}}
- go get -tool golang.org/x/tools/cmd/stringer
- go get -tool honnef.co/go/tools/cmd/staticcheck
- go get -u ./...
- go mod tidy {{.CLI_ARGS}}
go-tidy:
desc: Tidy Go modules for the project.
platforms: [linux]
aliases: [tidy]
cmds:
- for:
var: TARGET_RELEASES
cmd: |
echo "Tidying with {{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}} GOARCH={{with $arch := split "-" .ITEM}}{{$arch._1}}{{end}}"
GOOS={{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}} GOARCH={{with $arch := split "-" .ITEM}}{{$arch._1}}{{end}} go mod tidy {{.CLI_ARGS}}
go-vendor:
desc: Creates vendor directory for release build
platforms: [linux]
aliases: [vendor]
cmds:
- for:
var: TARGET_RELEASES
cmd: |
echo "Vendoring with {{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}} GOARCH={{with $arch := split "-" .ITEM}}{{$arch._1}}{{end}}"
GOOS={{with $arch := split "-" .ITEM}}{{$arch._0}}{{end}} GOARCH={{with $arch := split "-" .ITEM}}{{$arch._1}}{{end}} go mod vendor {{.CLI_ARGS}}
clean:
desc: Cleans all build release aritfacts
platforms: [linux]
cmds:
- |
find 'static/sentences' -type f \
-name '*.json.gz' \
-not -name 'russian.json.gz' \
-not -name 'icelandic.json.gz' \
-not -name 'korean.json.gz' \
-not -name 'hungarian.json.gz' \
-delete -printf "removed '%p'\n"
- |
find 'static/dictionaries' -type f \
-name 'hyph-*.txt.gz' \
-delete -printf "removed '%p'\n"
- rm -rfv {{.REL_BUILD_DIR}}
- rm -rfv {{.DEV_BUILD_DIR}}
- rm -fv .task/checksum/*
- rm -fv .task/timestamp/*
- rm -fv misc/version.go
copy-file:
internal: true
desc: Copies source file to destination
requires:
vars: [SRC, DST]
label: copy-file-{{.SRC}}-{{.DST}}
cmds:
- echo "{{.TATN}}Copying \"{{.SRC}}\" to \"{{.DST}}\"{{.TOFF}}"
- mkdir -p {{dir .DST}}
- cp '{{.SRC}}' '{{.DST}}'
sources:
- '{{.SRC}}'
generates:
- '{{.DST}}'
status:
- test -f '{{.DST}}'
method: timestamp