-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTaskfile.yml
More file actions
99 lines (89 loc) · 2.57 KB
/
Taskfile.yml
File metadata and controls
99 lines (89 loc) · 2.57 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
version: "3"
vars:
BIN_NAME: chaitin-cli
BUILD_DIR: bin
DIST_DIR: dist
tasks:
default:
cmds:
- task --list
fmt:
desc: Format Go source files
cmds:
- go fmt ./...
fmt:check:
desc: Fail if Go source files are not gofmt-clean
cmds:
- |
set -euo pipefail
files="$(find . -path './vendor' -prune -o -name '*.go' -print)"
if [ -z "$files" ]; then
exit 0
fi
unformatted="$(gofmt -l $files)"
if [ -n "$unformatted" ]; then
echo "the following files are not gofmt-formatted:"
echo "$unformatted"
exit 1
fi
lint:
desc: Run compile checks
cmds:
- go vet ./...
test:
desc: Run unit tests
cmds:
- go test ./...
build:
desc: Build the {{ .BIN_NAME }} binary
cmds:
- mkdir -p {{.BUILD_DIR}}
- go build -o {{.BUILD_DIR}}/{{.BIN_NAME}} .
build:target:
desc: Build the {{ .BIN_NAME }} binary for a target platform
requires:
vars:
- GOOS
- GOARCH
vars:
TARGET_DIR: '{{.BUILD_DIR}}/{{.GOOS}}_{{.GOARCH}}'
BIN_EXT: '{{if eq .GOOS "windows"}}.exe{{end}}'
cmds:
- mkdir -p {{.TARGET_DIR}}
- env CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -o {{.TARGET_DIR}}/{{.BIN_NAME}}{{.BIN_EXT}} .
package:
desc: Build and archive the {{ .BIN_NAME }} binary for a target platform
requires:
vars:
- GOOS
- GOARCH
vars:
TARGET_DIR: '{{.BUILD_DIR}}/{{.GOOS}}_{{.GOARCH}}'
BIN_EXT: '{{if eq .GOOS "windows"}}.exe{{end}}'
ARCHIVE_EXT: '{{if eq .GOOS "windows"}}zip{{else}}tar.gz{{end}}'
DEFAULT_PACKAGE_NAME: '{{.BIN_NAME}}_{{.GOOS}}_{{.GOARCH}}'
PACKAGE_NAME: '{{default .DEFAULT_PACKAGE_NAME .PACKAGE_NAME}}'
cmds:
- task: build:target
vars:
GOOS: '{{.GOOS}}'
GOARCH: '{{.GOARCH}}'
- mkdir -p {{.DIST_DIR}}
- |
set -euo pipefail
rm -rf "{{.DIST_DIR}}/{{.PACKAGE_NAME}}"
mkdir -p "{{.DIST_DIR}}/{{.PACKAGE_NAME}}"
cp "{{.TARGET_DIR}}/{{.BIN_NAME}}{{.BIN_EXT}}" "{{.DIST_DIR}}/{{.PACKAGE_NAME}}/"
cp README.md LICENSE "{{.DIST_DIR}}/{{.PACKAGE_NAME}}/"
if [ "{{.GOOS}}" = "windows" ]; then
(
cd "{{.DIST_DIR}}"
zip -rq "{{.PACKAGE_NAME}}.zip" "{{.PACKAGE_NAME}}"
)
else
tar -C "{{.DIST_DIR}}" -czf "{{.DIST_DIR}}/{{.PACKAGE_NAME}}.tar.gz" "{{.PACKAGE_NAME}}"
fi
run:chaitin:
desc: Run the chaitin demo command
cmds:
- go run . chaitin