-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_tool.cue
238 lines (196 loc) · 6.41 KB
/
make_tool.cue
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
package xtemplate
import (
"strings"
"list"
"tool/exec"
"tool/file"
"tool/os"
)
#vars: {
rootdir: string
testdir: string
gitver: string
version: string
ldflags: string
latest: string
env: {[string]: string}
}
meta: {
vars: #vars & {
rootdir: strings.TrimSpace(_commands.reporoot.stdout)
testdir: "\(rootdir)/test"
gitver: strings.TrimSpace(_commands.gitver.stdout)
version: strings.TrimSpace(_commands.version.stdout)
ldflags: "-X 'github.com/infogulch/xtemplate/app.version=\(version)'"
latest: strings.TrimSpace(_commands.latest.stdout)
env: {for k, v in _commands.env if k != "$id" {(k): v}}
}
_commands: {
reporoot: exec.Run & {
cmd: ["bash", "-c", "git rev-parse --show-toplevel"]
stdout: string
}
gitver: exec.Run & {
cmd: ["bash", "-c", "git describe --exact-match --tags --match='v*' 2> /dev/null || git rev-parse --short HEAD"]
dir: vars.rootdir
stdout: string
}
version: exec.Run & {
cmd: ["bash", "-c", "go list -f {{.Version}} -m github.com/infogulch/xtemplate@\(vars.gitver)"]
dir: vars.rootdir
stdout: string
}
latest: exec.Run & {
cmd: ["bash", "-c", "git tag -l --sort -version:refname | head -n 1"]
dir: vars.rootdir
stdout: string
}
env: os.Environ
}
}
task: build: {
vars: #vars
outfile: *"xtemplate" | string
gobuild: exec.Run & {
env: {[string]: string}
cmd: ["go", "build", "-ldflags", vars.ldflags, "-buildmode", "exe", "-o", outfile, "./cmd"]
dir: vars.rootdir
mustSucceed: true
}
}
task: run: {
vars: #vars
rmdataw: file.RemoveAll & {path: "\(vars.testdir)/dataw"}
mkdataw: file.Mkdir & {path: "\(vars.testdir)/dataw", $after: rmdataw.$done}
start: exec.Run & {
cmd: ["bash", "-c", "./xtemplate --loglevel -4 -d DB:sql:sqlite3:file:./dataw/test.sqlite -d FS:fs:./data --config-file config.json &>xtemplate.log &"]
dir: vars.testdir
$after: mkdataw.$done
}
}
task: test: {
vars: #vars
port: int | *8080
list: file.Glob & {glob: "\(vars.testdir)/tests/*.hurl"}
ready: exec.Run & {cmd: "curl -X GET --retry-all-errors --retry 5 --retry-connrefused --retry-delay 1 http://localhost:\(port)/ready --silent", stdout: "OK"}
hurl: exec.Run & {
cmd: ["hurl", "--continue-on-error", "--no-output", "--test", "--report-html", "report", "--connect-to", "localhost:8080:localhost:\(port)"] + list.files
dir: vars.testdir
after: ready.$done
}
}
task: gotest: {
vars: #vars
gotest: exec.Run & {
cmd: ["bash", "-c", "go test -v ./... >\(vars.testdir)/gotest.log"]
dir: vars.rootdir
}
}
task: build_test: {
vars: #vars
build: task.build & {"vars": vars, outfile: "\(vars.testdir)/xtemplate"}
run: task.run & {"vars": vars, start: $after: build.gobuild.$done}
test: task.test & {"vars": vars, ready: $after: run.start.$done}
kill: exec.Run & {cmd: "pkill xtemplate", $after: test.hurl.$done}
}
task: dist: {
vars: #vars
rmdist: file.RemoveAll & {path: "\(vars.rootdir)/dist"}
oses: ["linux", "darwin", "windows"]
arches: ["amd64", "arm64"]
matrix: [for os in oses for arch in arches {GOOS: os, GOARCH: arch}]
for env in matrix {
(env.GOOS + "_" + env.GOARCH): {
dir: "\(vars.rootdir)/dist/xtemplate-\(env.GOARCH)-\(env.GOOS)"
exe: string | *"xtemplate"
if env.GOOS == "windows" {
exe: "xtemplate.exe"
}
mkdir: file.MkdirAll & {path: dir, $after: rmdist.$done}
build: task.build & {"vars": vars, outfile: "\(dir)/\(exe)", gobuild: {$after: mkdir.$done, "env": env & vars.env}}
cp: exec.Run & {cmd: ["cp", "README.md", "LICENSE", "\(dir)"], $after: mkdir.$done}
zip: exec.Run & {cmd: ["zip", "-jqr6", "\(dir)_\(vars.version).zip", dir], $after: cp.$done && build.$done}
}
}
}
task: build_docker: {
vars: #vars
tags: [
"infogulch/xtemplate:\(vars.version)",
if vars.version == vars.latest {"infogulch/xtemplate:latest"},
]
build: exec.Run & {
cmd: ["docker", "build"] + list.FlattenN([for t in tags {["-t", t]}], 1) + ["--build-arg", "LDFLAGS=\(vars.ldflags)", "--progress=plain", "."]
dir: vars.rootdir
}
}
task: test_docker: {
vars: #vars
build: exec.Run & {
cmd: ["docker", "build", "-t", "xtemplate-test", "--target", "test", "--build-arg", "LDFLAGS=\(vars.ldflags)", "."]
dir: vars.rootdir
}
run: exec.Run & {
cmd: ["docker", "run", "-d", "--rm", "--name", "xtemplate-test", "-p", "8081:80", "xtemplate-test"]
$after: build.$done
}
test: task.test & {"vars": vars, port: 8081, ready: $after: run.$done}
stop: exec.Run & {cmd: "docker stop xtemplate-test", $after: test.hurl.$done} // be nice if we can always run this even if previous steps fail
}
task: push_docker: {
tags: [...string]
for tag in tags {
("push-" + tag): exec.Run & {
cmd: ["docker", "push", tag]
}
}
}
task: build_caddy: {
vars: #vars
xbuild: exec.Run & {
cmd: ["bash", "-c",
"xcaddy build " +
"--with github.com/infogulch/xtemplate-caddy " +
"--with github.com/infogulch/xtemplate=. " +
"--with github.com/infogulch/xtemplate/providers=./providers " +
"--with github.com/infogulch/xtemplate/providers/nats=./providers/nats " +
"--with github.com/mattn/go-sqlite3 " +
"--output \(vars.testdir)/caddy " +
"&>\(vars.testdir)/xcaddy.log",
]
dir: vars.rootdir
env: vars.env & {CGO_ENABLED: "1"}
}
}
task: run_caddy: {
vars: #vars
rmdataw: file.RemoveAll & {path: "\(vars.testdir)/dataw"}
mkdataw: file.Mkdir & {path: "\(vars.testdir)/dataw", $after: rmdataw.$done}
start: exec.Run & {
cmd: ["bash", "-c", "./caddy start --config caddy.json &>xtemplate.caddy.log"]
dir: vars.testdir
$after: mkdataw.$done
}
}
task: build_test_caddy: {
vars: #vars
build: task.build_caddy & {"vars": vars}
run: task.run_caddy & {"vars": vars, start: $after: build.xbuild.$done}
test: task.test & {"vars": vars, port: 8082, ready: $after: run.start.$done}
kill: exec.Run & {cmd: "pkill caddy", $after: test.hurl.$done} // is there a better way?
}
command: {
for k, t in task {
(k): {cfg: meta, vars: cfg.vars, t}
}
}
command: ci: {
cfg: meta
gotest: task.gotest & {"vars": cfg.vars}
build_test: task.build_test & {"vars": cfg.vars}
build_test_caddy: task.build_test_caddy & {"vars": cfg.vars, run: rmdataw: $after: build_test.kill.$done}
dist: task.dist & {"vars": cfg.vars, rmdist: $after: build_test.kill.$done}
test_docker: task.test_docker & {"vars": cfg.vars}
build_docker: task.build_docker & {"vars": cfg.vars, build: $after: test_docker.stop.$done}
push_docker: task.push_docker & {tags: build_docker.tags} & {[=~"^push"]: $after: build_docker.build.$done}
}