ci: publish current coverage badges
Gitea/john-slop/pipeline/head There was a failure building this commit
Details
Gitea/john-slop/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
d672cfdf71
commit
d2f6f01fcd
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
15
AGENTS.md
15
AGENTS.md
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# John Slop
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
John Slop is a local-first linter for concrete signs of low-effort or
|
||||
insufficiently reviewed text and source code. It reports explainable evidence
|
||||
|
|
|
|||
|
|
@ -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 |
|
|
@ -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 |
|
|
@ -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 |
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 <line-coverage-percent> <output.svg>" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
[ "$#" -eq 2 ] || usage
|
||||
percent=$1
|
||||
output=$2
|
||||
|
||||
if [ "$percent" = "-" ]; then
|
||||
rounded=-
|
||||
color='#9f9f9f'
|
||||
else
|
||||
if ! awk -v value="$percent" 'BEGIN {
|
||||
valid = value ~ /^[0-9]+([.][0-9]+)?$/ && value >= 0 && value <= 100
|
||||
exit(valid ? 0 : 1)
|
||||
}'; then
|
||||
echo "coverage percentage must be - or a number from 0 through 100: $percent" >&2
|
||||
exit 2
|
||||
fi
|
||||
rounded=$(awk -v value="$percent" 'BEGIN { printf "%.0f", value }')
|
||||
if [ "$rounded" -ge 90 ]; then
|
||||
color='#4c1'
|
||||
elif [ "$rounded" -ge 70 ]; then
|
||||
color='#dfb317'
|
||||
else
|
||||
color='#e05d44'
|
||||
fi
|
||||
fi
|
||||
|
||||
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/@PERCENT@/${rounded}/g" \
|
||||
-e "s/@COLOR@/${color}/g" \
|
||||
>"$temporary" <<'EOF'
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="112" height="20" role="img" aria-label="coverage: @PERCENT@%">
|
||||
<title>coverage: @PERCENT@%</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="112" height="20" rx="3"/></clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="75" height="20" fill="#555"/>
|
||||
<rect x="75" width="37" height="20" fill="@COLOR@"/>
|
||||
<rect width="112" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" dominant-baseline="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="37.5" y="10">coverage</text>
|
||||
<text x="93.5" y="10">@PERCENT@%</text>
|
||||
</g>
|
||||
</svg>
|
||||
EOF
|
||||
mv "$temporary" "$output"
|
||||
trap - EXIT HUP INT TERM
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#!/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) color='#4c1' ;;
|
||||
failing) color='#e05d44' ;;
|
||||
*)
|
||||
echo "test badge status must be passing or failing: $status" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
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/@STATUS@/${status}/g" \
|
||||
-e "s/@COLOR@/${color}/g" \
|
||||
>"$temporary" <<'EOF'
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="20" role="img" aria-label="tests: @STATUS@">
|
||||
<title>tests: @STATUS@</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="100" height="20" rx="3"/></clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="45" height="20" fill="#555"/>
|
||||
<rect x="45" width="55" height="20" fill="@COLOR@"/>
|
||||
<rect width="100" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" dominant-baseline="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="22.5" y="10">tests</text>
|
||||
<text x="72.5" y="10">@STATUS@</text>
|
||||
</g>
|
||||
</svg>
|
||||
EOF
|
||||
mv "$temporary" "$output"
|
||||
trap - EXIT HUP INT TERM
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#!/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
|
||||
|
||||
value_width=$(awk -v value="$version" 'BEGIN {
|
||||
width = length(value) * 7 + 10
|
||||
print (width < 45 ? 45 : width)
|
||||
}')
|
||||
badge_width=$((59 + value_width))
|
||||
value_center=$(awk -v width="$value_width" 'BEGIN {
|
||||
printf "%.1f", 59 + width / 2
|
||||
}')
|
||||
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/@VERSION@/${version}/g" \
|
||||
-e "s/@BADGE_WIDTH@/${badge_width}/g" \
|
||||
-e "s/@VALUE_WIDTH@/${value_width}/g" \
|
||||
-e "s/@VALUE_CENTER@/${value_center}/g" \
|
||||
>"$temporary" <<'EOF'
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="@BADGE_WIDTH@" height="20" role="img" aria-label="version: @VERSION@">
|
||||
<title>version: @VERSION@</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="20" rx="3"/></clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="59" height="20" fill="#555"/>
|
||||
<rect x="59" width="@VALUE_WIDTH@" height="20" fill="#007ec6"/>
|
||||
<rect width="@BADGE_WIDTH@" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" dominant-baseline="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="29.5" y="10">version</text>
|
||||
<text x="@VALUE_CENTER@" y="10">@VERSION@</text>
|
||||
</g>
|
||||
</svg>
|
||||
EOF
|
||||
mv "$temporary" "$output"
|
||||
trap - EXIT HUP INT TERM
|
||||
|
|
@ -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}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue