forked from formancehq/ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
226 lines (197 loc) · 6.28 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
# https://taskfile.dev
version: "3"
dotenv:
- .env
vars:
PKG: "./..."
FAILFAST: "-failfast"
TIMEOUT: "10m"
RUN: ".*"
TAGS: "-tags json1,netgo"
BENCH_RESULTS_DIR: "/tmp/benchmarks"
BENCH_RESULTS_FILE: "/tmp/benchmarks/ledger.txt"
BENCH_CPU_PROFILE: "/tmp/benchmarks/ledger.cpu.prof"
BENCH_MEM_PROFILE: "/tmp/benchmarks/ledger.mem.prof"
VERBOSE: "false"
tasks:
default:
cmds:
- task: lint
- task: tests:local
lint:
cmds:
- golangci-lint run --fix {{if eq .VERBOSE "true"}}-v{{end}}
tests:
cmds:
- go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic {{.PKG}}
tests:local:
cmds:
- task: tests:local:sqlite
- task: tests:local:postgres
tests:local:sqlite:
cmds:
- >
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} {{.FAILFAST}} -coverpkg {{.PKG}}
-coverprofile coverage.out -covermode atomic
-run={{.RUN}} -timeout {{.TIMEOUT}} {{.PKG}} |
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' |
sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/'' |
sed ''/RUN/s//$(printf "\033[34mRUN\033[0m")/''
- task: print:coverage
tests:local:postgres:
deps: [postgres]
cmds:
- >
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} {{.FAILFAST}} -coverpkg {{.PKG}}
-coverprofile coverage.out -covermode atomic
-run={{.RUN}} -timeout {{.TIMEOUT}} {{.PKG}} |
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' |
sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/'' |
sed ''/RUN/s//$(printf "\033[34mRUN\033[0m")/''
- task: print:coverage
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"
print:coverage:
cmds:
- go tool cover -html=coverage.out -o coverage.html
- cov-report ./coverage.out
- echo "To open the html coverage file, use one of the following commands:"
- echo "open coverage.html on mac"
- echo "xdg-open coverage.html on linux"
silent: true
bench:
deps: [postgres]
cmds:
- mkdir -p {{.BENCH_RESULTS_DIR}}
- >
go test {{.TAGS}} ./pkg/storage/sqlstorage
-run=XXX -bench={{.RUN}} -benchmem -timeout 1h
-cpuprofile {{.BENCH_CPU_PROFILE}} -memprofile {{.BENCH_MEM_PROFILE}}
| tee {{.BENCH_RESULTS_FILE}}
- benchstat {{.BENCH_RESULTS_FILE}}
env:
NUMARY_STORAGE_DRIVER: "postgres"
NUMARY_STORAGE_POSTGRES_CONN_STRING: "postgresql://ledger:[email protected]/ledger"
bench:cpu:
cmds:
- go tool pprof -http=":" {{.BENCH_CPU_PROFILE}}
bench:mem:
cmds:
- go tool pprof -http=":" {{.BENCH_MEM_PROFILE}}
install:
deps:
- install:golangci-lint
- install:cov-report
- install:perf
install:golangci-lint:
cmds:
- >
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |
sh -s -- -b $(go env GOPATH)/bin latest
- golangci-lint --version
install:cov-report:
cmds:
- go install github.com/go-phorce/cov-report/cmd/cov-report
install:perf:
- go install golang.org/x/perf/cmd/...@latest
postgres:
cmds:
- docker compose up -d postgres
clean:
cmds:
- go clean
- rm -f {{.SERVICE}} coverage.out coverage.html
- docker compose down -v
sdk:template:
desc: Extract templates
dir: ./sdk
preconditions:
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task template -- go")
cmds:
- >
docker run --rm -w /local -v ${PWD}:/local openapitools/openapi-generator-cli:latest author
template -g {{.CLI_ARGS}} -o templates/{{.CLI_ARGS}}
sdk:generate:
desc: Generate client code
dir: ./sdk
preconditions:
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task generate -- go")
cmds:
- wget https://raw.githubusercontent.com/formancehq/ledger/{{.VERSION}}/pkg/api/controllers/swagger.yaml -O swagger.yaml
- sed -i -e "s/LEDGER_VERSION/{{.VERSION}}/g" swagger.yaml
- >
docker run --rm -w /local -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate
-i ./swagger.yaml
-g {{ (split "-" .CLI_ARGS)._0 }}
-c ./configs/{{.CLI_ARGS}}.yaml
-o ./sdks/{{.CLI_ARGS}}
--git-user-id=formancehq
--git-repo-id=numary-sdk-{{.CLI_ARGS}}
-p packageVersion={{.VERSION}}
sdk:test:
desc: Test client code
dir: ./sdk
preconditions:
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task test -- go")
- sh: "[[ -e sdks/{{.CLI_ARGS}}/Taskfile.yml ]]"
msg: "Not Taskfile found. You have to create a taskfile in ./sdks/{{.CLI_ARGS}}/ with a 'test' task"
vars:
RANDOM:
sh: "echo $$"
cmds:
- |
cd ./sdks/{{.CLI_ARGS}}
task test
goreleaser:test:pkg:
desc: Test a package
cmds:
- docker run --platform linux/{{.Platform}} --rm --workdir /tmp -v $PWD/dist:/tmp {{.Image}} sh -c '{{.Cmd}} && goreleaser --version'
goreleaser:test:rpm:
desc: Tests rpm packages
vars:
rpm: "rpm --nodeps -ivh"
cmds:
- task: goreleaser:test:pkg
vars:
Platform: "amd64"
Image: fedora
Cmd: "{{.rpm}} numary_*_linux_amd64.rpm"
- task: goreleaser:test:pkg
vars:
Platform: "arm64"
Image: fedora
Cmd: "{{.rpm}} numary_*_linux_arm64.rpm"
goreleaser:test:deb:
desc: Tests deb packages
vars:
dpkg: "dpkg --ignore-depends=git -i"
cmds:
- task: goreleaser:test:pkg
vars:
Platform: "amd64"
Image: ubuntu
Cmd: "{{.dpkg}} numary_*_linux_amd64.deb"
- task: goreleaser:test:pkg
vars:
Platform: "arm64"
Image: ubuntu
Cmd: "{{.dpkg}} numary_*_linux_arm64.deb"
run:
cmds:
- docker compose up -d --remove-orphans
stop:
cmds:
- docker compose stop
ps:
cmds:
- docker compose ps
rm:
deps: [stop]
cmds:
- docker compose rm -f
- docker volume prune -f
- rm {{.BENCH_CPU_PROFILE}} {{.BENCH_MEM_PROFILE}}