-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
233 lines (165 loc) · 9.33 KB
/
Copy pathjustfile
File metadata and controls
233 lines (165 loc) · 9.33 KB
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
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
rustflags := env("RUSTFLAGS", "") + (if env("CI", "") != "" { " --cfg ci" } else { "" })
export RUSTFLAGS := rustflags
toolchain := ""
tool := "cargo"
cargo := tool + (if toolchain != "" { " +" + toolchain } else { "" })
cargo_nightly := tool + " +nightly"
cargo_hack := cargo + " hack"
cargo_tarpaulin := cargo + " tarpaulin"
cargo_llvm_cov := cargo_nightly + " llvm-cov"
all_features := "true"
all_features_flag := if all_features == "true" { "--all-features" } else { "" }
feature_powerset_flag := if all_features == "true" { "--feature-powerset" } else { "" }
all_targets := "true"
all_targets_flag := if all_targets == "true" { "--all-targets" } else { "" }
message_format := ""
message_format_flag := if message_format != "" { "--message-format " + message_format } else { "" }
target_tuple := ""
target_tuple_flag := if target_tuple != "" { "--target " + target_tuple } else { "" }
release := "false"
release_flag := if release == "true" { "--release" } else { "" }
workspace := "true"
package := ""
workspace_flag := if workspace != "true" { "" } else if package != "" { "" } else { "--workspace" }
all_flag := if workspace_flag == "" { "" } else { "--all" }
package_flag := if package != "" { "--package " + package } else { workspace_flag }
package_all_flag := if package != "" { "--package " + package } else { all_flag }
package_only_flag := if package != "" { "--package " + package } else { "" }
warnings_as_errors := "true"
clippy_flags := if warnings_as_errors == "true" { "-- -D warnings" } else { "" }
force_prep := "false"
force_prep_flag := if force_prep == "true" { "--force" } else { "" }
open := if env("CI", "") == "" { "true" } else { "false" }
open_flag := if open == "true" { "--open" } else { "" }
no_deps := if toolchain == "nightly" { "true" } else { "false" }
no_deps_flag := if no_deps == "true" { "--no-deps" } else { "" }
just := "just all_features=" + all_features + " all_targets=" + all_targets + " message_format=" + message_format + " target_tuple=" + target_tuple + " release=" + release + " workspace=" + workspace + " package=" + package + " warnings_as_errors=" + warnings_as_errors + " force_prep=" + force_prep + " open=" + open + " no_deps=" + no_deps
rustdoc_extra_flags := if toolchain == "nightly" { "--cfg docsrs" } else { "" }
skip_test_reqs_value := "running"
# ----- Project-specific variables -----
lambda_package := if package != "" { package } else { "aoc_leaderbot_aws_lambda_impl" }
lambda_package_flag := "--package " + lambda_package
lambda_bin_flag := "--binary-name " + lambda_package
output_format := ""
output_format_flag := if output_format != "" { "--output-format " + output_format } else { "" }
arm64 := "true"
arm64_flag := if arm64 == "true" { "--arm64" } else { "" }
cargo_lambda := cargo + " lambda"
[private]
default:
@just --list
@_before-test: (_dynamo "up")
@_after-test: (_dynamo "down")
@_check-test-reqs: (_check-container-state "aoc_leaderbot-dynamodb-local")
@_run-tests *cmd:
{{ if env('CI', '') != '' { cmd } else if `just _check-test-reqs` == skip_test_reqs_value { cmd } else { just + " _run-with-test-reqs " + cmd } }}
_run-with-test-reqs *cmd: _before-test && _after-test
{{cmd}}
# Run an executable
run bin_name="" *extra_args: (_run-it "--bin" bin_name extra_args)
# Run an example
teach example_name *extra_args: (_run-it "--example" example_name extra_args)
_run-it run_param run_param_value *extra_args:
{{cargo}} run {{package_only_flag}} {{all_features_flag}} {{target_tuple_flag}} {{release_flag}} {{ if run_param_value != '' { run_param + ' ' + run_param_value } else { '' } }} {{ if extra_args != '' { '-- ' + extra_args } else { '' } }}
# Run `cargo hack clippy` for the feature powerset and rustfmt
tidy: clippy fmt
# Run `cargo hack clippy` for the feature powerset
clippy *extra_args:
{{cargo_hack}} clippy --target-dir target/clippy-target {{package_flag}} {{all_targets_flag}} {{feature_powerset_flag}} {{message_format_flag}} {{target_tuple_flag}} {{extra_args}} {{clippy_flags}}
# Run rustfmt
fmt *extra_args:
{{cargo_nightly}} fmt {{package_all_flag}} {{message_format_flag}} {{extra_args}}
# Run `cargo check`
check *extra_args:
{{cargo}} check {{package_flag}} {{all_targets_flag}} {{all_features_flag}} {{message_format_flag}} {{target_tuple_flag}} {{release_flag}} {{extra_args}}
# Run `cargo hack check` for the feature powerset
check-powerset *extra_args:
{{cargo_hack}} check --target-dir target/check-powerset-target {{package_flag}} --no-dev-deps --lib --bins {{feature_powerset_flag}} {{message_format_flag}} {{target_tuple_flag}} {{release_flag}} {{extra_args}}
# Run `cargo build`
build *extra_args:
{{cargo}} build {{package_flag}} {{all_targets_flag}} {{all_features_flag}} {{message_format_flag}} {{target_tuple_flag}} {{release_flag}} {{extra_args}}
# Run `cargo test`
@test *extra_args: (_run-tests cargo "test" package_flag all_features_flag message_format_flag target_tuple_flag release_flag extra_args)
# Run `cargo update` to update dependencies in Cargo.lock
update *extra_args:
{{cargo}} update {{extra_args}}
# Run `cargo tarpaulin` to produce code coverage
@tarpaulin *extra_args: (_run-tests cargo_tarpaulin "--target-dir target/tarpaulin-target" extra_args)
{{ if open == "true" { "just _open-tarpaulin" } else { "" } }}
[unix]
@_open-tarpaulin:
open tarpaulin-report.html
[windows]
@_open-tarpaulin:
./tarpaulin-report.html
# Run `cargo llvm-cov` to produce code coverage
@llvm-cov *extra_args: (_run-tests cargo_llvm_cov "--codecov --output-path codecov.json" package_flag all_targets_flag all_features_flag target_tuple_flag extra_args)
{{cargo_llvm_cov}} report --html {{open_flag}}
# Generate documentation with rustdoc
doc: _doc
_doc $RUSTDOCFLAGS=("-D warnings " + rustdoc_extra_flags):
{{cargo}} doc {{open_flag}} {{no_deps_flag}} {{package_flag}} {{all_features_flag}} {{message_format_flag}}
# Check doc coverage with Nightly rustdoc
doc-coverage: _doc-coverage
_doc-coverage $RUSTDOCFLAGS="-Z unstable-options --show-coverage":
{{cargo_nightly}} doc --no-deps {{package_flag}} {{all_features_flag}} {{message_format_flag}}
[private]
minimize:
{{cargo_hack}} --remove-dev-deps {{package_flag}}
{{cargo_nightly}} update -Z minimal-versions
# Run `cargo minimal-versions check`
check-minimal: prep _check-minimal-only && unprep
_check-minimal-only: (_rimraf "target/check-minimal-target")
{{cargo}} minimal-versions check --target-dir target/check-minimal-target {{package_flag}} --lib --bins {{all_features_flag}} {{message_format_flag}}
# Run `cargo msrv` with `cargo minimal-versions check`
msrv: (prep "--manifest-backup-suffix .msrv-prep.outer.bak") && (unprep "--manifest-backup-suffix .msrv-prep.outer.bak")
{{cargo}} msrv find -- {{just}} _check-minimal-only
# Run `cargo msrv` with `cargo check`
msrv-full *extra_args: (prep "--manifest-backup-suffix .msrv-prep.outer.bak --no-merge-pinned-dependencies") && (unprep "--manifest-backup-suffix .msrv-prep.outer.bak")
{{cargo}} msrv find -- {{just}} _msrv-check {{extra_args}}
_msrv-check *extra_args: (_rimraf "target/msrv-target") (check "--target-dir target/msrv-target" extra_args)
# Perform `cargo publish` dry-run on a package
test-package *extra_args: (_publish "--dry-run" extra_args)
# Run `cargo publish` to publish crates
publish *extra_args: (_publish extra_args)
_publish *extra_args:
{{cargo}} publish --locked {{package_flag}} {{all_features_flag}} {{target_tuple_flag}} {{extra_args}}
# Run `cargo msrv-prep`
prep *extra_args:
{{cargo_nightly}} msrv-prep {{package_flag}} --backup-root-manifest {{force_prep_flag}} {{extra_args}}
# Run `cargo msrv-unprep`
unprep *extra_args:
{{cargo_nightly}} msrv-unprep {{package_flag}} --backup-root-manifest {{extra_args}}
# ----- Utilities -----
# Removes a directory (like `rm -rf`)
@_rimraf target_dir:
{{ if path_exists(target_dir) == "true" { "just _rimraf-it '" + target_dir + "'" } else { "" } }}
[unix]
@_rimraf-it target_dir:
rm -rf '{{target_dir}}'
[windows]
@_rimraf-it target_dir:
Remove-Item "{{target_dir}}" -Recurse
# Prints state of a docker container to stdout
@_check-container-state name:
docker container ls --filter "name={{name}}" --format "{{{{.State}}"
# ----- Project-specific recipes -----
# Run `docker compose [up/down]` to start/stop local Dynamo as needed
@dynamo *extra_args:
{{ "just _dynamo " + (if `just _check-test-reqs` != skip_test_reqs_value { "up" } else { "down" }) + " " + extra_args }}
_dynamo command *extra_args:
docker compose {{ if command == "up" { 'up -d' } else { command } }} {{extra_args}}
# Run `cargo lambda watch` to start the lambda locally
watch *extra_args:
{{cargo_lambda}} watch {{lambda_package_flag}} {{all_features_flag}} {{target_tuple_flag}} {{release_flag}} {{extra_args}}
# Run `cargo lambda build`
build-lambda *extra_args:
{{cargo_lambda}} build {{lambda_package_flag}} {{all_features_flag}} {{message_format_flag}} {{release_flag}} {{arm64_flag}} {{extra_args}}
# Run `cargo lambda deploy` using `.env` file
deploy-lambda *extra_args:
{{cargo_lambda}} deploy {{lambda_bin_flag}} {{output_format_flag}} --env-file .env {{extra_args}}
# Run tool to post test message to Slack
slack *extra_args: (teach "post_test_message_to_slack" extra_args)
# Run tool to create DynamoDB table for the AWS Lambda bot impl
prepare-dynamo *extra_args: (run "prepare_dynamodb" extra_args)