Skip to content

ci(nrg): generate README.md and README.zh_CN.md from a single template#118

Open
andriishin wants to merge 1 commit into
leonchen83:masterfrom
andriishin:nrg-readme-template
Open

ci(nrg): generate README.md and README.zh_CN.md from a single template#118
andriishin wants to merge 1 commit into
leonchen83:masterfrom
andriishin:nrg-readme-template

Conversation

@andriishin
Copy link
Copy Markdown

What this changes

README.md and README.zh_CN.md are currently maintained as two separate hand-edited files (~30 KB / 32 KB, 739 / 755 lines). Every commit that touches one needs a parallel edit to the other — with two big files and a non-trivial section structure (TOC + 9 top-level sections + nested sub-sections), that's brittle.

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 master.

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 master:

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

No translation content, link, code block, image, anchor, or heading 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 -->

It signals to future contributors not to hand-edit, and the drift-check job below enforces it on PRs.

How the template works

  • Lines tagged <!--en--> only render in README.md.
  • Lines tagged <!--zh--> only render in README.zh_CN.md.
  • Untagged lines render in both — used for code-block contents and a few shared structural lines.

Most of the template is per-language (TOC entries with locale-specific anchors, prose, headings) — that's just the nature of two large translated docs. The shared parts are mostly the Java code blocks and mvn snippets.

Adding a third language later is purely additive — append ja to <!--@nrg.languages=...-->, add <!--@nrg.fileNamePattern.ja=README.ja.md-->, and add <!--ja-->-tagged lines next to existing <!--en--> lines. Existing files stay untouched.

CI behavior

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

  • regenerate (push to master, 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.

This pom.xml Java project is also eligible for the nrg-maven-plugin — drop a 10-line plugin block into pom.xml and mvn package regenerates the READMEs locally, no separate workflow needed. Happy to add that as a follow-up if you'd prefer it over the GitHub Action route.

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 (e.g. EN-only template + community-managed translations) 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 master. 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, image, or heading changed.

How the template works:

  - README.src.md uses per-line <!--en--> / <!--zh--> markers for
    translated bits (most lines: TOC entries, headings, prose,
    descriptive comments). Untagged lines render in both languages —
    used for code-block contents, identical structural separators,
    and a few shared lines.
  - Default NRG file-name pattern produces README.md (default lang =
    en); nrg.fileNamePattern.zh maps the zh output to README.zh_CN.md.

CI behavior:

  - regenerate (push to master, 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. Failure log shows a unified diff
    pointing back at README.src.md.

Hardenings:
  - Workflow default permissions = contents: read; regenerate job
    overrides to contents: write only where it needs git push.
  - nanolaba/nrg-action pinned to commit SHA (supply-chain hygiene).
  - Commit step uses git pathspec exclude pattern so README.src.md
    can never be re-staged accidentally.
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