-
Notifications
You must be signed in to change notification settings - Fork 41
feat(#857): readme-automation #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paskhalov
wants to merge
5
commits into
objectionary:master
Choose a base branch
from
paskhalov:857-readme-automation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2022-2026 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| name: readme-automation | ||
|
|
||
| 'on': | ||
| workflow_dispatch: | ||
| push: | ||
| paths: | ||
| - "src/eoc.js" | ||
| concurrency: | ||
| group: readmeautomation-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-24.04 | ||
|
|
||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
| - name: Use Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: "18.x" | ||
| check-latest: false | ||
| - name: Clean install | ||
| run: npm ci | ||
| - name: Install global | ||
| run: npm install -g | ||
| - name: Run readme_automation script | ||
| run: |- | ||
| node scripts/readme_automation.js | ||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@v8 | ||
| with: | ||
| commit-message: "chore(readme): insert sections into README from CLI help" | ||
| branch: chore/readme-automation | ||
| title: "chore(readme): insert sections into README from CLI help" | ||
| body: | | ||
| This PR was automatically generated by GitHub Actions. | ||
|
|
||
| - Insert sections into README from CLI help output | ||
| - Keeps documentation in sync with the CLI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env node | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2026 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| const assert = require('assert'); | ||
| const { commandsDescription } = require("../src/eoc"); | ||
|
|
||
| function escapeRegex(str) { | ||
| return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| } | ||
|
|
||
| function updateSection(sectionName, newContent, readMeContent) { | ||
| const start = `<!-- BEGIN ${sectionName.toUpperCase()} SECTION -->`; | ||
| const end = `<!-- END ${sectionName.toUpperCase()} SECTION -->`; | ||
| const regex = new RegExp( | ||
| `(${escapeRegex(start)})([\\s\\S]*?)(${escapeRegex(end)})`, | ||
| "g" | ||
| ); | ||
| return readMeContent.replace(regex, `$1\n${newContent}$3`); | ||
| } | ||
|
|
||
| function bulletListTemplate(rows) { | ||
| return `${rows.map(([cmd, desc]) => `* \`${cmd}\` ${desc}`).join("\n") }\n`; | ||
| } | ||
|
|
||
| function modifyReadme(commands,fs) { | ||
| assert.ok(commands.length > 0,'Commands should have rows') | ||
| const commandsMarkdown = bulletListTemplate(commands); | ||
| assert.ok(commandsMarkdown.length > 0,"commandsMarkdown result should have text") | ||
| let readMeContent = fs.readFileSync('README.md', "utf8"); | ||
| assert.ok(readMeContent.length > 0,"readMeContent should have text") | ||
| readMeContent = updateSection('commands', commandsMarkdown, readMeContent); | ||
| assert.ok(readMeContent.length > 0,"readMeContent should sill have text after modification") | ||
| fs.writeFileSync('README.md',readMeContent); | ||
| } | ||
|
|
||
| function syncCommandsToReadme(fs) | ||
| { | ||
| modifyReadme(commandsDescription(),fs); | ||
| } | ||
|
|
||
| module.exports = { | ||
| bulletListTemplate, updateSection, modifyReadme, syncCommandsToReadme | ||
| }; | ||
|
|
||
| if (require.main === module) { | ||
| syncCommandsToReadme(require("fs")); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2026 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| const assert = require("assert"); | ||
| const path = require("path"); | ||
| const { updateSection, bulletListTemplate, modifyReadme, syncCommandsToReadme} = require(path.join(__dirname, "../scripts/readme_automation.js")); | ||
|
|
||
| const readme = `before\n<!-- BEGIN COMMANDS SECTION -->\nold content\n<!-- END COMMANDS SECTION -->\n<!-- BEGIN OPTIONS SECTION -->\nkeep\n<!-- END OPTIONS SECTION -->\nafter` | ||
| const commandsList = [['one','a'],['two','b'],['three','c']]; | ||
| const keywords = ["keep","after","before","<!-- BEGIN COMMANDS SECTION -->","<!-- END COMMANDS SECTION -->"]; | ||
| const fsMockProto = {readMeContent:null, readFileSync(path,options){ return readme; }, writeFileSync(path,data){ this.readMeContent = data; }}; | ||
|
|
||
|
|
||
| describe("readme_automation scripts", () => { | ||
| it("updateSection replaces only the requested section", () => { | ||
| const readmeUpdated = updateSection("commands", "new content", readme); | ||
| assert.ok(!readmeUpdated.includes("old content"),"Update README should no have 'old content'"); | ||
| assert.ok(keywords.every(sub => readmeUpdated.includes(sub)),"Update README should have all keywords"); | ||
| assert.ok(readmeUpdated.includes("new content"),"Update README should have `new content`"); | ||
| }); | ||
| it("bulletListTemplate renders a list", async () => { | ||
| const bulletListMarkdown = bulletListTemplate(commandsList); | ||
| assert.strictEqual(bulletListMarkdown, "* `one` a\n* `two` b\n* `three` c\n"); | ||
| }); | ||
| it("call modifyReadme with fs mock", async () => { | ||
| const fsMock = {...fsMockProto}; | ||
| modifyReadme(commandsList,fsMock); | ||
| assert.notEqual(fsMock.readMeContent,null,"README file should have some content"); | ||
| assert.ok(!fsMock.readMeContent.includes("old content"),"README file should no have 'old content'"); | ||
| assert.ok(keywords.every(sub => fsMock.readMeContent.includes(sub)),"README file should have all keywords"); | ||
| assert.ok(["* `one` a","* `two` b","* `three` c"].every(sub => fsMock.readMeContent.includes(sub))); | ||
| }); | ||
| it("test the whole workflow with fs mock", async () => { | ||
| const fsMock = {...fsMockProto}; | ||
| syncCommandsToReadme(fsMock); | ||
| assert.notEqual(fsMock.readMeContent,null,"README file should have some content"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paskhalov In these tests, you check how
parseBlock,updateSectionandbulletListTemplateare working. There is no need for that. We would like to have a single function that would update readme and we should test only this function. All of the other functions are just intermediate steps.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one test, delete the rest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paskhalov I'm not sure about a single test, but we need one function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it