diagprint 0.7.1

A Rust diagnostics lifecycle framework for structured diagnostics, rendering, remediation, CI, editors, and telemetry.
Documentation
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/usr/bin/env bash

mode="${1:-full}"
msrv="1.85.0"

packages=(
    diagprint
    diagprint-derive
    diagprint-lsp
    diagprint-async
    diagprint-otel
    diagprint-test
)

root_features=(
    artifact-store
    derive
    compression
    cybercore
    html
    terminal-docs
    anyhow
    tracing
    miette
    codespan-reporting
    ariadne
    annotate-snippets
)

print_rule() {
    printf '%*s\n' 72 '' | tr ' ' '='
}

run_gate() {
    local name="$1"
    shift

    echo
    print_rule
    echo " GATE: $name"
    print_rule
    echo

    "$@"
    local status=$?

    if [[ $status -ne 0 ]]; then
        echo
        echo "FAILED: $name"
        echo "Exit status: $status"
        exit "$status"
    fi

    echo
    echo "PASS: $name"
}

require_command() {
    local command_name="$1"

    if ! command -v "$command_name" >/dev/null 2>&1; then
        echo "error: required command not found: $command_name" >&2
        exit 127
    fi
}

require_repo_root() {
    if [[ ! -f Cargo.toml ]]; then
        echo "error: run this script from the diagprint repository root" >&2
        exit 1
    fi

    if [[ ! -f crates/diagprint-derive/Cargo.toml ]]; then
        echo "error: this does not appear to be the diagprint workspace" >&2
        exit 1
    fi
}

require_clean_tree() {
    local status_output

    status_output="$(git status --porcelain)"

    if [[ -n "$status_output" ]]; then
        echo
        print_rule
        echo " RELEASE TREE IS NOT CLEAN"
        print_rule
        echo
        printf '%s\n' "$status_output"
        echo
        echo "Release dry-runs must be executed from a clean committed tree."
        exit 1
    fi

    echo
    echo "PASS: working tree is clean"
}

check_msrv_toolchain() {
    if ! rustup toolchain list | grep -Eq "^${msrv}([[:space:]-]|$)"; then
        echo
        echo "error: Rust $msrv toolchain is not installed" >&2
        echo
        echo "Install it with:"
        echo
        echo "  rustup toolchain install $msrv"
        exit 1
    fi
}

check_core_package_hygiene() {
    local package_list
    local status

    package_list="$(
        cargo package \
            --allow-dirty \
            --list \
            -p diagprint
    )"
    status=$?

    if [[ $status -ne 0 ]]; then
        echo
        echo "FAILED: unable to inspect diagprint package contents"
        exit "$status"
    fi

    if grep -Eq '^\.diagprint(/|$)' <<<"$package_list"; then
        echo
        echo "FAILED: .diagprint generated state is present in the package"
        exit 1
    fi

    if grep -Eq '^reports(/|$)' <<<"$package_list"; then
        echo
        echo "FAILED: generated reports are present in the package"
        exit 1
    fi

    echo
    echo "PASS: .diagprint is excluded"
    echo "PASS: reports are excluded"
}

run_quick_gates() {
    run_gate \
        "Unstaged whitespace" \
        git diff --check

    run_gate \
        "Staged whitespace" \
        git diff --cached --check

    run_gate \
        "Formatting" \
        cargo fmt --all -- --check

    run_gate \
        "Workspace check" \
        cargo check \
            --workspace \
            --all-targets \
            --all-features

    run_gate \
        "Workspace Clippy" \
        cargo clippy \
            --workspace \
            --all-targets \
            --all-features \
            -- \
            -D warnings

    run_gate \
        "diagprint-derive UI contract" \
        cargo test \
            -p diagprint-derive \
            --test ui
}

run_full_gates() {
    run_quick_gates

    run_gate \
        "Workspace tests" \
        cargo test \
            --workspace \
            --all-targets \
            --all-features

    run_gate \
        "Workspace doctests" \
        cargo test \
            --workspace \
            --doc \
            --all-features

    run_gate \
        "Strict rustdoc" \
        env RUSTDOCFLAGS="-D warnings" \
        cargo doc \
            --workspace \
            --no-deps \
            --all-features

    echo
    print_rule
    echo " ROOT FEATURE MATRIX"
    print_rule

    local feature

    for feature in "${root_features[@]}"; do
        run_gate \
            "Feature: $feature" \
            cargo check \
                -p diagprint \
                --no-default-features \
                --features "$feature" \
                --all-targets
    done

    run_gate \
        "Tracing integration in isolation" \
        cargo test \
            -p diagprint \
            --no-default-features \
            --features tracing \
            --test tracing_integration

    echo
    print_rule
    echo " PACKAGE CONTENTS"
    print_rule

    local package

    for package in "${packages[@]}"; do
        run_gate \
            "Package contents: $package" \
            cargo package \
                --allow-dirty \
                --list \
                -p "$package"
    done

    echo
    print_rule
    echo " GENERATED STATE EXCLUSION"
    print_rule

    check_core_package_hygiene

    check_msrv_toolchain

    run_gate \
        "MSRV workspace check" \
        cargo +"$msrv" check \
            --workspace \
            --all-targets \
            --all-features

    run_gate \
        "MSRV workspace tests" \
        cargo +"$msrv" test \
            --workspace \
            --all-targets \
            --all-features

    run_gate \
        "MSRV doctests" \
        cargo +"$msrv" test \
            --workspace \
            --doc \
            --all-features

    run_gate \
        "MSRV strict rustdoc" \
        env RUSTDOCFLAGS="-D warnings" \
        cargo +"$msrv" doc \
            --workspace \
            --no-deps \
            --all-features
}

run_derive_release() {
    run_full_gates

    echo
    print_rule
    echo " DIAGPRINT-DERIVE RELEASE GATE"
    print_rule

    require_clean_tree

    run_gate \
        "diagprint-derive package verification" \
        cargo package \
            -p diagprint-derive

    run_gate \
        "diagprint-derive publish dry run" \
        cargo publish \
            --dry-run \
            -p diagprint-derive
}

run_core_release() {
    run_full_gates

    echo
    print_rule
    echo " DIAGPRINT CORE RELEASE GATE"
    print_rule

    require_clean_tree

    run_gate \
        "diagprint package verification" \
        cargo package \
            -p diagprint

    run_gate \
        "diagprint publish dry run" \
        cargo publish \
            --dry-run \
            -p diagprint
}

run_satellite_release() {
    run_full_gates

    echo
    print_rule
    echo " COMPANION CRATE RELEASE GATE"
    print_rule

    require_clean_tree

    local satellites=(
        diagprint-lsp
        diagprint-async
        diagprint-otel
        diagprint-test
    )

    local package

    for package in "${satellites[@]}"; do
        run_gate \
            "$package package verification" \
            cargo package \
                -p "$package"

        run_gate \
            "$package publish dry run" \
            cargo publish \
                --dry-run \
                -p "$package"
    done
}

require_command cargo
require_command git
require_command rustup
require_repo_root

echo
print_rule
echo " DIAGPRINT RELEASE GATES"
print_rule
echo
echo "Mode       : $mode"
echo "Repository : $(pwd)"
echo "Revision   : $(git rev-parse --short HEAD)"
echo "Branch     : $(git branch --show-current)"
echo "MSRV       : $msrv"

case "$mode" in
    quick)
        run_quick_gates
        ;;

    full)
        run_full_gates
        ;;

    derive)
        run_derive_release
        ;;

    core)
        run_core_release
        ;;

    satellites)
        run_satellite_release
        ;;

    *)
        echo
        echo "Usage:"
        echo "  ./scripts/release-gates quick"
        echo "  ./scripts/release-gates full"
        echo "  ./scripts/release-gates derive"
        echo "  ./scripts/release-gates core"
        echo "  ./scripts/release-gates satellites"
        echo
        exit 2
        ;;
esac

echo
print_rule
echo " ALL REQUESTED DIAGPRINT GATES GREEN"
print_rule
echo