-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy path.justfile
executable file
·162 lines (134 loc) · 4.29 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
#!/usr/bin/env just --justfile
repo := `git rev-parse --show-toplevel`
profile := env_var_or_default('PROFILE', "dev")
github-event-name := env_var_or_default('GITHUB_EVENT_NAME', "none")
######################################################################
## Helper to print a message when calling `just`
######################################################################
[private]
default:
@echo "Usage: just <recipe>"
@just list-repo-recipes
@echo "For further information, run 'just --help'"
# List recipes in this file and from the calling directory
[no-cd]
[private]
usage:
@echo "Usage: just <recipe>"
@just list-local-recipes
@just list-repo-recipes
@echo "For further information, run 'just --help'"
[no-cd]
[private]
list-local-recipes:
@echo '\nAvailable recipes:'
@just --list --unsorted --list-heading ''
[private]
list-repo-recipes:
@echo "\nRepository recipes:"
@just --list --unsorted --list-heading ''
######################################################################
## Helper to run a global command
######################################################################
# Runs yarn in the repository root
[private]
yarn *args:
yarn {{args}}
######################################################################
## Helper to run a command on an environmental condition
######################################################################
# Runs the provided command if `PROFILE` starts with `"dev"`
[private]
[no-cd]
in-dev +command:
#!/usr/bin/env bash
set -euo pipefail
if [[ {{ profile }} =~ dev.* ]]; then
echo "{{command}}" >&2
{{command}}
fi
# Runs the provided command if in a pull request
[private]
[no-cd]
in-pr +command:
#!/usr/bin/env bash
set -euo pipefail
if [[ {{ github-event-name }} = pull_request ]]; then
echo "{{command}}" >&2
{{command}}
fi
# Runs the provided command if not in a pull request
[private]
[no-cd]
not-in-pr +command:
#!/usr/bin/env bash
set -euo pipefail
if [[ {{ github-event-name }} != pull_request ]]; then
echo "{{command}}" >&2
{{command}}
fi
# Runs the provided command in CI only
[private]
[no-cd]
in-ci +command:
#!/usr/bin/env bash
set -eo pipefail
if [ -n "$CI" ]; then
echo "{{command}}" >&2
{{command}}
fi
######################################################################
## Predefined commands
######################################################################
# Runs all linting commands and fails if the CI would fail
[no-cd]
lint:
@just format --check
@just clippy -- -D warnings
@RUSTDOCFLAGS='-Z unstable-options --check' just doc
@RUSTDOCFLAGS='-Z unstable-options --check' just doc --document-private-items
# Sync the package.json files to the `Cargo.toml` file
[no-cd]
sync-turborepo:
@cargo -Zscript run --manifest-path "{{repo}}/.github/scripts/rust/sync-turborepo.rs" "{{repo}}" | xargs just yarn fix:package-json
# Format the code using `rustfmt`
[no-cd]
format *arguments:
cargo fmt --all {{arguments}}
# Lint the code using `clippy`
[no-cd]
clippy *arguments:
@just in-pr cargo clippy --profile {{profile}} --all-features --all-targets --no-deps {{arguments}}
@just not-in-pr cargo hack --optional-deps --feature-powerset clippy --profile {{profile}} --all-targets --no-deps {{arguments}}
# Builds the crate
[no-cd]
build *arguments:
cargo build --profile {{profile}} {{arguments}}
# Run the test suite
[no-cd]
test *arguments:
cargo hack --optional-deps --feature-powerset nextest run {{arguments}}
cargo test --all-features --doc
# Run the test suite with `miri`
[no-cd]
miri *arguments:
cargo miri test --all-features --all-targets {{arguments}}
# Runs the benchmarks
[no-cd]
bench *arguments:
cargo bench --all-features --all-targets {{arguments}}
# Run the test suite and generate a coverage report
[no-cd]
coverage *arguments:
cargo llvm-cov nextest --all-features --all-targets --cargo-profile coverage {{arguments}}
cargo llvm-cov --all-features --profile coverage --doc
# Run the test suite and optionally generate a coverage report when `$TEST_COVERAGE` is set to `true`
[no-cd]
test-or-coverage *arguments:
#!/usr/bin/env bash
set -eo pipefail
if [[ "$TEST_COVERAGE" = 'true' || "$TEST_COVERAGE" = '1' ]]; then
just coverage --lcov --output-path lcov.info {{arguments}}
else
just test --no-fail-fast {{arguments}}
fi