Skip to Content

publish_repo_badges.sh

Repository‑Local Test Badge Publisher for PMIverse and PMISuite

Purpose

publish_repo_badges.sh copies the latest pytest badge artifacts (SVG files) generated by run_pytest_repo.sh into a target repository under:

.badges/tests/

This enables README‑embedded badges that render directly from the repository, similar to OCA's self‑contained badge system. No external CI badge hosting is required.

The script optionally performs Git commit and push operations to publish the badges automatically.


Badge Workflow Overview

run_pytest_repo.sh  →  Generates badges (SVG)
        ↓
/srv/pmiverse/logs/tests/latest/badges/
        ↓
publish_repo_badges.sh  →  Copies SVGs into repo/.badges/tests/
        ↓
README.md can embed badges:
    ![](./.badges/tests/<badge>.svg)

This achieves reproducible, portable badge rendering across deployments and mirrors the OCA project model.


Features

1. Badge Publishing

  • Copies all SVG test badges (summary + per‑addon) from a log directory.
  • Default source directory:
/srv/pmiverse/logs/tests/latest/badges

2. Repository Integration

Creates or updates:

<repo>/.badges/tests/

These badges can then be referenced in README.md:

![Tests](./.badges/tests/summary.svg)
![my_addon](./.badges/tests/my_addon.svg)

3. Optional Git Commit and Push

If --commit is provided:

External write: This mode creates a commit and pushes it. Obtain explicit approval before using it; omit --commit for a local copy-only operation.

  • Stages .badges/tests/*.svg
  • Creates a chore commit
  • Pushes to the selected branch

If --branch is provided, the script switches to that branch before committing.

4. Designed for Automation

Can be used manually or integrated into CI pipelines to automatically publish updated badges.


Usage

publish_repo_badges.sh --repo <repo_root> \
    [--source <logs_dir>] \
    [--commit] \
    [--branch <name>]

Arguments


Option Description


--repo <path> Target repository root. Required.

--source <path> Badge source directory (default: /srv/pmiverse/logs/tests/latest/badges).

--commit Commit and push badge updates.

--branch <name> Branch to commit into (default: current Git HEAD).

-h, --help Show inline script help.



Examples

1. Copy badges into a repository

./publish_repo_badges.sh --repo /srv/repos/my_project

2. Copy badges from a custom logs directory

./publish_repo_badges.sh --repo my_repo --source /tmp/test_badges/

3. Copy badges and push them to the current branch

./publish_repo_badges.sh --repo my_repo --commit

4. Copy badges and push them to a specific branch

./publish_repo_badges.sh --repo my_repo --commit --branch staging

Behaviour Summary

  • Ensures destination directory .badges/tests exists.
  • Copies all *.svg badge files from the source directory.
  • If --commit is used:
    • Optional branch checkout
    • Git add, commit, and push
    • Skips commit if no changes detected

Logs output to stdout for CI compatibility.


Requirements

  • Bash 4+
  • Git (if using commit/push functionality)
  • Badge generator run_pytest_repo.sh (or equivalent) must already have produced SVG badges.

Integration in README.md

Example README embedding:

## Test Status

![Overall Tests](./.badges/tests/summary.svg)
![Module A](./.badges/tests/module_a.svg)
![Module B](./.badges/tests/module_b.svg)

These links will always reflect the latest published badges.


Failure Modes and Handling

Condition Script Behaviour


Missing --repo Exits with error. Missing source badge directory Exits with error. No SVG files present Copies nothing (non‑fatal). Git commit requested but no badge changes No commit created. Invalid branch name Git checkout will fail.


CI/CD Usage Recommendation

Typical pattern:

run_pytest_repo.sh  # generate badges
publish_repo_badges.sh --repo $REPO --commit --branch $BRANCH

This ensures badges reflect the test results of the latest CI run.


License

Copyright (c) 2025\ LUXIM d.o.o., Slovenia --- Matjaž Mozetič\ Part of PMISuite.

See the repository-level README.md for the repository license statement.