-
Notifications
You must be signed in to change notification settings - Fork 18
/
Taskfile.yaml
323 lines (295 loc) · 11.6 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
version: '3'
output: 'group'
silent: true
# Used commands: cp, rm, mkdir, wget, cirl, find, grep, tar, git, cat, go, gofmt, 7z
#
# NOTE: I did not find a good way to check if they are available. Using task preconditions
# works, but is kind of useless as task will fail anyways and creating a special task to
# check is ugly as it needs to be in the dependencies for every target...
vars:
DEV_BUILD_DIR: 'build'
REL_BUILD_DIR: 'release'
GO_PATH: '{{env "GOPATH"}}'
TEMP: '{{env "TEMP"}}'
# this is coming from github actions
REF_VER: '{{regexFind "refs/tags/v[0-9]+\\.[0-9]+\\.?[0-9]*[-a-zA-Z0-9+]*" (env "GITHUB_REF")}}'
TATN: { sh: '{{if (env "TERM")}}tput setaf 4{{end}}' }
TOFF: { sh: '{{if (env "TERM")}}tput sgr0{{end}}' }
env:
CGO_ENABLED: '0'
GOTOOLCHAIN: 'local+path'
# this should work for most cases
GOPATH: '{{if .GO_PATH}}{{.GO_PATH}}{{else if .TEMP}}{{joinPath .TEMP "gopkg_fb2c"}}{{else}}/tmp/gopkg_fb2c{{end}}'
tasks:
default:
desc: Builds development version for host OS
aliases: [debug]
deps:
- task: copy-file
vars: { SRC: '{{joinPath "scripts" "pre-commit"}}', DST: '{{joinPath ".git" "hooks" "pre-commit"}}' }
- task: copy-file
vars: { SRC: '{{joinPath "kindlegen" (OS) "kindlegen"}}{{.SUFFIX}}', DST: '{{joinPath .DEV_BUILD_DIR "kindlegen"}}{{.SUFFIX}}' }
- task: get-dictionaries
- task: get-sentences
- task: generate-enums
cmds:
- task: go-build
vars: { FLAGS: 'debug', PACKAGE: './cmd/fb2c', TARGET: '{{joinPath .DEV_BUILD_DIR "fb2c"}}{{exeExt}}' }
test:
desc: Runs all available tests
deps: [test-hyphenator, test-processor]
test-processor:
desc: Runs tests on processor package
cmds:
- go test -v -mod=mod -gcflags 'all=-N -l' -coverprofile={{joinPath .DEV_BUILD_DIR "test_processor.out"}} ./processor
test-hyphenator:
desc: Runs tests on hyphenator package
cmds:
- go test -v -mod=mod -gcflags 'all=-N -l' -coverprofile={{joinPath .DEV_BUILD_DIR "test_hyphenator.out"}} ./hyphenator
release:
desc: Cross-builds release for all supported platforms
deps: [get-dictionaries, get-sentences]
cmds:
- mkdir -p '{{.REL_BUILD_DIR}}'
- for: [linux-amd64, linux-arm64, linux-386, darwin-amd64, darwin-arm64, windows-amd64-.exe, windows-arm64-.exe, windows-386-.exe]
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: '{{joinPath .REL_BUILD_DIR "fb2c"}}-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: { SRC: '{{joinPath "kindlegen" .GOOS "kindlegen"}}{{.SUFFIX}}', DST: '{{joinPath .BUILD_DIR "fb2converter" "kindlegen"}}{{.SUFFIX}}' }
- task: go-build
vars: { GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{joinPath .BUILD_DIR "fb2converter" "fb2c"}}{{.SUFFIX}}' }
- task: go-build
vars: { GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2epub', TARGET: '{{joinPath .BUILD_DIR "fb2epub" "fb2epub"}}{{.SUFFIX}}' }
- task: go-build
vars: { GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2mobi', TARGET: '{{joinPath .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: '{{joinPath .REL_BUILD_DIR "fb2c"}}-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: { SRC: '{{joinPath "kindlegen" .GOOS "kindlegen"}}{{.SUFFIX}}', DST: '{{joinPath .BUILD_DIR "kindlegen"}}{{.SUFFIX}}' }
- task: go-build
vars: { GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{joinPath .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-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: '{{joinPath .REL_BUILD_DIR "fb2c"}}-{{.GOOS}}-{{.GOARCH}}'
cmds:
- mkdir -p {{.BUILD_DIR}}
- defer: rm -rf {{.BUILD_DIR}}
- task: copy-file
vars: { SRC: '{{joinPath "kindlegen" .GOOS "kindlegen"}}{{.SUFFIX}}', DST: '{{joinPath .BUILD_DIR "kindlegen"}}{{.SUFFIX}}' }
- task: go-build
vars: { GOOS: '{{.GOOS}}', GOARCH: '{{.GOARCH}}', FLAGS: 'release', PACKAGE: './cmd/fb2c', TARGET: '{{joinPath .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
vars:
STRINGER: '{{joinPath .DEV_BUILD_DIR "stringer"}}{{exeExt}}'
INPUT: 'processor/enums.go'
OUTPUT: 'processor/enums_string.go'
cmds:
- task: go-build
vars: { FLAGS: 'xtool', PACKAGE: 'golang.org/x/tools/cmd/stringer', TARGET: '{{.STRINGER}}' }
- echo "{{.TATN}}Generating enums{{.TOFF}}"
- |
./{{.STRINGER}} -linecomment \
-type OutputFmt,NotesFmt,TOCPlacement,TOCType,APNXGeneration,StampPlacement,CoverProcessing \
-output processor/enums_string.go \
processor/enums.go
sources:
- '{{.INPUT}}'
generates:
- '{{.OUTPUT}}'
lint:
desc: Lints whole project
vars:
LINTER: '{{joinPath .DEV_BUILD_DIR "staticcheck"}}{{exeExt}}'
cmds:
- task: go-build
vars: { FLAGS: 'xtool', PACKAGE: 'honnef.co/go/tools/cmd/staticcheck', TARGET: '{{.LINTER}}' }
- echo "{{.TATN}}Linting project{{.TOFF}}"
- ./{{.LINTER}} -f stylish -tests=false ./...
sources:
- './**/*.go'
- './go.sum'
- './go.mod'
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 if eq .FLAGS "xtool" -}}
-mod=mod -trimpath
{{- else -}}
{{fail "go build flags could be \"debug\", \"release\" or \"xtool\" only!"}}
{{- end -}}
cmds:
- task: project-version
- echo "{{.TATN}}Building \"{{base .TARGET}}\" binary for \"$GOOS:$GOARCH\" from \"{{.PACKAGE}}\"{{.TOFF}}"
- go build {{.GOARGS}} -o '{{.TARGET}}' '{{.PACKAGE}}'
sources:
- './**/*.go'
generates:
- '{{.TARGET}}'
project-version:
internal: true
run: when_changed
desc: Generates "misc.go/version.go" file with version info to be used on runtime
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: '{{joinPath .ROOT_DIR "misc"}}'
FILE: '{{joinPath .ROOT_DIR "misc" "version.go"}}'
GIT_HASH:
sh: git rev-list -1 HEAD
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:
- '{{joinPath ".git" "index"}}'
generates:
- '{{.FILE}}'
status:
- test -f '{{.FILE}}'
get-dictionaries:
internal: true
run: once
desc: Get dictionary rules for all supported languages
vars:
DIR: '{{joinPath "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/generic/hyph-utf8/patterns/txt
- wget -q -r -l1 --no-parent -nd -A.hyp.txt http://ctan.math.utah.edu/ctan/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/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: '{{joinPath "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 .
copy-file:
internal: true
run: when_changed
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}}'
go-tidy:
desc: Tidy Go modules
aliases: [tidy]
vars:
GO_VER: '{{default "" (regexFind "[0-9]+\\.[0-9]+\\.?[0-9]*[-a-zA-Z0-9+]*" (env "CUR_PROJECT_TYPE"))}}'
cmds:
- go mod tidy{{if .GO_VER}} -go={{.GO_VER}}{{end}}
go-vendor:
desc: Creates vendor directory for release build
aliases: [vendor]
cmds:
- go mod vendor
clean:
desc: Cleans all build release aritfacts
cmds:
- |
find '{{joinPath "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 '{{joinPath "static" "dictionaries"}}' -type f \
-name 'hyph-*.txt.gz' \
-delete -printf "removed '%p'\n"
- rm -rfv {{.REL_BUILD_DIR}}
- rm -fv .task/checksum/*