Support: Updating a section in the README using "readme-box" in a GitHub Action

Created on 5 Aug 2020  路  7Comments  路  Source: EddieHubCommunity/support

Description

I would like to update the a section in the README using readme-box. I get an error ##[error]Contents do not contain start/end comments for section "data-section", the section does exist, I must be missing something else.

Here is my code to update the README:

await readmeBox.updateSection(content, {
            owner: process.env.GITHUB_REPOSITORY.split('/')[0],
            repo: process.env.GITHUB_REPOSITORY.split('/')[1],
            token: githubToken,
            section: 'data-section',
});

Here is the README code:

<!--START_SECTION:data-section-->
<!--END_SECTION:data-section-->

GitHub Action job run https://github.com/EddieJaoudeCommunity/awesome-github-profiles/runs/950486163?check_suite_focus=true

Stack

GitHub Action with NodeJS

question solved

Most helpful comment

ReadmeBox.updateSection gets the README contents from the default branch via API requests, not by reading the file within Actions:

https://github.com/JasonEtco/readme-box/blob/601b520c34c8292ef9c33afcbb0a7ddba7412a4b/src/index.ts#L44-L45

So you'd need to merge the addition of those comments before this Action works 馃槵 I realize that's a little weird - so you can use the various helper methods instead:

const oldContent = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'README.md'), 'utf8')
const box = new ReadmeBox()
const replacedContents = box.replaceSection({
  section: 'data-section',
  oldContent,
  newContent: 'some new stuff'
})

All 7 comments

ReadmeBox.updateSection gets the README contents from the default branch via API requests, not by reading the file within Actions:

https://github.com/JasonEtco/readme-box/blob/601b520c34c8292ef9c33afcbb0a7ddba7412a4b/src/index.ts#L44-L45

So you'd need to merge the addition of those comments before this Action works 馃槵 I realize that's a little weird - so you can use the various helper methods instead:

const oldContent = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'README.md'), 'utf8')
const box = new ReadmeBox()
const replacedContents = box.replaceSection({
  section: 'data-section',
  oldContent,
  newContent: 'some new stuff'
})

Awesome, thank you 馃憤 .

Is the token no longer needed?

Yep, if you're not making API calls you don't need it as an option in the constructor! If you want to use ReadmeBox#updateReadme you'd need it though, up to how you actually update the file contents in Git.

I changed direction, but now I came back 馃槀 . I thought I could use the branch option in updateSection. What do you think?

Oh although branch is part of ReadmeBoxOpts, when updateSection uses updateReadme it has the branch hardcoded branch: 'master', hmm so that won't work 馃

I will raise you a PR 馃

I test the PR I raised from my fork in my Github Action and it worked 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ankushKun picture ankushKun  路  3Comments

SuNiL-Chau picture SuNiL-Chau  路  4Comments

rootritesh picture rootritesh  路  4Comments

DoomHammer picture DoomHammer  路  4Comments

mohit01-beep picture mohit01-beep  路  5Comments