-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjustfile
182 lines (152 loc) · 6.52 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env just --justfile
@_default:
just --list --unsorted
# Clean all build artifacts
clean:
cargo clean
rm -f Cargo.lock
# Update dependencies, including breaking changes
update:
cargo +nightly -Z unstable-options update --breaking
cargo update
# Run cargo clippy
clippy:
cargo clippy --all-targets --workspace $({{just_executable()}} get-package-exclude-args) -- -D warnings
# Test code formatting
test-fmt:
cargo fmt --all -- --check
# Run cargo fmt
fmt:
cargo +nightly fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate
# Build and open code documentation
docs:
cargo doc --no-deps --open
# Quick compile
check:
cargo check --all-targets --workspace $({{just_executable()}} get-package-exclude-args)
# Default build
build:
cargo build --all-targets --workspace $({{just_executable()}} get-package-exclude-args)
# build all
build-all-features:
cargo build --all-targets --workspace $({{just_executable()}} get-package-exclude-args) --features "ffi,vsc"
# Run all tests
test *ARGS: build
cargo test --all-targets --workspace $({{just_executable()}} get-package-exclude-args) {{ARGS}}
# Find the minimum supported Rust version. Install it with `cargo install cargo-msrv`
msrv:
cargo msrv find --min 1.77 --component rustfmt -- {{just_executable()}} ci-test-msrv
# Find unused dependencies. Install it with `cargo install cargo-udeps`
udeps:
cargo +nightly udeps --all-targets --workspace
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
semver *ARGS:
cargo semver-checks {{ARGS}}
# Generate and show coverage report. Requires grcov to be installed.
grcov:
#!/usr/bin/env bash
set -euo pipefail
find . -name '*.profraw' | xargs rm
rm -rf ./target/debug/coverage
export LLVM_PROFILE_FILE="varnish-%p-%m.profraw"
export RUSTFLAGS="-Cinstrument-coverage"
cargo build --all-targets --workspace
cargo test --all-targets --workspace
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
open ./target/debug/coverage/index.html
# Publish crates to crates.io in the right order
publish:
#!/usr/bin/env bash
set -euo pipefail
cargo publish -p varnish-sys
cargo publish -p varnish-macros
cargo publish -p varnish
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
git tag -a "v$LOCAL_VERSION" -m "Release v$LOCAL_VERSION"
echo "A new tag v$LOCAL_VERSION has been created. Please push it to the repository:"
if git remote get-url upstream > /dev/null 2> /dev/null ; then
echo " git push upstream tag v$LOCAL_VERSION"
else
echo " git push origin tag v$LOCAL_VERSION"
fi
# 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:
TRYBUILD=overwrite cargo insta test -p varnish-macros -p varnish --accept
# Test documentation
test-doc:
cargo test --doc
cargo doc --no-deps
rust-info:
rustc --version
cargo --version
# Run tests only relevant to the latest Varnish version
ci-test-extras: test-doc
# Run all tests as expected by CI
ci-test: rust-info test-fmt clippy test build-all-features
# Run minimal subset of tests to ensure compatibility with MSRV
ci-test-msrv: rust-info test
# Verify that the current version of the crate is not the same as the one published on crates.io
check-if-published:
#!/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
# Get the `--exclude <SPEC>` parameter for the cargo build/test/... command, depending on the installed version of Varnish
[private]
get-package-exclude-args:
#!/usr/bin/env bash
set -euo pipefail
if {{just_executable()}} get-varnish-version 7.0 > /dev/null 2> /dev/null ; then
echo ""
else
EXCLUDE="--exclude vmod_be --exclude vmod_vfp --exclude vmod_vdp --exclude vmod_test"
echo "INFO: Due to older Varnish, running with: $EXCLUDE" >&2
echo "$EXCLUDE"
fi
# Get the version of Varnish installed on the system. If a version arg is provided, check that the installed version is at least that version.
get-varnish-version $required_version="":
#!/usr/bin/env bash
set -euo pipefail
VARNISH_VER=$(dpkg-query -W -f='${source:Upstream-Version}\n' varnish-dev || echo "unknown")
if [ -n "$required_version" ]; then
if [ "$(printf "$required_version\n$VARNISH_VER" | sort -V | head -n1)" != "$required_version" ]; then
echo "ERROR: Varnish version $required_version is required, but $VARNISH_VER is installed."
exit 1
else
echo "Found varnish-dev package v$VARNISH_VER >= $required_version"
fi
elif [ "$VARNISH_VER" = "unknown" ]; then
echo "ERROR: varnish-dev package was not found"
exit 1
else
echo "Found varnish-dev package v$VARNISH_VER"
fi
[private]
docker-build-ver VERSION:
docker build --progress=plain -t varnish-img-{{VERSION}} --build-arg VARNISH_VERSION={{VERSION}} --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) -f docker/Dockerfile docker
[private]
docker-run-ver VERSION *ARGS:
mkdir -p docker/.cache/{{VERSION}}
touch docker/.cache/{{VERSION}}/.bash_history
docker run --rm -it \
-v "$PWD:/app/" \
-v "$PWD/docker/.cache/{{VERSION}}:/home/user/.cache" \
-v "$PWD/docker/.cache/{{VERSION}}/.bash_history:/home/user/.bash_history" \
varnish-img-{{VERSION}} {{ARGS}}
docker-run-76 *ARGS: (docker-build-ver "76") (docker-run-ver "76" ARGS)
docker-run-75 *ARGS: (docker-build-ver "75") (docker-run-ver "75" ARGS)
docker-run-74 *ARGS: (docker-build-ver "74") (docker-run-ver "74" ARGS)
docker-run-60 *ARGS: (docker-build-ver "60lts") (docker-run-ver "60lts" ARGS)