Update dependency lerna to v8.1.8 #998
Workflow file for this run
This file contains 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
name: Update CHANGELOG.md | |
on: | |
pull_request: | |
branches: | |
- main | |
types: [closed] | |
concurrency: | |
group: update-changelog | |
jobs: | |
update-changelog: | |
runs-on: ubuntu-22.04 | |
name: Update CHANGELOG.md | |
if: github.event.pull_request.merged == true | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update CHANGELOG.md | |
id: changelog | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
// Fetches an issue (pull request) information. | |
const {promises: fs} = require('fs'); | |
const {data: issue} = await github.rest.issues.get({ | |
...context.repo, | |
issue_number: context.issue.number, | |
}); | |
console.log(issue); | |
const {user, pull_request: pull} = issue; | |
// Reads the current `CHANGELOG.md`. | |
let changelog = await fs.readFile('CHANGELOG.md', 'utf-8'); | |
// Exatracts `# dev` section from the `CHANGELOG.md`. | |
const devMatch = changelog.match(/^# dev\n\n([^]*?)(?=\n# )\n/); | |
let devSection = ''; | |
if (devMatch !== null) { | |
changelog = changelog.slice(devMatch[0].length); | |
devSection = devMatch[0]; | |
} | |
console.log(devSection); | |
// Extracts each update subsection from `# dev` section. | |
const updateLists = { | |
feature: { category: 'New Features' }, | |
change: { category: 'Changes' }, | |
fix: { category: 'Fixes' }, | |
misc: { category: 'Misc' }, | |
}; | |
for (const label of Object.keys(updateLists)) { | |
const subsection = `\n${updateLists[label].category}:\n\n`; | |
const index = devSection.indexOf(subsection); | |
if (index === -1) { | |
updateLists[label].updates = []; | |
continue; | |
} | |
const endIndex = devSection.indexOf('\n\n', index + subsection.length); | |
updateLists[label].updates = devSection.slice(index + subsection.length, endIndex).split('\n'); | |
} | |
console.log(updateLists); | |
// Inserts a new line for this update to the update list specified by a label. | |
const newLine = `- [#${issue.number}](${pull.html_url}) ${issue.title} ([@${user.login}](${user.html_url}))`; | |
let hasUpdate = false; | |
for (const label of issue.labels) { | |
console.log(label); | |
if (updateLists[label.name]) { | |
updateLists[label.name].updates.push(newLine); | |
hasUpdate = true; | |
} | |
} | |
core.setOutput('has_update', hasUpdate); | |
if (!hasUpdate) return; | |
let newDevSection = '# dev\n'; | |
for (const label of Object.keys(updateLists)) { | |
if (updateLists[label].updates.length === 0) { | |
continue; | |
} | |
newDevSection += '\n'; | |
newDevSection += `${updateLists[label].category}:\n`; | |
newDevSection += `\n`; | |
for (const update of updateLists[label].updates) { | |
newDevSection += `${update}\n`; | |
} | |
} | |
console.log(newDevSection); | |
// Updates the `CHANGELOG.md`. | |
changelog = `${newDevSection}\n${changelog}`; | |
await fs.writeFile('CHANGELOG.md', changelog); | |
- name: Commit a new `CHANGELOG.md` | |
if: steps.changelog.outputs.has_update == 'true' | |
run: | | |
git config --local user.name "MakeNowJust bot" | |
git config --local user.email "[email protected]" | |
git add . | |
git commit -m "Update CHANGELOG.md" | |
git push origin main |