-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.toml
More file actions
287 lines (243 loc) · 8.69 KB
/
Makefile.toml
File metadata and controls
287 lines (243 loc) · 8.69 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
#
# SPDX-License-Identifier: MIT
# Makefile.toml for cargo-make
# Usage:
# cargo make # pretty help (default)
# cargo make ci # fmt, clippy, tests, package
# TAG=v0.3.0 cargo make release
# CARGO_REGISTRY_TOKEN=... TAG=v0.3.0 cargo make publish
[env]
ALL_FEATURES = "true" # toggle --all-features for clippy/test
# ------- Default task (no root 'default_task' key) -------
[tasks.default]
category = "Meta"
description = "Default task -> help"
run_task = "help"
# ------- Core checks -------
[tasks.clippy]
category = "Lint"
clear = true
script_runner = "bash"
script = ['''
set -euo pipefail
if [ "${ALL_FEATURES}" = "true" ]; then
cargo clippy --workspace --all-targets --all-features -- -D warnings
else
cargo clippy --workspace --all-targets -- -D warnings
fi
''']
description = "Run clippy for all targets; fail on warnings"
[tasks.test]
category = "Test"
clear = true
script_runner = "bash"
script = ['''
set -euo pipefail
if [ "${ALL_FEATURES}" = "true" ]; then
cargo test --workspace --all-features --no-fail-fast
else
cargo test --workspace --no-fail-fast
fi
''']
description = "Run tests (optionally with all features)"
[tasks.package]
category = "Package"
clear = true
command = "cargo"
args = ["package", "--locked"]
description = "Verify that the crate can be packaged cleanly"
[tasks.ci]
category = "Meta"
dependencies = ["format", "clippy", "test", "package"]
description = "Run fmt, clippy, tests, and packaging checks"
# ------- Release gatekeeping -------
[tasks.check_tag_env]
clear = true
script_runner = "bash"
script = ['''
set -euo pipefail
if [ -z "${TAG:-}" ]; then
echo "TAG env var is required, e.g. TAG=v0.3.0"
exit 1
fi
''']
description = "Ensure TAG env var is provided (e.g. TAG=v1.2.3)"
[tasks.ensure_tag_matches_version]
clear = true
script_runner = "bash"
script = [
'''
set -euo pipefail
TAG="${TAG#refs/tags/}"
if command -v jq >/dev/null 2>&1; then
FILE_VER="$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')"
else
FILE_VER="$(cargo metadata --no-deps --format-version=1 | sed -n 's/.*"version":"\([^"]*\)".*/\1/p' | head -n1)"
fi
if [ -z "${FILE_VER}" ]; then
echo "Unable to parse version from cargo metadata."
exit 1
fi
if [ "${TAG}" != "v${FILE_VER}" ]; then
echo "Tag ${TAG} != Cargo.toml version v${FILE_VER}"
exit 1
fi
echo "Tag ${TAG} matches Cargo.toml version v${FILE_VER}"
''',
]
dependencies = ["check_tag_env"]
description = "Ensure git tag matches Cargo.toml version"
[tasks.check_token]
clear = true
script_runner = "bash"
script = ['''
set -euo pipefail
if [ -z "${CARGO_REGISTRY_TOKEN:-}" ]; then
echo "CARGO_REGISTRY_TOKEN is required to publish."
exit 1
fi
''']
description = "Ensure crates.io token is present in env"
# ------- Publish & Release -------
[tasks.publish]
category = "Release"
clear = true
script_runner = "bash"
script = ['''
set -euo pipefail
cargo publish --locked --token "${CARGO_REGISTRY_TOKEN}"
''']
dependencies = ["check_token", "ensure_tag_matches_version", "ci"]
description = "Publish crate to crates.io after checks and tag/version verification"
[tasks.tag]
category = "Release"
clear = true
script_runner = "bash"
script = [
'''
set -euo pipefail
if command -v jq >/dev/null 2>&1; then
VER="$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')"
else
VER="$(cargo metadata --no-deps --format-version=1 | sed -n 's/.*"version":"\([^"]*\)".*/\1/p' | head -n1)"
fi
if [ -z "${VER}" ]; then
echo "Unable to extract version from Cargo metadata."
exit 1
fi
TAG="v${VER}"
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "Tag ${TAG} already exists."
exit 1
fi
git tag "${TAG}"
echo "Created tag ${TAG}. You can push it with: git push origin ${TAG}"
''',
]
description = "Create git tag vX.Y.Z from Cargo.toml version (does not push)"
[tasks.release]
category = "Release"
clear = true
dependencies = ["publish"]
description = "Run checks and publish the crate (requires TAG and token)"
# ------- Extras -------
[tasks.format]
category = "Format"
clear = true
description = "Format code using rustfmt on nightly (optional)"
script_runner = "bash"
script = ['''
set -euo pipefail
if ! rustup toolchain list | grep -q "^nightly"; then
echo "Installing nightly toolchain for rustfmt..."
rustup toolchain install nightly >/dev/null
fi
rustup component add rustfmt --toolchain nightly >/dev/null
cargo +nightly fmt --
''']
[tasks.install-hooks]
clear = true
workspace = false
description = "Install git pre-commit hook from .hooks/"
script_runner = "bash"
script = [
'set -euo pipefail',
'if [ ! -f .hooks/pre-commit ]; then echo "❌ .hooks/pre-commit not found!"; exit 1; fi',
'echo "🔗 Linking .hooks/pre-commit to .git/hooks/pre-commit..."',
'mkdir -p .git/hooks',
'ln -sf ../../.hooks/pre-commit .git/hooks/pre-commit',
'chmod +x .hooks/pre-commit',
'echo "✅ pre-commit hook installed."',
]
# ------- Pretty Help -------
[tasks.help]
clear = true
category = "Meta"
description = "Pretty, colored help with examples"
script_runner = "bash"
script = [
'''
set -euo pipefail
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
BOLD="\033[1m"; DIM="\033[2m"; RESET="\033[0m"
BLUE="\033[34m"; CYAN="\033[36m"; GREEN="\033[32m"; YELLOW="\033[33m"; MAGENTA="\033[35m"
else
BOLD=""; DIM=""; RESET=""; BLUE=""; CYAN=""; GREEN=""; YELLOW=""; MAGENTA=""
fi
hr() { printf "%s\n" "──────────────────────────────────────────────────────────────────────────────"; }
row() { printf " %b%s%b %b%s%b\n" "$GREEN" "$1" "$RESET" "$DIM" "$2" "$RESET"; }
if command -v jq >/dev/null 2>&1; then
META="$(cargo metadata --no-deps --format-version=1)"
VER="$(printf "%s" "$META" | jq -r '.packages[0].version')"
MSRV="$(printf "%s" "$META" | jq -r '.packages[0].rust_version // "unknown"')"
NAME="$(printf "%s" "$META" | jq -r '.packages[0].name')"
else
META="$(cargo metadata --no-deps --format-version=1)"
VER="$(printf "%s" "$META" | sed -n 's/.*\"version\":\"\\([^\"]*\\)\".*/\\1/p' | head -n1)"
MSRV="$(printf "%s" "$META" | sed -n 's/.*\"rust_version\":\"\\([^\"]*\\)\".*/\\1/p' | head -n1)"; [ -z "$MSRV" ] && MSRV="unknown"
NAME="$(printf "%s" "$META" | sed -n 's/.*\"name\":\"\\([^\"]*\\)\".*/\\1/p' | head -n1)"
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')"
LAST_TAG="$(git describe --tags --abbrev=0 2>/dev/null || echo 'none')"
printf "%b%s%b %b(%s, MSRV %s, branch %s, last tag %s)%b\n" \
"$BOLD$BLUE" "${NAME:-crate} development tasks" "$RESET" \
"$DIM" "version ${VER:-unknown}" "${MSRV:-unknown}" "${BRANCH}" "${LAST_TAG}" "$RESET"
hr
printf "%b%s%b\n" "$BOLD$MAGENTA" "Common commands" "$RESET"
row "cargo make ci" "Run fmt, clippy, tests, and packaging"
row "cargo make tag" "Create git tag v${VER} from Cargo.toml (no push)"
row "TAG=v${VER} cargo make release" "Run checks and publish to crates.io"
row "ALL_FEATURES=false cargo make ci" "Run CI without --all-features"
echo
printf "%b%s%b\n" "$BOLD$MAGENTA" "Formatting" "$RESET"
row "cargo make format" "Format with nightly rustfmt (unstable features)"
echo
printf "%b%s%b\n" "$BOLD$MAGENTA" "Lint & Tests" "$RESET"
row "cargo make clippy" "Run clippy --workspace --all-targets -D warnings"
row "cargo make test" "Run tests --workspace"
echo
printf "%b%s%b\n" "$BOLD$MAGENTA" "Packaging & Release" "$RESET"
row "cargo make package" "Dry-run packaging (--locked)"
row "cargo make publish" "Publish to crates.io (requires TAG and token)"
echo
printf "%b%s%b\n" "$BOLD$MAGENTA" "Hooks & Utilities" "$RESET"
row "cargo make install-hooks" "Install .hooks/pre-commit"
echo
printf "%b%s%b\n" "$BOLD$DIM" "Environment variables:" "$RESET"
printf " %b%-22s%b %s\n" "$CYAN" "ALL_FEATURES=true|false" "$RESET" "Enable/disable --all-features for clippy/test"
printf " %b%-22s%b %s\n" "$CYAN" "TAG=vX.Y.Z" "$RESET" "Git tag matching Cargo.toml version"
printf " %b%-22s%b %s\n" "$CYAN" "CARGO_REGISTRY_TOKEN" "$RESET" "crates.io token for publish"
echo
printf "%b%s%b\n" "$BOLD$DIM" "Tips:" "$RESET"
printf " • Keep %bCargo.lock%b committed\n" "$BOLD" "$RESET"
printf " • Tag must exactly match version: %bv%s%b\n" "$BOLD" "${VER}" "$RESET"
echo
''',
]
# Alias
[tasks.h]
clear = true
run_task = "help"
category = "Meta"
description = "Alias: help"