Compare commits

..

3 Commits

Author SHA1 Message Date
Dandaedre 3d78c0ca2a
refactor(ci): centralize badge rendering
Rust CI JohnSlop passed all CI checks.
Gitea/john-slop/pipeline/head This commit looks good Details
2026-10-04 01:33:47 +02:00
Dandaedre 002b945e9b
fix(ci): escape coverage regex for Groovy
Rust CI JohnSlop passed all CI checks.
Gitea/john-slop/pipeline/head This commit looks good Details
2026-10-03 14:43:18 +02:00
Dandaedre d2f6f01fcd
ci: publish current coverage badges
Gitea/john-slop/pipeline/head There was a failure building this commit Details
2026-10-03 03:07:43 +02:00
15 changed files with 551 additions and 45 deletions

3
.gitignore vendored
View File

@ -22,8 +22,9 @@ target/
# Local implementation journal (intentionally not committed)
/recap.md
# Generated locally by rust_autobadges/Cargo Tarpaulin
# Generated locally or in CI by Cargo Tarpaulin and the badge scripts
/tarpaulin-report.html
/coverage/
# Legacy cargo-cyclonedx intermediates may remain in reused CI workspaces.
**/sbom.cdx.json

View File

@ -1,17 +0,0 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 440
coverage = 92.72
[last_run_clean.run_duration]
secs = 62
nanos = 238260804
[last_run_incremental]
run_status = "Success"
lines_parsed = 420
coverage = 92.84
[last_run_incremental.run_duration]
secs = 45
nanos = 633186947

View File

@ -237,9 +237,9 @@ cargo doc --no-deps
```
Run `cargo tarpaulin --config tarpaulin.toml` when tests or executable Rust code
change. It enforces the 90% line-coverage floor. Refresh
the tracked local badges with `rust_autobadges --high-coverage-percent 0.7
--mid-coverage-percent 0.3` after a clean test and coverage run.
change. It enforces the 90% line-coverage floor. Jenkins renders the version,
test, and coverage badges from package metadata and CI results; generated badge
files and status snapshots do not belong in the repository.
Also run focused CLI golden tests and LSP protocol tests once those binaries
exist. Favor property tests for replacement idempotence/non-overlap and fuzz
@ -270,7 +270,8 @@ After every milestone's acceptance criteria and quality gates pass, create an
annotated Git tag named `v0.1.N`, where `N` is the milestone number, on its
completion commit. Before that completion commit, set the workspace package
version and internal registry dependency requirements to `0.1.N`, refresh
`Cargo.lock`, cut the matching changelog entry, and regenerate the version badge.
Verify those artifacts and binary `--version` output agree before tagging. Never
move an existing milestone tag; add a corrective commit and a documented
successor tag if a published milestone needs amendment.
`Cargo.lock` and cut the matching changelog entry. Jenkins derives the version
badge from that metadata. Verify the manifests, lockfile, changelog, and binary
`--version` output agree before tagging. Never move an existing milestone tag;
add a corrective commit and a documented successor tag if a published milestone
needs amendment.

97
Jenkinsfile vendored
View File

@ -8,8 +8,10 @@ pipeline {
CARGO_TERM_COLOR = 'always'
RUST_BACKTRACE = '1'
MSRV = '1.98.1'
CARGO_TARPAULIN_VERSION = '0.37.5'
CARGO_AUDIT_VERSION = '0.22.2'
CARGO_DENY_VERSION = '0.20.2'
BADGE_PUBLISH_ROOT = '/mnt/assets/coverage'
}
stages {
@ -65,6 +67,11 @@ pipeline {
cargo install cargo-deny --locked --version "${CARGO_DENY_VERSION}"
fi
INSTALLED_TARPAULIN="$(cargo tarpaulin --version 2>/dev/null || true)"
if [ "${INSTALLED_TARPAULIN}" != "cargo-tarpaulin-tarpaulin ${CARGO_TARPAULIN_VERSION}" ]; then
cargo install cargo-tarpaulin --locked --version "${CARGO_TARPAULIN_VERSION}"
fi
'''
}
}
@ -148,6 +155,32 @@ pipeline {
cargo test --locked --test example_fixtures --all-features
cargo test --locked --test cli --all-features
mkdir -p coverage
: > "coverage/.tests-passed-${BUILD_NUMBER}"
'''
}
}
stage('Coverage') {
steps {
sh '''
set -eu
cargo tarpaulin \
--config tarpaulin.toml \
--out Json \
--output-dir coverage
mv coverage/tarpaulin-report.json coverage/summary.json
coverage_percent=$(sed -n \
's/^.*],"coverage":\\([0-9][0-9.]*\\),"covered":[0-9][0-9]*,"coverable":[0-9][0-9]*}$/\\1/p' \
coverage/summary.json)
scripts/render-coverage-badge.sh \
"${coverage_percent}" \
coverage/coverage.svg
rm coverage/summary.json
: > "coverage/.coverage-ready-${BUILD_NUMBER}"
'''
}
}
@ -236,7 +269,7 @@ pipeline {
conclusion: 'SUCCESS',
name: 'Rust CI',
summary: 'JohnSlop passed all CI checks.',
text: 'The Linux MSRV/stable matrix, formatting, feature tests, fixtures, docs, Clippy, supply-chain policy, and release build completed successfully.',
text: 'The Linux MSRV/stable matrix, formatting, feature tests, fixtures, coverage and badge generation, docs, Clippy, supply-chain policy, and release build completed successfully.',
title: 'Build Successful'
)
@ -248,7 +281,7 @@ pipeline {
conclusion: 'FAILURE',
name: 'Rust CI',
summary: 'JohnSlop failed CI.',
text: 'A toolchain, formatting, test, fixture, documentation, Clippy, supply-chain, or release check failed. Check the Jenkins log.',
text: 'A toolchain, formatting, test, fixture, coverage, badge generation, documentation, Clippy, supply-chain, or release check failed. Check the Jenkins log.',
title: 'Build Failed'
)
@ -266,5 +299,65 @@ pipeline {
echo '⚠️ JohnSlop CI is unstable.'
}
cleanup {
sh '''
set -eu
mkdir -p coverage
test_status=failing
if [ -f "coverage/.tests-passed-${BUILD_NUMBER}" ]; then
test_status=passing
fi
scripts/render-test-badge.sh \
"${test_status}" \
coverage/test.svg
if [ ! -f "coverage/.coverage-ready-${BUILD_NUMBER}" ]; then
scripts/render-coverage-badge.sh - coverage/coverage.svg
fi
package_version=$(awk '
$0 == "[workspace.package]" { in_package = 1; next }
substr($0, 1, 1) == "[" { in_package = 0 }
in_package && $1 == "version" && $2 == "=" {
gsub(/^"|"$/, "", $3)
print $3
exit
}
' Cargo.toml)
if [ -z "${package_version}" ]; then
echo "could not determine workspace package version" >&2
exit 2
fi
scripts/render-version-badge.sh \
"${package_version}" \
coverage/version.svg
rm -f \
coverage/summary.json \
coverage/tarpaulin-report.json \
"coverage/.tests-passed-${BUILD_NUMBER}" \
"coverage/.coverage-ready-${BUILD_NUMBER}"
'''
archiveArtifacts(
allowEmptyArchive: false,
artifacts: 'coverage/coverage.svg,coverage/test.svg,coverage/version.svg',
fingerprint: true
)
sh '''
set -eu
if [ "${BRANCH_NAME:-}" = "main" ]; then
scripts/publish-badges.sh \
"${BADGE_PUBLISH_ROOT}" \
coverage \
test \
version
fi
'''
}
}
}

View File

@ -1,8 +1,8 @@
# John Slop
![version](badges/version.svg)
![tests](badges/test.svg)
![test coverage](badges/coverage.svg)
![version](https://assets.dandaedre.com/coverage/idle-org/john-slop/main/version.svg)
![tests](https://assets.dandaedre.com/coverage/idle-org/john-slop/main/test.svg)
![test coverage](https://assets.dandaedre.com/coverage/idle-org/john-slop/main/coverage.svg)
John Slop is a local-first linter for concrete signs of low-effort or
insufficiently reviewed text and source code. It reports explainable evidence

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 93%"><title>test-coverage: 93%</title><linearGradient id="bms-317a4207573154a7" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-317a4207573154a7"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-317a4207573154a7)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-317a4207573154a7)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">93%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">93%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="82" height="18" role="img" aria-label="test: passing"><title>test: passing</title><linearGradient id="bms-5402c39dce014bd3" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-5402c39dce014bd3"><rect width="82" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-5402c39dce014bd3)"><rect width="31" height="18" fill="#555"/><rect x="31" width="51" height="18" fill="#97ca00"/><rect width="82" height="18" fill="url(#bms-5402c39dce014bd3)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="165" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">test</text><text x="165" y="130" transform="scale(.1)" fill="#fff" textLength="210">test</text><text aria-hidden="true" x="555" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">passing</text><text x="555" y="130" transform="scale(.1)" fill="#fff" textLength="410">passing</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="124" height="18" role="img" aria-label="version: 0.1.27-rc.8"><title>version: 0.1.27-rc.8</title><linearGradient id="bms-574ac137cd70c506" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-574ac137cd70c506"><rect width="124" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-574ac137cd70c506)"><rect width="51" height="18" fill="#555"/><rect x="51" width="73" height="18" fill="#fe7d37"/><rect width="124" height="18" fill="url(#bms-574ac137cd70c506)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="265" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">version</text><text x="265" y="130" transform="scale(.1)" fill="#fff" textLength="410">version</text><text aria-hidden="true" x="865" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="630">0.1.27-rc.8</text><text x="865" y="130" transform="scale(.1)" fill="#fff" textLength="630">0.1.27-rc.8</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -61,10 +61,10 @@ generated diff.
## Coverage and badges
Run line coverage with Cargo Tarpaulin:
Run the same line-coverage command used by Jenkins:
```sh
cargo tarpaulin --config tarpaulin.toml
cargo tarpaulin --config tarpaulin.toml --out Json --output-dir coverage
```
The configuration enforces a 90% floor. The current suite measured 92.72%
@ -73,16 +73,21 @@ platform/I/O failure injection, malformed archive internals, coordinate
overflow, LSP logging/reload failures, and subprocess attribution. Do not add
brittle tests or production seams solely to make Tarpaulin count those paths.
After a clean test and coverage run, refresh the repository-local badges with:
`Cargo.toml` is the authoritative version source. Jenkins temporarily renames
the Tarpaulin JSON output to `coverage/summary.json`, extracts and validates its
overall percentage, renders the badges locally, and then removes the summary.
It archives only `coverage/version.svg`, `coverage/test.svg`, and
`coverage/coverage.svg`, with fingerprinting. Successful `main` builds publish
those files atomically under
`/mnt/assets/coverage/idle-org/john-slop/main/`, which serves these mutable URLs:
```sh
rust_autobadges --high-coverage-percent 0.7 --mid-coverage-percent 0.3
```
- `https://assets.dandaedre.com/coverage/idle-org/john-slop/main/version.svg`
- `https://assets.dandaedre.com/coverage/idle-org/john-slop/main/test.svg`
- `https://assets.dandaedre.com/coverage/idle-org/john-slop/main/coverage.svg`
Commit `badges/*.svg` and `.run_status.toml`; do not commit the generated
`tarpaulin-report.html`. Coverage is currently a local release gate: Jenkins
runs both feature configurations, but its Tarpaulin check is disabled while the
job does not publish the report artifact.
The asset server is deployment-owned: it must mount assets read-only, disable
directory listings, serve SVG with a restrictive content security policy, and
revalidate these URLs or apply a short cache lifetime.
## Test scope
@ -96,7 +101,7 @@ Each completed milestone receives an immutable annotated `v0.1.N` Git tag,
where `N` is the milestone number, after its acceptance criteria and quality
gates pass. Its completion commit must also use package version `0.1.N` in the
workspace manifest, internal registry requirements, lockfile, changelog, binary
version output, and generated version badge.
version output. Jenkins derives the current version badge from that metadata.
## Fuzzing

270
scripts/make-badge.sh Executable file
View File

@ -0,0 +1,270 @@
#!/bin/sh
set -eu
usage() {
cat >&2 <<'EOF'
usage: $0 <version|test|coverage> [options]
Render one deterministic SVG badge. Defaults:
version --text version --value unknown --color #007ec6
test --text tests --value passing --color #4c1
coverage --text coverage --value - --color #9f9f9f --suffix %
Options:
--text TEXT left-hand label
--value VALUE right-hand value
--color COLOR value background (#RGB or #RRGGBB)
--size PX font size, from 6 through 24 (default: 11)
--height PX badge height, from 14 through 64 (default: 20)
--label-width PX fixed label width instead of automatic sizing
--value-width PX fixed value width instead of automatic sizing
--suffix TEXT text appended to the displayed value
--output PATH output file (default: coverage/<kind>.svg)
-h, --help show this help
Examples:
./ci-coverage-badges.sh version --value 1.2.3
./ci-coverage-badges.sh test --value failing
./ci-coverage-badges.sh coverage --value 87.4
./ci-coverage-badges.sh version --text release --value rc.12 --size 12 --color '#8a2be2'
EOF
exit "${1:-2}"
}
[ "$#" -ge 1 ] || usage
kind=$1
shift
case "$kind" in
version)
text=version
value=unknown
color='#007ec6'
suffix=
output=coverage/version.svg
;;
test)
text=tests
value=passing
color=
suffix=
output=coverage/test.svg
;;
coverage)
text=coverage
value=-
color=
suffix=%
output=coverage/coverage.svg
;;
-h|--help) usage 0 ;;
*)
echo "unsupported badge kind: $kind" >&2
usage
;;
esac
font_size=11
height=20
label_width=
value_width=
color_set=false
while [ "$#" -gt 0 ]; do
option=$1
case "$option" in
--text|--value|--color|--size|--height|--label-width|--value-width|--suffix|--output)
[ "$#" -ge 2 ] || {
echo "missing value for $option" >&2
exit 2
}
option_value=$2
shift 2
case "$option" in
--text) text=$option_value ;;
--value) value=$option_value ;;
--color) color=$option_value; color_set=true ;;
--size) font_size=$option_value ;;
--height) height=$option_value ;;
--label-width) label_width=$option_value ;;
--value-width) value_width=$option_value ;;
--suffix) suffix=$option_value ;;
--output) output=$option_value ;;
esac
;;
-h|--help) usage 0 ;;
*)
echo "unknown option: $option" >&2
usage
;;
esac
done
validate_text() {
field_name=$1
field_value=$2
if ! printf '%sX\n' "$field_value" | LC_ALL=C awk '
BEGIN { valid = 1 }
NR != 1 || $0 !~ /^[ -~]+X$/ || length($0) <= 1 { valid = 0 }
END { exit(valid == 0 ? 1 : 0) }
'; then
echo "$field_name must contain printable ASCII characters: $field_value" >&2
exit 2
fi
}
validate_integer() {
field_name=$1
field_value=$2
minimum=$3
maximum=$4
case "$field_value" in
''|*[!0-9]*)
echo "$field_name must be an integer from $minimum through $maximum: $field_value" >&2
exit 2
;;
esac
if [ "$field_value" -lt "$minimum" ] || [ "$field_value" -gt "$maximum" ]; then
echo "$field_name must be an integer from $minimum through $maximum: $field_value" >&2
exit 2
fi
}
validate_text text "$text"
validate_text value "$value"
if [ -n "$suffix" ]; then
validate_text suffix "$suffix"
fi
validate_integer size "$font_size" 6 24
validate_integer height "$height" 14 64
if [ -n "$label_width" ]; then
validate_integer label-width "$label_width" 20 1000
fi
if [ -n "$value_width" ]; then
validate_integer value-width "$value_width" 20 1000
fi
case "$output" in
''|*/) echo "output must name an SVG file: $output" >&2; exit 2 ;;
esac
case "$kind" in
test)
if [ "$color_set" = false ]; then
case "$value" in
passing) color='#4c1' ;;
failing) color='#e05d44' ;;
*) color='#9f9f9f' ;;
esac
fi
;;
coverage)
if [ "$value" = '-' ]; then
[ "$color_set" = true ] || color='#9f9f9f'
else
if ! awk -v candidate="$value" 'BEGIN {
valid = candidate ~ /^[0-9]+([.][0-9]+)?$/ && candidate >= 0 && candidate <= 100
exit(valid ? 0 : 1)
}'; then
echo "coverage value must be - or a number from 0 through 100: $value" >&2
exit 2
fi
value=$(awk -v candidate="$value" 'BEGIN { printf "%.0f", candidate }')
if [ "$color_set" = false ]; then
if [ "$value" -ge 90 ]; then
color='#4c1'
elif [ "$value" -ge 70 ]; then
color='#dfb317'
else
color='#e05d44'
fi
fi
fi
;;
esac
case "$color" in
\#[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]|\#[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]) ;;
*) echo "color must be #RGB or #RRGGBB: $color" >&2; exit 2 ;;
esac
display_value=$value$suffix
if [ -z "$label_width" ]; then
label_width=$(printf '%s\\n' "$text" | awk -v size="$font_size" '{
width = int(length($0) * size * 0.64 + 14)
print (width < 35 ? 35 : width)
}')
fi
if [ -z "$value_width" ]; then
value_width=$(printf '%s\\n' "$display_value" | awk -v size="$font_size" '{
width = int(length($0) * size * 0.64 + 14)
print (width < 35 ? 35 : width)
}')
fi
badge_width=$((label_width + value_width))
label_center=$(awk -v width="$label_width" 'BEGIN { printf "%.1f", width / 2 }')
value_center=$(awk -v left="$label_width" -v width="$value_width" 'BEGIN {
printf "%.1f", left + width / 2
}')
vertical_center=$(awk -v badge_height="$height" 'BEGIN { printf "%.1f", badge_height / 2 }')
xml_escape() {
sed \
-e 's/&/\&amp;/g' \
-e 's/</\&lt;/g' \
-e 's/>/\&gt;/g' \
-e 's/"/\&quot;/g'
}
sed_replacement_escape() {
sed -e 's/[\\&|]/\\&/g'
}
escaped_text=$(printf '%s' "$text" | xml_escape | sed_replacement_escape)
escaped_value=$(printf '%s' "$display_value" | xml_escape | sed_replacement_escape)
escaped_title=$(printf '%s: %s' "$text" "$display_value" | xml_escape | sed_replacement_escape)
output_dir=${output%/*}
if [ "$output_dir" != "$output" ]; then
mkdir -p "$output_dir"
fi
temporary="${output}.tmp.$$"
trap 'rm -f "$temporary"' EXIT HUP INT TERM
sed \
-e "s/@BADGE_WIDTH@/$badge_width/g" \
-e "s/@HEIGHT@/$height/g" \
-e "s/@LABEL_WIDTH@/$label_width/g" \
-e "s/@VALUE_WIDTH@/$value_width/g" \
-e "s/@LABEL_CENTER@/$label_center/g" \
-e "s/@VALUE_CENTER@/$value_center/g" \
-e "s/@VERTICAL_CENTER@/$vertical_center/g" \
-e "s/@FONT_SIZE@/$font_size/g" \
-e "s/@COLOR@/$color/g" \
-e "s|@TITLE@|$escaped_title|g" \
-e "s|@TEXT@|$escaped_text|g" \
-e "s|@VALUE@|$escaped_value|g" \
>"$temporary" <<'EOF'
<svg xmlns="http://www.w3.org/2000/svg" width="@BADGE_WIDTH@" height="@HEIGHT@" role="img" aria-label="@TITLE@">
<title>@TITLE@</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
<stop offset=".9" stop-opacity=".3"/>
<stop offset="1" stop-opacity=".5"/>
</linearGradient>
<clipPath id="r"><rect width="@BADGE_WIDTH@" height="@HEIGHT@" rx="3"/></clipPath>
<g clip-path="url(#r)">
<rect width="@LABEL_WIDTH@" height="@HEIGHT@" fill="#555"/>
<rect x="@LABEL_WIDTH@" width="@VALUE_WIDTH@" height="@HEIGHT@" fill="@COLOR@"/>
<rect width="@BADGE_WIDTH@" height="@HEIGHT@" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" dominant-baseline="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="@FONT_SIZE@">
<text x="@LABEL_CENTER@" y="@VERTICAL_CENTER@">@TEXT@</text>
<text x="@VALUE_CENTER@" y="@VERTICAL_CENTER@">@VALUE@</text>
</g>
</svg>
EOF
mv "$temporary" "$output"
trap - EXIT HUP INT TERM

78
scripts/publish-badges.sh Executable file
View File

@ -0,0 +1,78 @@
#!/bin/sh
set -eu
usage() {
echo "usage: $0 <badge-publication-root> <badge> [badge...]" >&2
echo "badges: coverage test version" >&2
exit 2
}
[ "$#" -ge 2 ] || usage
publication_root=$1
shift
case "$publication_root" in
/*) ;;
*)
echo "badge publication root must be an absolute path: $publication_root" >&2
exit 2
;;
esac
if [ ! -d "$publication_root" ] || [ ! -w "$publication_root" ]; then
echo "badge publication root must be an existing writable directory: $publication_root" >&2
exit 2
fi
selected=' '
for badge in "$@"; do
case "$badge" in
coverage|test|version) ;;
*)
echo "unsupported badge: $badge" >&2
exit 2
;;
esac
case "$selected" in
*" $badge "*)
echo "badge selected more than once: $badge" >&2
exit 2
;;
esac
selected="$selected$badge "
source="coverage/$badge.svg"
if [ ! -f "$source" ] || [ ! -s "$source" ] || [ -L "$source" ]; then
echo "required badge must be a regular nonempty file, not a symlink: $source" >&2
exit 2
fi
done
owner_root="$publication_root/idle-org"
project_root="$owner_root/john-slop"
badge_root="$project_root/main"
for directory in "$owner_root" "$project_root"; do
if [ -L "$directory" ] || { [ -e "$directory" ] && [ ! -d "$directory" ]; }; then
echo "badge destination component is not a directory: $directory" >&2
exit 2
fi
mkdir -p "$directory"
chmod 0755 "$directory"
done
if [ -L "$badge_root" ]; then
unlink "$badge_root"
elif [ -e "$badge_root" ] && [ ! -d "$badge_root" ]; then
echo "badge destination is not a directory: $badge_root" >&2
exit 2
fi
mkdir -p "$badge_root"
chmod 0755 "$badge_root"
temporary=
trap 'if [ -n "$temporary" ]; then rm -f "$temporary"; fi' EXIT HUP INT TERM
for badge in "$@"; do
temporary=$(mktemp "$badge_root/.$badge.svg.XXXXXX")
cp "coverage/$badge.svg" "$temporary"
chmod 0644 "$temporary"
mv -f "$temporary" "$badge_root/$badge.svg"
temporary=
echo "published $badge badge to $badge_root/$badge.svg"
done
trap - EXIT HUP INT TERM

View File

@ -0,0 +1,18 @@
#!/bin/sh
set -eu
usage() {
echo "usage: $0 <line-coverage-percent> <output.svg>" >&2
exit 2
}
[ "$#" -eq 2 ] || usage
percent=$1
output=$2
script_dir=$(CDPATH= cd -P "$(dirname "$0")" && pwd)
exec "$script_dir/make-badge.sh" coverage \
--value "$percent" \
--label-width 75 \
--value-width 37 \
--output "$output"

25
scripts/render-test-badge.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
set -eu
usage() {
echo "usage: $0 <passing|failing> <output.svg>" >&2
exit 2
}
[ "$#" -eq 2 ] || usage
status=$1
output=$2
case "$status" in
passing|failing) ;;
*)
echo "test badge status must be passing or failing: $status" >&2
exit 2
;;
esac
script_dir=$(CDPATH= cd -P "$(dirname "$0")" && pwd)
exec "$script_dir/make-badge.sh" test \
--value "$status" \
--label-width 45 \
--value-width 55 \
--output "$output"

23
scripts/render-version-badge.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
set -eu
usage() {
echo "usage: $0 <package-version> <output.svg>" >&2
exit 2
}
[ "$#" -eq 2 ] || usage
version=$1
output=$2
case "$version" in
''|*[!0-9A-Za-z.+-]*)
echo "package version contains unsupported badge characters: $version" >&2
exit 2
;;
esac
script_dir=$(CDPATH= cd -P "$(dirname "$0")" && pwd)
exec "$script_dir/make-badge.sh" version \
--value "$version" \
--label-width 59 \
--output "$output"

View File

@ -100,7 +100,19 @@ fn workspace_members_and_resolved_versions_are_synchronized() {
);
}
let badge = fs::read_to_string("badges/version.svg").expect("version badge must be readable");
let temporary = tempfile::tempdir().expect("temporary badge directory must be created");
let badge_path = temporary.path().join("version.svg");
let output = Command::new("scripts/render-version-badge.sh")
.arg(workspace_version)
.arg(&badge_path)
.output()
.expect("version badge renderer must run");
assert!(
output.status.success(),
"version badge rendering failed: {}",
String::from_utf8_lossy(&output.stderr)
);
let badge = fs::read_to_string(badge_path).expect("rendered version badge must be readable");
assert!(
badge.contains(&format!("aria-label=\"version: {workspace_version}\"")),
"version badge must advertise workspace version {workspace_version}"