Skip to content

Publish test-count badges through the documentation site#21

Merged
timlichtenberg merged 2 commits into
mainfrom
tl/badges-branch-publish
Jun 1, 2026
Merged

Publish test-count badges through the documentation site#21
timlichtenberg merged 2 commits into
mainfrom
tl/badges-branch-publish

Conversation

@timlichtenberg
Copy link
Copy Markdown
Member

@timlichtenberg timlichtenberg commented Jun 1, 2026

Description

The test-count badges regenerate from pytest --collect-only, but the old refresh workflow pushed the new JSON back to main, which the branch ruleset blocks for the Actions token. The push failed and the published counts drifted out of step with the suite: the badge read 126 tests while collection now reports 338.

This serves the badges from the documentation site instead of a protected branch. The documentation deploy (docs.yaml) regenerates the three JSON files after building the site and writes them into site/badges/, so they ship with the existing GitHub Pages deployment. The shields.io endpoint URLs point at the site, the standalone push-to-main workflow is removed, and the stale on-main copies are dropped. No branch push, no token, no ruleset bypass.

No issue number; surfaced by the failing "Refresh test count badges" check on the latest main.

Validation of changes

  • Confirmed the Pages site serves nested static files (sitemap.xml, objects.inv, assets/* all return HTTP 200), so badges/tests-*.json resolves at https://proteus-framework.org/CALLIOPE/badges/.
  • Regenerated the badges locally with tools/generate_test_badges.py: total 338, unit 215, integration 123 (the committed copies were 126 / 96 / 30).
  • Confirmed docs.yaml parses as valid YAML and that no /main/.github/badges/ or publish-test-badges references remain in the tree.

The published badge URL resolves once this merges and the documentation redeploys.

Tested on macOS with Python 3.12.

Checklist

  • I have followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have checked that the tests still pass on my computer
  • I have updated the docs, as appropriate
  • I have added tests for these changes, as appropriate
  • I have checked that all dependencies have been updated, as required

@timlichtenberg timlichtenberg requested a review from a team as a code owner June 1, 2026 10:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e2b31a5a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

git config user.email 'actions@github.com'
git add .github/badges
git commit --quiet -m 'ci: refresh test count badges'
git push --quiet --force "$remote" HEAD:badges
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict manual badge publishing to main

When this workflow is run manually with workflow_dispatch on any non-main ref (for example via gh workflow run ... --ref feature-branch, which GitHub supports), the checkout and badge generation use that selected branch's tests but this line still force-pushes the result to the shared public badges branch. A contributor testing a PR branch can therefore overwrite the published badge counts with pre-merge or experimental counts; guard the publish step to refs/heads/main or explicitly check out/count main before updating the shared branch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this workflow is run manually with workflow_dispatch on any non-main ref ... this line still force-pushes the result to the shared public badges branch

Good catch, and it is a real hole in that approach (I hit it myself while testing). This PR has since dropped the branch-push design entirely: publish-test-badges.yml is removed, and the counts are generated during the docs deploy and served from the documentation site. There is no shared badges branch any more, so a workflow_dispatch on a feature ref cannot overwrite the published counts.

The badge-refresh workflow pushed regenerated counts to main, which the
branch ruleset blocks for the Actions token, so the published numbers went
stale. Generate the three test-count JSON files during the documentation
deploy and serve them from the published site, so refreshing the badges needs
no push to a protected branch. The shields.io endpoint URLs point at the site,
the standalone publish workflow is removed, and the stale on-main copies are
dropped.
@timlichtenberg timlichtenberg force-pushed the tl/badges-branch-publish branch from 8e2b31a to 5e625a7 Compare June 1, 2026 11:21
@timlichtenberg timlichtenberg changed the title Publish test-count badges to a dedicated branch Publish test-count badges through the documentation site Jun 1, 2026
@timlichtenberg
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e625a767e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- run: zensical build --clean
- name: Add test-count badges to the site
run: |
pip install ".[develop]"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fetch tags before installing the package

On normal main pushes where HEAD is not itself a release tag, the docs workflow's default actions/checkout is a depth-1 checkout without tag history, but this newly added install now builds a package whose version is derived by setuptools-scm (dynamic = ["version"] with no fallback in pyproject.toml). The deleted badge workflow used fetch-depth: 0 before this same install; without restoring that here, pip install ".[develop]" can fail version detection before tools/generate_test_badges.py runs, so the docs/badge deployment remains broken. The setuptools-scm docs also call out using fetch-depth: 0 for GitHub Actions: https://setuptools-scm.readthedocs.io/en/latest/integrations/

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without restoring [fetch-depth: 0] here, pip install ".[develop]" can fail version detection before tools/generate_test_badges.py runs

Added fetch-depth: 0 to the docs checkout, thanks. One correction for the record: the build does not actually fail without it. I tested a depth-1, no-tags checkout, and setuptools-scm falls back to a 0.0.post1.dev1+g<sha> version and the wheel builds fine; since the badge step only runs pytest --collect-only, the counts are unaffected by the version string. The full fetch is still the right call (it yields the real version and matches the setuptools-scm guidance), just not a deploy-breaker.

The docs deploy now installs the package to count tests for the badges, and
setuptools-scm reads the version from git tags. A shallow checkout has none,
so it falls back to a 0.0.post dev version; fetch the full history so the
build resolves the real version.
@timlichtenberg
Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Member

@nichollsh nichollsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Seems like compiling the badges during the documentation workflow will be more consistent. Personally, I would prefer uploading them to a Gist so that the workflow doesn't have to make any modifications to the GitHub repo directly, but this is a fine alternative.

@timlichtenberg timlichtenberg merged commit 40af425 into main Jun 1, 2026
5 checks passed
@timlichtenberg timlichtenberg deleted the tl/badges-branch-publish branch June 1, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants