-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJustfile
162 lines (131 loc) · 4.14 KB
/
Justfile
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
git := env_var_or_default("GIT", "git")
rustc := env_var_or_default("RUSTC", "rustc")
cargo := env_var_or_default("CARGO", "cargo")
cargo_watch := env_var_or_default("CARGO_WATCH", "cargo-watch")
just := env_var_or_default("JUST", just_executable())
root_dir := invocation_directory()
version := `cargo get version | head --bytes=-1`
sha := `git rev-parse --short HEAD`
_default:
{{just}} --list
#############
# Utilities #
#############
# Print the current version
print-version:
@echo -n "{{version}}"
# Print the current SHA
print-sha:
@echo -n "{{sha}}"
# Ensure a binary is present
ensure-binary bin env_name:
#!/usr/bin/env -S bash -euo pipefail
if [ -z "$(command -v {{bin}})" ]; then
echo "Missing binary [{{bin}}], make sure it is installed & on your PATH (or override it's location with {{env_name}})";
echo "(if the binary is not on your system, you may need to install the package via cargo)";
exit 1;
fi
###########
# Project #
###########
# Set up the project
setup:
@{{just}} ensure-binary rustc RUSTC
@{{just}} ensure-binary cargo CARGO
# Format
fmt:
{{cargo}} fmt
# Lint
lint:
{{cargo}} clippy
# Lint the project
lint-watch:
@{{just}} ensure-binary cargo-watch CARGO_WATCH
@{{cargo}} watch --watch=src --shell 'just lint'
# Build
build:
{{cargo}} build
# Build continuously (development mode)
build-watch:
@{{just}} ensure-binary cargo-watch CARGO_WATCH
{{cargo}} watch -x build
# Build the release version of the binary
build-release:
@{{cargo}} build --release
# Check the project
check:
@{{cargo}} check
# Ensure that the # of commits is what we expect
check-commit-count now before count:
@export COUNT=$(($(git rev-list --count {{now}} --no-merges) - $(git rev-list --count {{before}}))) && \
if [ "$COUNT" != "1" ]; then \
echo -e "[error] number of commits ($COUNT) is *not* {{count}} -- please squash commits"; \
exit 1; \
fi
########
# Test #
########
test_focus := env_var_or_default("TEST", "")
test: test-unit test-int test-examples
# Run unit tests
test-unit:
@{{just}} ensure-binary cargo-nextest CARGO_NEXTEST
@{{cargo}} nextest run -E 'kind(lib)'
@{{cargo}} nextest run -F tokio -E 'kind(lib)'
@{{cargo}} nextest run -F async-std -E 'kind(lib)'
# Run unit tests continuously
test-unit-watch:
@{{just}} ensure-binary cargo-watch CARGO_WATCH
@{{just}} ensure-binary cargo-nextest CARGO_NEXTEST
@{{cargo}} watch -- {{cargo}} nextest run {{test_focus}}
test-int:
@{{just}} ensure-binary cargo-nextest CARGO_NEXTEST
@{{cargo}} nextest run -E 'kind(test)'
test-examples:
@{{cargo}} run --example sync
@{{cargo}} run --example tokio --features=tokio
@{{cargo}} run --example async-std --features=async-std
######################
# Release Management #
######################
publish_crate := env_var_or_default("PUBLISH_CRATE", "no")
changelog_file_path := env_var_or_default("CHANGELOG_FILE_PATH", "CHANGELOG")
# Generate the changelog
changelog:
{{git}} cliff --unreleased --tag={{version}} --prepend={{changelog_file_path}}
# Release a major version
release-major:
{{git}} fetch --tags
{{cargo}} set-version --bump major
{{just}} changelog
{{git}} commit -am "release: v`just print-version`"
{{git}} push
{{git}} tag v`just print-version`
{{git}} push origin v`just print-version`
if [ "{{publish_crate}}" = "yes" ]; then \
{{cargo}} publish; \
fi
# Release a minor version
release-minor:
{{git}} fetch --tags
{{cargo}} set-version --bump minor
{{just}} changelog
{{git}} commit -am "release: v`just print-version`"
{{git}} push
{{git}} tag v`just print-version`
{{git}} push origin v`just print-version`
if [ "{{publish_crate}}" = "yes" ]; then \
{{cargo}} publish; \
fi
# Release a patch version
release-patch:
{{git}} fetch --tags
{{cargo}} set-version --bump patch
{{just}} changelog
{{git}} commit -am "release: v`just print-version`"
{{git}} push
{{git}} tag v`just print-version`
{{git}} push origin v`just print-version`
if [ "{{publish_crate}}" = "yes" ]; then \
{{cargo}} publish; \
fi