12 KiB
Publish current CI badges through the assets mount
Apply this task to one repository at a time. Read the repository's local agent instructions, inspect its existing CI and coverage setup, preserve unrelated work, and follow its commit policy. Do not push or publish outside CI unless the user explicitly requests it.
Goal
Make the default branch expose three small, current SVG badges:
<asset-mount>/coverage/<owner>/<project>/<default-branch>/version.svg
<asset-mount>/coverage/<owner>/<project>/<default-branch>/test.svg
<asset-mount>/coverage/<owner>/<project>/<default-branch>/coverage.svg
<asset-origin>/coverage/<owner>/<project>/<default-branch>/version.svg
<asset-origin>/coverage/<owner>/<project>/<default-branch>/test.svg
<asset-origin>/coverage/<owner>/<project>/<default-branch>/coverage.svg
Discover the canonical owner, project name, default branch, asset mount, and public asset origin from repository or CI configuration. Do not infer them only from the local checkout directory. Keep the default-branch component stable; these URLs describe the latest default-branch build, not an immutable commit.
Retain only the three badges as Jenkins artifacts. Do not publish or retain commit-addressed coverage directories, HTML, JSON, LCOV, or other detailed reports unless the repository already has a separate requirement for them.
This task is complete only when all three badges are present in the README,
generated by CI, archived by Jenkins, and copied by a default-branch build to
the resolved asset mount below coverage/<owner>/<project>/<default-branch>/.
When the deployment contract uses /mnt/assets, verify the resulting files at
these exact filesystem paths rather than merely checking a similarly named
workspace or archive directory:
/mnt/assets/coverage/<owner>/<project>/<default-branch>/version.svg
/mnt/assets/coverage/<owner>/<project>/<default-branch>/test.svg
/mnt/assets/coverage/<owner>/<project>/<default-branch>/coverage.svg
Do not report the task as successful when only scripts or pipeline definitions were added. A configured operation, an archived artifact, a file in the Jenkins workspace, and a file below the publication mount are four different states; verify each required state explicitly.
CI behavior
- Remove or recreate the workspace
coverage/output directory at the start of the build so files from an earlier run cannot satisfy later checks. - Use the project's established test and line-coverage tools. Pin tools that CI installs itself, and keep tool configuration in the conventional tracked project file.
- Enforce an honest coverage floor supported by useful behavior tests. Do not exclude ordinary production code or distort code or tests to increase the percentage.
- Produce a temporary machine-readable coverage summary, extract and validate
a numeric percentage from 0 through 100, render
coverage/coverage.svg, and remove the summary. - Read the version from authoritative package or build metadata and render
coverage/version.svg. Do not duplicate the version in CI configuration. - Write a build-specific marker only after the test stage succeeds. In an
always-run cleanup action, render
coverage/test.svgaspassingonly when that marker exists; otherwise render it asfailing. Remove the marker afterward so an old workspace cannot affect a later build. - If coverage did not complete, render a neutral
-%badge during cleanup. Cleanup must run for both successful and failed builds so published status cannot silently remain stale. - Before archival or publication, enumerate the selected files and require all three expected names to be regular, nonempty, non-symlink files that parse as XML. Fail if any is absent or if an unexpected file is selected.
- Archive exactly the three nonempty SVG files with fingerprinting on every
branch. Do not use
allowEmptyArchive, broad|| true, exception swallowing, or another fallback that converts missing badge output into CI success. - Publish all three badges only from the resolved default branch. Confirm the branch condition actually runs in the Jenkins job type in use; a branch predicate that silently skips the real default branch is a failure. A missing or unwritable publication mount is a CI failure, not a reason to print a warning and continue.
- Keep rendering and filesystem publication in small tracked scripts rather
than large Jenkins shell blocks. Use the repository's existing scripting
language when suitable; otherwise use portable POSIX
sh.
Update the Jenkins success and failure summaries to mention tests, coverage, badge generation, and any other gates that the pipeline actually runs. Success output must identify the resolved publication directory. Failure output must identify the phase and missing or rejected path without hiding the original build error.
Renderer contract
Render badges locally and deterministically. Do not call an external badge service.
- The version renderer accepts only characters valid for the project's version format, grows the value segment for long versions, and enforces a sensible minimum width.
- The test renderer accepts only
passingorfailingand selects green or red respectively. - The coverage renderer accepts
-or a number from 0 through 100, rounds numeric values, and selects documented green, yellow, red, or neutral colors. - Reject invalid input before creating or replacing output.
- Escape all text inserted into XML.
- Center labels and values horizontally with
text-anchor="middle". In a 20-pixel badge, center text vertically aty="10"withdominant-baseline="middle"instead of treatingyas a font baseline. - When POSIX
awkprints a conditional expression, parenthesize it, for exampleprint (width < 45 ? 45 : width), so the expression also works with FreeBSD awk.
Publication contract
The publication script receives the publication root and an explicit allow-listed set of badge names. It must:
- require an absolute publication root and validate all arguments before changing published state;
- create only the required owner, project, and default-branch directories;
- publish only
coverage.svg,test.svg, andversion.svgbelow the resolved default-branch directory; - verify every selected source badge exists, is a regular nonempty file, and is not a symlink;
- migrate an old default-branch symlink by unlinking the symlink itself without deleting its target, and reject any other non-directory branch destination;
- make directories mode
0755and badges mode0644so the web server can traverse and read them even under a restrictive umask; - copy each badge to a temporary file in its destination directory and rename it atomically over the public file;
- after each rename, require the destination to be a regular, nonempty, non-symlink file and compare it with the source so a partial or misdirected copy cannot be reported as published;
- clean temporary files on ordinary failures and signals;
- quote paths and remain portable to the Jenkins worker's operating system;
- never recursively synchronize, prune, or delete the shared asset mount.
Exit nonzero with a message on standard error when validation, directory creation, copying, permissions, renaming, or post-copy verification fails. The message must name the operation and safe path involved. Never print a success message before all selected badges have passed post-copy verification.
Do not automatically remove old commit-addressed directories. That is a separate destructive migration requiring explicit authorization and exact path verification.
Repository updates
Place the live badges immediately below the README title, substituting the resolved values:



Editing the README is a required deliverable, not optional follow-up. After the edit, search the rendered source and require each resolved badge URL exactly once in an image reference. Check that no old owner, project, default branch, filename, or asset origin remains in another badge block. A successful CI setup without these README references does not complete this task.
Do not link them to a report that CI does not retain. Document the local coverage command, enforced floor, version source, temporary summary, archived files, publication path, and public URLs. Remove tracked generated badge files and obsolete status snapshots.
If this task also owns the web-server configuration, mount public assets read-only, disable directory listing, serve SVG with a restrictive content security policy, and revalidate or use a short cache lifetime for mutable badge URLs. Otherwise record these as deployment requirements without expanding the repository change into unrelated infrastructure work.
Verification
Before committing:
- Run the repository's formatting, build/check, test, lint, and supported toolchain gates relevant to the change.
- Run the exact CI coverage command and confirm the enforced floor.
- Confirm the temporary summary yields a valid percentage, is removed, and exactly three nonempty SVGs are selected for archival.
- Exercise normal and long versions, passing and failing test states, green, yellow, red, and neutral coverage, and invalid input rejection.
- Parse every rendered file as XML and rasterize representative badges to inspect text placement.
- Test publication with
umask 077against a temporary absolute root. Verify modes, atomic replacement, idempotence, and old-symlink migration without deleting the old target. - Verify rejection of missing badges, relative roots, unwritable destinations, and regular-file branch destinations.
- Verify the README contains each resolved public badge URL exactly once and that all three image references render directly below the title.
- On an actual default-branch Jenkins build, confirm the generation log names
all three workspace files, the archive contains exactly those files, and the
publication stage runs rather than being skipped. Inspect the resolved
destination below
/mnt/assetswhen that is the configured mount and compare all three published files with the generated sources. - Request each public URL without relying on a browser cache, require an SVG response, parse it as XML, and confirm its displayed value matches the build that published it. A pre-existing or stale public file is not evidence that the current operation succeeded.
- Validate Jenkins syntax as far as local tooling permits, inspect the final diff, commit the change, and confirm the worktree is clean.
Failure reporting and handoff
Never silently downgrade a required check, and never describe the operation as successful merely because the repository changes are committed. If any badge is not added to the README, generated, archived, copied to the configured asset mount, or served at its public URL, tell the calling agent or user that the badge operation failed or remains incomplete and explain why.
The final report must give a separate status for each of these checkpoints:
- README references;
- CI generation;
- Jenkins archival;
- default-branch publication to the resolved mount; and
- public URL retrieval and content validation.
For every failed, skipped, or unavailable checkpoint, report the failing phase, the expected safe path or URL, the observed error or evidence, and the next action needed. Distinguish a reproducible failure from a check that could not be performed because Jenkins, the mount, credentials, network access, or the default branch was unavailable. Do not invent results, treat unavailable as passed, or hide an earlier failure behind successful cleanup or badge rendering.
Report the measured coverage, enforced floor, checks run, commit ID, and the five checkpoint statuses above. Do not claim the public badges are live until a successful default-branch Jenkins build has generated and archived the badges, copied all three to the resolved publication directory, and their uncached public responses have been validated.