ci: generate and publish current badges
This commit is contained in:
parent
b8df3cc142
commit
c300fe3fb3
|
|
@ -29,6 +29,7 @@ testepo*
|
|||
naming.json
|
||||
config.toml
|
||||
tarpaulin-report.html
|
||||
/coverage/
|
||||
|
||||
# Local repositories used for manual CLI testing and IDE inspection.
|
||||
/.local/
|
||||
|
|
|
|||
|
|
@ -380,6 +380,8 @@ These require user approval and are not part of the current implementation:
|
|||
position tests; document and provide a runnable `lib_efo` repository example.
|
||||
- [x] Configure Tarpaulin around its subprocess-attribution limitation and
|
||||
refresh `rust_autobadges` at a directly measured coverage level above 70%.
|
||||
- [x] Generate version, test, and measured-coverage badges in Jenkins cleanup;
|
||||
archive all branches and safely publish only `main` under the shared asset root.
|
||||
|
||||
## TUI release-readiness pass
|
||||
|
||||
|
|
|
|||
|
|
@ -55,8 +55,9 @@ workflows. Tests that touch a repository must use a temporary directory and
|
|||
must not depend on execution order. Snapshot tests are appropriate for stable
|
||||
human output; assertions on structured data are preferred for persistence.
|
||||
|
||||
Tarpaulin and `rust_autobadges` are release-time tools. Do not run them in CI or
|
||||
for routine commits. Refresh their badges only for a significant release.
|
||||
Tarpaulin runs in CI with the tracked configuration and its documented line-
|
||||
coverage floor. Do not restore `rust_autobadges`; Jenkins renders and publishes
|
||||
the mutable badges from verified test and coverage results.
|
||||
|
||||
## Documentation and commits
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ pipeline {
|
|||
environment {
|
||||
CARGO_TERM_COLOR = 'always'
|
||||
RUST_BACKTRACE = '1'
|
||||
CARGO_TARPAULIN_VERSION = '0.37.5'
|
||||
BADGE_PUBLICATION_ROOT = '/mnt/assets/coverage'
|
||||
BADGE_OWNER = 'idle-org'
|
||||
BADGE_PROJECT = 'epoch_forge'
|
||||
BADGE_DEFAULT_BRANCH = 'main'
|
||||
}
|
||||
|
||||
stages {
|
||||
|
|
@ -19,6 +24,11 @@ pipeline {
|
|||
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
|
||||
# Jenkins may reuse workspaces. Never trust badges or
|
||||
# completion markers left by an earlier build.
|
||||
rm -rf -- coverage
|
||||
mkdir -m 0755 coverage
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +59,16 @@ pipeline {
|
|||
cargo --version
|
||||
rustfmt --version
|
||||
cargo clippy --version
|
||||
|
||||
if ! cargo tarpaulin --version 2>/dev/null \
|
||||
| grep -F "$CARGO_TARPAULIN_VERSION" >/dev/null; then
|
||||
echo "Installing cargo-tarpaulin $CARGO_TARPAULIN_VERSION..."
|
||||
cargo install cargo-tarpaulin \
|
||||
--version "$CARGO_TARPAULIN_VERSION" \
|
||||
--locked
|
||||
fi
|
||||
|
||||
cargo tarpaulin --version
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
|
@ -90,6 +110,50 @@ pipeline {
|
|||
--all-targets \
|
||||
--all-features \
|
||||
--locked
|
||||
|
||||
case "$BUILD_NUMBER" in
|
||||
''|*[!0-9]*)
|
||||
echo "ERROR: BUILD_NUMBER is not numeric: $BUILD_NUMBER" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
: > "coverage/.tests-passed-$BUILD_NUMBER"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Coverage') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eu
|
||||
|
||||
echo "Measuring workspace line coverage (minimum 65%)..."
|
||||
cargo tarpaulin \
|
||||
--workspace \
|
||||
--all-features \
|
||||
--locked \
|
||||
--output-dir coverage
|
||||
|
||||
summary=coverage/tarpaulin-report.json
|
||||
[ -f "$summary" ] && [ -s "$summary" ] || {
|
||||
echo "ERROR: Tarpaulin did not create $summary." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
coverage_value=$(sed -n \
|
||||
's/.*"coverage":\([0-9][0-9.]*\),"covered":[0-9][0-9]*,"coverable":[0-9][0-9]*}$/\1/p' \
|
||||
"$summary")
|
||||
if ! awk -v value="$coverage_value" 'BEGIN {
|
||||
valid = value ~ /^[0-9]+([.][0-9]+)?$/ && value >= 0 && value <= 100
|
||||
exit(valid ? 0 : 1)
|
||||
}'; then
|
||||
echo "ERROR: invalid overall coverage in $summary: $coverage_value" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
scripts/ci-coverage-badges.sh coverage --value "$coverage_value"
|
||||
rm -f "$summary"
|
||||
: > "coverage/.coverage-ready-$BUILD_NUMBER"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +168,9 @@ pipeline {
|
|||
--workspace \
|
||||
--all-targets \
|
||||
--all-features \
|
||||
--locked
|
||||
--locked \
|
||||
-- \
|
||||
-D warnings
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
|
@ -133,8 +199,8 @@ pipeline {
|
|||
publishChecks(
|
||||
conclusion: 'SUCCESS',
|
||||
name: 'Rust CI',
|
||||
summary: 'Epoch Forge passed all CI checks.',
|
||||
text: 'Formatting, workspace checks, tests, Clippy, and the release build completed successfully.',
|
||||
summary: 'Epoch Forge passed tests, coverage, and all CI checks.',
|
||||
text: 'Formatting, workspace checks, tests, the coverage floor, Clippy, and the release build passed. Badge artifacts are finalized during cleanup.',
|
||||
title: 'Build Successful'
|
||||
)
|
||||
|
||||
|
|
@ -146,7 +212,7 @@ pipeline {
|
|||
conclusion: 'FAILURE',
|
||||
name: 'Rust CI',
|
||||
summary: 'Epoch Forge failed CI.',
|
||||
text: 'Formatting, compilation, tests, Clippy, or the release build failed. Check the Jenkins log.',
|
||||
text: 'Formatting, compilation, tests, coverage, Clippy, or the release build failed. Cleanup still generates current badge artifacts; check the Jenkins log.',
|
||||
title: 'Build Failed'
|
||||
)
|
||||
|
||||
|
|
@ -158,11 +224,80 @@ pipeline {
|
|||
conclusion: 'ACTION_REQUIRED',
|
||||
name: 'Rust CI',
|
||||
summary: 'Epoch Forge CI is unstable.',
|
||||
text: 'The Jenkins build completed with an unstable status.',
|
||||
text: 'The Jenkins build is unstable. Cleanup still generates current test, coverage, and version badge artifacts.',
|
||||
title: 'Build Unstable'
|
||||
)
|
||||
|
||||
echo '⚠️ Epoch Forge CI is unstable.'
|
||||
}
|
||||
|
||||
cleanup {
|
||||
script {
|
||||
sh '''
|
||||
set -eu
|
||||
|
||||
test_marker="coverage/.tests-passed-$BUILD_NUMBER"
|
||||
coverage_marker="coverage/.coverage-ready-$BUILD_NUMBER"
|
||||
|
||||
if [ -f "$test_marker" ]; then
|
||||
scripts/ci-coverage-badges.sh test --value passing
|
||||
else
|
||||
scripts/ci-coverage-badges.sh test --value failing
|
||||
fi
|
||||
|
||||
if [ ! -f "$coverage_marker" ]; then
|
||||
scripts/ci-coverage-badges.sh coverage --value -
|
||||
fi
|
||||
|
||||
version=$(awk '
|
||||
/^\[package\][[:space:]]*$/ { in_package = 1; next }
|
||||
/^\[/ && in_package { exit }
|
||||
in_package && /^[[:space:]]*version[[:space:]]*=/ {
|
||||
line = $0
|
||||
sub(/^[^=]*=[[:space:]]*"/, "", line)
|
||||
sub(/"[[:space:]]*$/, "", line)
|
||||
print line
|
||||
exit
|
||||
}
|
||||
' bin_efo/Cargo.toml)
|
||||
[ -n "$version" ] || {
|
||||
echo "ERROR: could not read efo version from bin_efo/Cargo.toml." >&2
|
||||
exit 1
|
||||
}
|
||||
scripts/ci-coverage-badges.sh version --value "$version"
|
||||
|
||||
rm -f coverage/tarpaulin-report.json \
|
||||
"$test_marker" "$coverage_marker"
|
||||
|
||||
for badge in version test coverage; do
|
||||
path="coverage/$badge.svg"
|
||||
if [ -L "$path" ] || [ ! -f "$path" ] || [ ! -s "$path" ]; then
|
||||
echo "ERROR: invalid badge artifact: $path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
'''
|
||||
|
||||
archiveArtifacts(
|
||||
allowEmptyArchive: false,
|
||||
artifacts: 'coverage/version.svg,coverage/test.svg,coverage/coverage.svg',
|
||||
fingerprint: true
|
||||
)
|
||||
|
||||
if (env.BRANCH_NAME == env.BADGE_DEFAULT_BRANCH) {
|
||||
sh '''
|
||||
set -eu
|
||||
scripts/publish-ci-coverage-badges.sh \
|
||||
"$BADGE_PUBLICATION_ROOT" \
|
||||
"$BADGE_OWNER" \
|
||||
"$BADGE_PROJECT" \
|
||||
"$BADGE_DEFAULT_BRANCH" \
|
||||
version test coverage
|
||||
'''
|
||||
} else {
|
||||
echo "Skipping public badge publication for branch ${env.BRANCH_NAME ?: '(unset)'}; default is ${env.BADGE_DEFAULT_BRANCH}."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
README.md
27
README.md
|
|
@ -1,6 +1,6 @@
|
|||
# Epoch Forge
|
||||
|
||||
  
|
||||
  
|
||||
|
||||
Epoch Forge (`efo`) is an early-alpha command-line tool for managing a game's
|
||||
world or organisation across a sequence of snapshots called **epochs**. It is
|
||||
|
|
@ -123,11 +123,26 @@ cargo test --workspace --all-targets --all-features --locked
|
|||
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
|
||||
```
|
||||
|
||||
Tarpaulin and `rust_autobadges` are intentionally release-only. They do not run
|
||||
in routine CI because of their cost; badge files are refreshed for significant
|
||||
releases. The Tarpaulin configuration excludes the thin CLI adapters because
|
||||
their subprocess integration tests cannot be attributed reliably by its ptrace
|
||||
backend; library and TUI code remain directly measured.
|
||||
CI runs the pinned `cargo-tarpaulin` 0.37.5 release with:
|
||||
|
||||
```bash
|
||||
cargo tarpaulin --workspace --all-features --locked --output-dir coverage
|
||||
```
|
||||
|
||||
The tracked Tarpaulin configuration enforces at least 65% line coverage across
|
||||
all production code. CLI subprocess tests remain valuable even though
|
||||
Tarpaulin cannot attribute their child execution, so those adapters stay in the
|
||||
measured surface. The temporary machine-readable summary is
|
||||
`coverage/tarpaulin-report.json`. The authoritative version is the `efo`
|
||||
package version in `bin_efo/Cargo.toml`.
|
||||
|
||||
Jenkins archives exactly `coverage/version.svg`, `coverage/test.svg`, and
|
||||
`coverage/coverage.svg`. Default-branch builds publish them under
|
||||
`/mnt/assets/coverage/idle-org/epoch_forge/main/`; the public URLs are the three
|
||||
badge images directly below this README's title. The asset mount should be
|
||||
read-only to the public server, with directory listing disabled, a restrictive
|
||||
SVG content security policy, and revalidation or a short cache lifetime for
|
||||
these mutable URLs.
|
||||
|
||||
## Release archives
|
||||
|
||||
|
|
|
|||
|
|
@ -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: 78%"><title>test-coverage: 78%</title><linearGradient id="bms-45525ec477e25d94" 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-45525ec477e25d94"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-45525ec477e25d94)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-45525ec477e25d94)"/></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">78%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">78%</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="104" height="18" role="img" aria-label="version: 1.0.228"><title>version: 1.0.228</title><linearGradient id="bms-ed89fff123285f2c" 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-ed89fff123285f2c"><rect width="104" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-ed89fff123285f2c)"><rect width="51" height="18" fill="#555"/><rect x="51" width="53" height="18" fill="#fe7d37"/><rect width="104" height="18" fill="url(#bms-ed89fff123285f2c)"/></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="765" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">1.0.228</text><text x="765" y="130" transform="scale(.1)" fill="#fff" textLength="430">1.0.228</text></g></svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
|
|
@ -34,11 +34,13 @@ The TUI retains the prior entity for one-step, conflict-checked undo.
|
|||
|
||||
Library tests cover parsing, statistics, display snapshots, entity/epoch
|
||||
behavior, and repository transactions. CLI behavior is covered by subprocess
|
||||
integration workflows; Tarpaulin excludes those thin adapters because its
|
||||
ptrace backend cannot reliably attribute child-process execution. Routine CI
|
||||
should run formatting, all-target workspace tests, strict Clippy, and a release
|
||||
build. Tarpaulin and `rust_autobadges` remain local significant-release-only
|
||||
tools. See [AGENTS.md](../AGENTS.md) for contributor rules.
|
||||
integration workflows. Tarpaulin cannot attribute child-process execution to
|
||||
the thin CLI adapters, but keeps all production code in the measured surface.
|
||||
Routine CI runs formatting, all-target workspace tests, strict Clippy, a
|
||||
release build, and pinned Tarpaulin line coverage with the documented 65%
|
||||
floor. During cleanup, Jenkins generates, archives, and conditionally publishes
|
||||
the three mutable badges so failed builds cannot leave stale success or
|
||||
coverage status. See [AGENTS.md](../AGENTS.md) for contributor rules.
|
||||
|
||||
`epoch_resolution` owns independent baseline previews and exact contribution
|
||||
reduction for adjudication, diffusion arrivals, and conflict rounds. CLI handlers
|
||||
|
|
|
|||
|
|
@ -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/&/\&/g' \
|
||||
-e 's/</\</g' \
|
||||
-e 's/>/\>/g' \
|
||||
-e 's/"/\"/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
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 ROOT OWNER PROJECT DEFAULT_BRANCH BADGE..." >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
[ "$#" -ge 5 ] || usage
|
||||
root=$1
|
||||
owner=$2
|
||||
project=$3
|
||||
default_branch=$4
|
||||
shift 4
|
||||
|
||||
case "$root" in
|
||||
/*) ;;
|
||||
*) echo "publication root must be absolute: $root" >&2; exit 2 ;;
|
||||
esac
|
||||
[ -d "$root" ] || { echo "publication root is not a directory: $root" >&2; exit 2; }
|
||||
[ -w "$root" ] || { echo "publication root is not writable: $root" >&2; exit 2; }
|
||||
|
||||
validate_component() {
|
||||
component_name=$1
|
||||
component_value=$2
|
||||
case "$component_value" in
|
||||
''|.|..|*[!A-Za-z0-9._-]*)
|
||||
echo "$component_name is not a safe path component: $component_value" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
validate_component owner "$owner"
|
||||
validate_component project "$project"
|
||||
validate_component default-branch "$default_branch"
|
||||
|
||||
badges=
|
||||
for name in "$@"; do
|
||||
case "$name" in
|
||||
coverage|test|version) ;;
|
||||
*) echo "unsupported badge name: $name" >&2; exit 2 ;;
|
||||
esac
|
||||
case " $badges " in
|
||||
*" $name "*) echo "duplicate badge name: $name" >&2; exit 2 ;;
|
||||
esac
|
||||
source_file="coverage/$name.svg"
|
||||
if [ -L "$source_file" ] || [ ! -f "$source_file" ] || [ ! -s "$source_file" ]; then
|
||||
echo "badge source must be a regular, nonempty, non-symlink file: $source_file" >&2
|
||||
exit 2
|
||||
fi
|
||||
badges="$badges $name"
|
||||
done
|
||||
|
||||
ensure_directory() {
|
||||
directory=$1
|
||||
description=$2
|
||||
if [ -L "$directory" ]; then
|
||||
echo "$description must not be a symlink: $directory" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ -e "$directory" ] && [ ! -d "$directory" ]; then
|
||||
echo "$description is not a directory: $directory" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ ! -d "$directory" ]; then
|
||||
mkdir "$directory"
|
||||
fi
|
||||
chmod 0755 "$directory"
|
||||
}
|
||||
|
||||
owner_dir="$root/$owner"
|
||||
ensure_directory "$owner_dir" "owner path"
|
||||
project_dir="$owner_dir/$project"
|
||||
ensure_directory "$project_dir" "project path"
|
||||
destination="$project_dir/$default_branch"
|
||||
|
||||
if [ -L "$destination" ]; then
|
||||
rm -f "$destination"
|
||||
elif [ -e "$destination" ] && [ ! -d "$destination" ]; then
|
||||
echo "default-branch path is not a directory: $destination" >&2
|
||||
exit 2
|
||||
fi
|
||||
ensure_directory "$destination" "default-branch path"
|
||||
|
||||
temporary=
|
||||
cleanup() {
|
||||
if [ -n "$temporary" ]; then
|
||||
rm -f "$temporary"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
for name in $badges; do
|
||||
source_file="coverage/$name.svg"
|
||||
temporary="$destination/.$name.svg.tmp.$$"
|
||||
cp "$source_file" "$temporary"
|
||||
chmod 0644 "$temporary"
|
||||
mv "$temporary" "$destination/$name.svg"
|
||||
temporary=
|
||||
done
|
||||
|
||||
trap - EXIT HUP INT TERM
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
[coverage]
|
||||
workspace = true
|
||||
all-features = true
|
||||
exclude-files = ["bin_efo/src/*"]
|
||||
fail-under = 65
|
||||
|
||||
[report]
|
||||
out = ["Html"]
|
||||
out = ["Json"]
|
||||
|
||||
# CLI behavior is exercised through subprocess integration tests. Tarpaulin's
|
||||
# ptrace backend cannot attribute those child executions reliably (and its
|
||||
# follow-exec mode currently segfaults), so measure the directly instrumented
|
||||
# library and TUI code rather than reporting every CLI adapter as uncovered.
|
||||
# Keep all production code in the measured surface. CLI subprocess tests are
|
||||
# still valuable even though Tarpaulin cannot attribute their child execution.
|
||||
|
|
|
|||
Loading…
Reference in New Issue