Skip to content

ci(nrg): generate README.md and README.fr.md from a single template#489

Open
andriishin wants to merge 1 commit intocodegouvfr:mainfrom
andriishin:nrg-readme-template
Open

ci(nrg): generate README.md and README.fr.md from a single template#489
andriishin wants to merge 1 commit intocodegouvfr:mainfrom
andriishin:nrg-readme-template

Conversation

@andriishin
Copy link
Copy Markdown

What this changes

README.md and README.fr.md are currently maintained as two hand-edited files (~6.5 KB each, 130 / 127 lines). About 28% of their lines are byte-identical (HTML wrappers, badge anchors, image tags), the rest is the same prose translated into the other language.

This PR consolidates them into a single source — README.src.md — and adds a GitHub Action (nanolaba/nrg-action@v1) that regenerates both on push to main.

After the merge: both rendered files on GitHub are unchanged; future content edits land in README.src.md once, and the bot updates both files in a single follow-up commit.

Byte-perfect preservation

Locally regenerated with NRG 1.2 — diff vs current main:

README.md       3 metadata-header insertions (only)
README.fr.md    3 metadata-header insertions (only)

No translation content, link, code block, badge, image, or HTML element changed. The 3-line metadata header marks each output as auto-generated:

<!-- This file was automatically generated by Nanolaba Readme Generator (NRG) 1.2 -->
<!-- Visit https://github.com/nanolaba/readme-generator for details -->

How the template works

  • Lines tagged <!--en--> only render in README.md.
  • Lines tagged <!--fr--> only render in README.fr.md.
  • Untagged lines render in both — about 28% of the template (HTML structure, badges, image tags).

Adding a third language later (e.g. Spanish) is purely additive — append es to <!--@nrg.languages=...-->, add <!--@nrg.fileNamePattern.es=README.es.md-->, and add <!--es-->-tagged lines next to existing <!--en--> / <!--fr--> lines. Existing files stay untouched.

CI behavior

Two jobs in .github/workflows/nrg.yml:

  • regenerate (push to main, when README.src.md or the workflow itself changes) — regenerates both READMEs and commits them as github-actions[bot].
  • drift-check (pull_request, when any tracked README or the template changes) — fails the PR if a contributor hand-edited a generated file, with a unified diff pointing back at README.src.md.

Both jobs pinned to nrg-version: '1.2'. The action itself is pinned to a commit SHA (not the floating @v1 tag) for supply-chain hygiene. Permissions scoped per-job: regenerate gets contents: write for git push, drift-check stays read-only.

If you don't want this

Easy to revert — drop README.src.md, drop .github/workflows/nrg.yml, restore the two README files. Happy to discuss alternative shapes if the byte-perfect-mirror approach isn't right for your workflow.

Adds README.src.md as the single source for the existing two READMEs and
wires up nanolaba/nrg-action@v1 to regenerate them on push to main. A
drift-check job on PRs catches any direct hand-edits to a generated
file with a clear diff pointing back at README.src.md.

Output preserves both files byte-for-byte except for a 3-line auto-
generated header injected at the top of each. No translation content,
link, code block, badge, or HTML structural element changed.

How the template works:

  - README.src.md uses per-line <!--en--> / <!--fr--> markers for
    translated bits. Untagged lines (HTML wrappers, badge anchors,
    img tags, <br>) render in both — about 28% of the template is
    shared structural code.
  - Default file-name pattern produces README.md (default lang = en);
    nrg.fileNamePattern.fr maps the fr output to README.fr.md.

CI behavior:

  - regenerate (push to main, README.src.md or workflow changes)
    regenerates both READMEs and commits as github-actions[bot].
  - drift-check (pull_request) fails the PR if a contributor hand-
    edits a generated README.

Hardenings: workflow default permissions = contents: read; regenerate
job overrides to contents: write only where needed for git push.
nanolaba/nrg-action pinned to commit SHA for supply-chain hygiene.
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.

1 participant