-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
358 lines (285 loc) · 10.8 KB
/
Makefile
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
ARGUMENTS = $(filter-out $@,$(MAKECMDGOALS))
GET_ARGUMENT = $(strip $(call word,$(1),$(ARGUMENTS)))
# Hurl variables
export HURL_prev_month := $(shell date +%s%3N -d '-1 month')
export HURL_next_month := $(shell date +%s%3N -d '+1 month')
export HURL_next_year := $(shell date +%s%3N -d '+1 year')
HURL_user_token := $(shell curl --silent --header \
'Content-Type: application/json' \
--data '{"email":"admin","password":"admin"}' \
'http://localhost:3000/_/user/token/value' | jq -r '.data[0].token')
HURL_user_token := "Bearer $(HURL_user_token)"
export HURL_user_token
export HURL_host = http://localhost:3000
# Add this at the beginning of your Makefile
.PHONY: help
help:
@echo "Available commands:"
@echo
@echo "Build:"
@echo " build-server - Build the query server in release mode"
@echo " build-server-watch - Watch and build the query server, with debug logging"
@echo " build-cli - Build the CLI with the dist profile"
@echo
@echo "Changelog:"
@echo " update-changelog - Update CHANGELOG.md with changes between the last two release commits"
@echo
@echo "Clean:"
@echo " clean - Remove Cargo.lock and clean the build artifacts"
@echo " clean-dbs - Remove all database files"
@echo " clean-hurl-dbs - Remove Hurl-specific database files"
@echo
@echo "CLI:"
@echo " install-esbuild - Install esbuild"
@echo " cli - Run the CLI"
@echo
@echo "Coverage:"
@echo " install-llvm-cov - Install cargo-llvm-cov"
@echo " coverage-clean - Clean coverage data"
@echo " coverage - Run coverage analysis"
@echo " coverage-watch - Watch and run coverage analysis"
@echo " coverage-report - Generate coverage report"
@echo " coverage-html - Generate HTML coverage report"
@echo " coverage-lcov - Generate LCOV coverage report"
@echo
@echo "Distribution:"
@echo " install-cargo-dist - Install cargo-dist"
@echo " dist-plan - Plan distribution"
@echo
@echo "Documentation:"
@echo " docs - Generate and open documentation"
@echo
@echo "Formatting:"
@echo " fmt - Format all code"
@echo " fmt-server - Format server code"
@echo " fmt-cli - Format CLI code"
@echo
@echo "Hurl:"
@echo " install-hurl - Install Hurl"
@echo " hurl - Run Hurl tests"
@echo " hurl-test - Run Hurl tests in test mode"
@echo " hurl-test-all - Run all Hurl tests in test mode"
@echo
@echo "Linting:"
@echo " lint - Run clippy on all targets"
@echo
@echo "npm:"
@echo " npm-publish - Publish npm packages"
@echo " npm-prerelease - Publish prerelease npm packages"
@echo " npm-un-prerelease - Unpublish prerelease npm packages"
@echo "Release:"
@echo " release - Create a new release version"
@echo " release-rollback - Rollback a release version"
@echo
@echo "Run:"
@echo " install-watch - Install cargo-watch"
@echo " run - Run the server"
@echo " run-cli - Run the CLI"
@echo " run-release - Run the server in release mode"
@echo " run-cli-release - Run the CLI in release mode"
@echo " dev - Run the server in development mode"
@echo " dev-build - Watch and build the server"
@echo " dev-cli - Watch and run the CLI"
@echo " dev-proxy - Run the server with proxy enabled"
@echo " dev-bun - Run the Bun development server"
@echo
@echo "Testing:"
@echo " install-nextest - Install cargo-nextest"
@echo " test - Run tests"
@echo " nextest - Run tests with nextest"
@echo " nextest-query - Run query tests with nextest"
@echo " nextest-query-server - Run query-server tests with nextest"
@echo " nextest-match - Run specific tests with nextest"
@echo " test-watch - Watch and run tests"
@echo
@echo "Tagging:"
@echo " tag-delete - Delete a version tag"
@echo
@echo "For more details on each command, check the Makefile"
# Build
build-server:
cargo build --package=query-server --release
build-server-watch:
cargo watch -c --ignore .dbs -x check -x clippy --shell "RUST_LOG=debug cargo build --package=query-server | bunyan"
build-cli:
cargo build --package=query --profile dist
# Changelog
changelog:
@release_commit=$$(git log --grep="release: version" --format="%H" -n 1); \
if [ -z "$$release_commit" ]; then \
echo "Error: No 'release' commit found."; \
exit 1; \
fi; \
last_commit=$$(git log --format="%H" -n 1); \
git cliff $$release_commit..$$last_commit --tag $(ARGUMENTS) --prepend CHANGELOG.md; \
echo "CHANGELOG.md has been updated with changes between commits:"; \
echo "Last Commit: $$last_commit"; \
echo "Previous Release Commit: $$release_commit"
# Clean
clean:
rm -rf Cargo.lock | cargo clean
clean-dbs:
rm -rf .dbs && rm -rf .tests
clean-hurl-dbs:
rm -rf .dbs/hurl*.sql
# CLI
install-esbuild:
curl -fsSL https://esbuild.github.io/dl/latest | sh
cli:
cp -r esbuild target/debug/
target/debug/query $(ARGUMENTS)
# Coverage
install-llvm-cov:
cargo install cargo-llvm-cov
coverage-clean:
cargo llvm-cov clean --workspace
coverage:
cargo llvm-cov --workspace --exclude query nextest
coverage-watch:
cargo watch -c -s "make coverage-lcov"
coverage-report:
cargo llvm-cov report
coverage-html:
cargo llvm-cov --workspace --exclude query --html nextest
coverage-lcov: coverage-clean
cargo llvm-cov --workspace --exclude query --lcov --output-path target/llvm-cov-target/lcov.info nextest
# Dist
install-cargo-dist:
cargo install cargo-dist --locked
dist-plan:
cargo dist plan
# Docs
docs:
cargo doc --package=query-server --open
# Format
fmt: fmt-server
fmt-server:
cargo fmt --all --package=query-server -- --check
fmt-cli:
cargo fmt --all --package=query -- --check
# Hurl
install-hurl:
cargo install hurl
hurl: clean-hurl-dbs
hurl --verbose --continue-on-error --variables-file .env --file-root hurl $(ARGUMENTS)
hurl-test: clean-hurl-dbs
hurl --test --continue-on-error --variables-file .env --file-root hurl $(ARGUMENTS)
hurl-test-all: clean-hurl-dbs
hurl --test --continue-on-error --variables-file .env --file-root hurl hurl/**/*.hurl hurl/**/**/*.hurl
hurl-integration: clean-hurl-dbs
hurl --test --continue-on-error --jobs=1 --file-root ./hurl hurl/**/*.hurl hurl/**/**/*.hurl
hurl-function:
@name="$(ARGUMENTS)"; \
if [ -f "hurl/function/$$name.js" ]; then \
output=$$(node hurl/function/$$name.js); \
sed -i "s/\"function\": \[.*\]/\"function\": $$output/" hurl/function/$$name.hurl 2>/dev/null && \
echo "Updated hurl/function/$$name.hurl" || \
echo "Error: hurl/function/$$name.hurl not found"; \
else \
echo "Error: hurl/function/$$name.js not found"; \
fi
hurl-bytes:
node hurl/file_to_bytes.mjs $(call GET_ARGUMENT,1) $(call GET_ARGUMENT,2)
# Lint
lint:
cargo clippy --all-targets --all-features --workspace
# npm
npm-publish:
npm publish https://github.com/gc-victor/query/releases/download/v$(ARGUMENTS)/query-npm-package.tar.gz
npm publish https://github.com/gc-victor/query/releases/download/v$(ARGUMENTS)/query-server-npm-package.tar.gz
npm-prerelease:
@if [ "$(findstring prerelease,$(ARGUMENTS))" = "prerelease" ]; then \
npm publish https://github.com/gc-victor/query/releases/download/v$(ARGUMENTS)/query-npm-package.tar.gz --tag prerelease-$(VERSION) ;\
npm publish https://github.com/gc-victor/query/releases/download/v$(ARGUMENTS)/query-server-npm-package.tar.gz --tag prerelease-$(VERSION) ;\
fi
npm-un-prerelease:
@if [ "$(findstring prerelease,$(ARGUMENTS))" = "prerelease" ]; then \
npm unpublish @qery/query@$(ARGUMENTS) --force ;\
npm unpublish @qery/query-server@$(ARGUMENTS) --force ;\
fi
# Release
release:
perl -pi -e 's/version = "$(call GET_ARGUMENT,1)"/version = "$(call GET_ARGUMENT,2)"/g' ./Cargo.toml
@if [ "$(findstring prerelease,$(call GET_ARGUMENT,2))" = "prerelease" ]; then \
perl -pi -e 's/targets = \["aarch64\-apple\-darwin", "x86_64\-apple\-darwin", "x86_64\-unknown\-linux\-gnu"]/targets = \["x86_64\-unknown\-linux\-gnu"\]/g' ./dist-workspace.toml; \
fi
cargo check --workspace
git add Cargo.lock
git add Cargo.toml
git add dist-workspace.toml
make changelog $(call GET_ARGUMENT,2)
git add CHANGELOG.md
git commit -m "release: version $(call GET_ARGUMENT,2)"
git push --force-with-lease
git tag v$(call GET_ARGUMENT,2)
git push --tags
release-rollback:
@read -p "Are you sure you want to rollback the tag version $(ARGUMENTS)? [Y/n] " REPLY; \
if [ "$$REPLY" = "Y" ] || [ "$$REPLY" = "y" ] || [ "$$REPLY" = "" ]; then \
git reset --soft HEAD~1; \
git reset HEAD Cargo.lock; \
git reset HEAD Cargo.toml; \
git reset HEAD CHANGELOG.md; \
git reset HEAD dist-workspace.toml; \
git checkout -- Cargo.lock; \
git checkout -- Cargo.toml; \
git checkout -- CHANGELOG.md; \
git checkout -- dist-workspace.toml; \
git tag -d v$(ARGUMENTS); \
git push origin --delete v$(ARGUMENTS); \
git push --force-with-lease; \
else \
echo "Aborted."; \
fi
# Run
install-watch:
cargo install cargo-watch
run:
RUST_LOG=info cargo run --package=query-server -q | bunyan
run-cli:
RUST_LOG=info cargo run --package=query
run-release:
RUST_LOG=info cargo run --package=query-server --release -q | bunyan
run-cli-release:
RUST_LOG=info cargo run --package=query --profile dist
dev:
cargo watch -c --ignore .dbs -x check -x clippy --shell "RUST_LOG=debug cargo run --package=query-server | bunyan"
dev-server:
cargo watch -c --ignore .dbs -x check -x clippy --shell "cargo build --package=query-server"
dev-cli:
cargo watch --ignore .dbs -x check -x clippy --shell "make run-cli -s"
dev-proxy:
export QUERY_SERVER_PROXY=true && cargo watch --ignore .dbs --shell "make run -s" & make dev-bun
dev-bun:
touch .dbs/kv.sql
export QUERY_SERVER_DBS_PATH=".dbs"
bun examples/proxy/index.ts
# Test
install-nextest:
cargo install cargo-nextest --locked
test:
cargo test -- --test-threads=1
nextest:
cargo nextest run
nextest-query:
cargo nextest run --package=query
nextest-query-server:
cargo nextest run --package=query-server
nextest-match:
cargo nextest run --filter-expr 'test($(ARGUMENTS))'
test-watch:
cargo watch -c -s "make test"
test-js:
find crates/runtime/src/js -name '*.test.js' -exec node {} \;
# Tag
tag-delete:
@read -p "Are you sure you want to delete the tag version $(ARGUMENTS)? [Y/n] " REPLY; \
if [ "$$REPLY" = "Y" ] || [ "$$REPLY" = "y" ] || [ "$$REPLY" = "" ]; then \
git tag -d v$(ARGUMENTS); \
git push origin --delete v$(ARGUMENTS); \
else \
echo "Aborted."; \
fi
# catch anything and do nothing
%:
@: