-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjustfile
executable file
·139 lines (115 loc) · 4.93 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
#!/usr/bin/env just --justfile
@_default:
just --list
# Clean all build artifacts
clean:
cargo clean
rm -f Cargo.lock
# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
update:
cargo +nightly -Z unstable-options update --breaking
cargo update
# Find unused dependencies. Install it with `cargo install cargo-udeps`
udeps:
cargo +nightly udeps --all-targets --workspace --all-features
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
semver *ARGS:
cargo semver-checks {{ARGS}}
# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
msrv:
cargo msrv find --write-msrv --component rustfmt --all-features --ignore-lockfile -- {{just_executable()}} ci-test-msrv
# Run cargo clippy to lint the code
clippy *ARGS:
cargo clippy --workspace --all-targets --all-features {{ARGS}}
# Test code formatting
test-fmt:
cargo fmt --all -- --check
# Reformat all code `cargo fmt`. If nightly is available, use it for better results
fmt:
#!/usr/bin/env bash
set -euo pipefail
if command -v cargo +nightly &> /dev/null; then
echo 'Reformatting Rust code using nightly Rust fmt to sort imports'
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
else
echo 'Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
cargo fmt --all
fi
# Build and open code documentation
docs:
cargo doc --no-deps --all-features --open
# Quick compile without building a binary
check:
cargo check --workspace --all-targets --all-features
# Default build
build *ARGS:
cargo build --all-targets --workspace --all-features {{ARGS}}
# Generate code coverage report
coverage *ARGS="--no-clean --open":
cargo llvm-cov test --workspace --all-targets --all-features --include-build-script {{ARGS}}
# Generate code coverage report to upload to codecov.io
ci-coverage: && \
(coverage '--codecov --output-path target/llvm-cov/codecov.info')
# ATTENTION: the full file path above is used in the CI workflow
mkdir -p target/llvm-cov
# Run all tests
test *ARGS:
cargo test --all-targets --workspace --all-features {{ARGS}}
# Use the experimental workspace publishing with --dry-run. Requires nightly Rust.
test-publish:
cargo +nightly -Z package-workspace publish --dry-run
# Run tests, and accept their results. Requires insta to be installed.
bless: (cargo-install "cargo-insta")
TRYBUILD=overwrite cargo insta test --accept --all-features
# Test documentation
test-doc:
cargo test --doc --all-features
cargo doc --no-deps --all-features
rust-info:
rustc --version
cargo --version
# Run all tests as expected by CI
ci-test: rust-info test-fmt
RUSTFLAGS='-D warnings' {{just_executable()}} build
{{just_executable()}} clippy -- -D warnings
RUSTFLAGS='-D warnings' {{just_executable()}} test
RUSTDOCFLAGS='-D warnings' {{just_executable()}} test-doc
# Run minimal subset of tests to ensure compatibility with MSRV
ci-test-msrv: rust-info test
# Check if a certain Cargo command is installed, and install it if needed
[private]
cargo-install $COMMAND $INSTALL_CMD="" *ARGS="":
#!/usr/bin/env bash
set -euo pipefail
if ! command -v $COMMAND > /dev/null; then
if ! command -v cargo-binstall > /dev/null; then
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} {{ARGS}}"
cargo install ${INSTALL_CMD:-$COMMAND} {{ARGS}}
else
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{ARGS}}"
cargo binstall ${INSTALL_CMD:-$COMMAND} {{ARGS}}
fi
fi
# Verify that the current version of the crate is not the same as the one published on crates.io
check-if-published: (assert "jq")
#!/usr/bin/env bash
set -euo pipefail
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
echo "Detected crate version: $LOCAL_VERSION"
CRATE_NAME="$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')"
echo "Detected crate name: $CRATE_NAME"
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
echo "Published crate version: $PUBLISHED_VERSION"
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "ERROR: The current crate version has already been published."
exit 1
else
echo "The current crate version has not yet been published."
fi
# Ensure that a certain command is available
[private]
assert $COMMAND:
@if ! type "{{COMMAND}}" > /dev/null; then \
echo "Command '{{COMMAND}}' could not be found. Please make sure it has been installed on your computer." ;\
exit 1 ;\
fi