-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
72 lines (65 loc) · 1.73 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
SHELL := /bin/bash
.PHONY: doc readme test
define source_env_if_not_ci
@if [ -z "$${CI}" ]; then \
if [ -f ./.env ]; then \
source ./.env; \
else \
echo "No .env file found"; \
exit 1; \
fi \
fi
endef
define RELEASE_TEMPLATE
npx conventional-changelog-cli -p conventionalcommits -i ./CHANGELOG.md -s
git add .
git commit -m "docs(changelog): update"
git push origin HEAD
cargo release $(1) --execute
git push origin HEAD --tags
endef
doc:
cargo doc
open ./target/doc/mistralai_client/index.html
readme:
@echo "Generating README.md from template..."
@> README.md # Clear README.md content before starting
@while IFS= read -r line || [[ -n "$$line" ]]; do \
if [[ $$line == *"<CODE>"* && $$line == *"</CODE>"* ]]; then \
example_path=$$(echo $$line | sed -n 's/.*<CODE>\(.*\)<\/CODE>.*/\1/p'); \
if [ -f $$example_path ]; then \
echo '```rs' >> README.md; \
cat $$example_path >> README.md; \
echo '```' >> README.md; \
else \
echo "Error: Example $$example_path not found." >&2; \
fi; \
else \
echo "$$line" >> README.md; \
fi; \
done < README.template.md
@echo "README.md has been generated."
release-patch:
$(call RELEASE_TEMPLATE,patch)
release-minor:
$(call RELEASE_TEMPLATE,minor)
release-major:
$(call RELEASE_TEMPLATE,major)
test:
@$(source_env_if_not_ci) && \
cargo test --no-fail-fast
test-cover:
@$(source_env_if_not_ci) && \
cargo llvm-cov
test-doc:
@$(source_env_if_not_ci) && \
cargo test --doc --no-fail-fast
test-examples:
@$(source_env_if_not_ci) && \
for example in $$(ls examples/*.rs | sed 's/examples\/\(.*\)\.rs/\1/'); do \
echo "Running $$example"; \
cargo run --example $$example; \
done
test-watch:
@source ./.env && \
cargo watch -x "test -- --nocapture"