From 5b3c6829f4c96ec40b2e38378624ced520cecabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 26 Jun 2023 12:04:21 +0200 Subject: [PATCH] ci: Automate `no-changelog` removal in generated changelog (no-changelog) (#6511) --- .github/scripts/package.json | 8 +++--- .github/scripts/update-changelog.mjs | 36 +++++++++++++++++++++++++ .github/workflows/release-create-pr.yml | 4 +-- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 .github/scripts/update-changelog.mjs diff --git a/.github/scripts/package.json b/.github/scripts/package.json index 3c5740b2f7..679eeebead 100644 --- a/.github/scripts/package.json +++ b/.github/scripts/package.json @@ -1,8 +1,10 @@ { "dependencies": { - "conventional-changelog-cli": "^2.2.2", - "glob": "^10.2.7", - "semver": "^7.3.8", + "add-stream": "^1.0.0", + "conventional-changelog": "^4.0.0", + "glob": "^10.3.0", + "semver": "^7.5.2", + "tempfile": "^5.0.0", "typescript": "*" } } diff --git a/.github/scripts/update-changelog.mjs b/.github/scripts/update-changelog.mjs new file mode 100644 index 0000000000..fda9ae1fd0 --- /dev/null +++ b/.github/scripts/update-changelog.mjs @@ -0,0 +1,36 @@ +import addStream from 'add-stream'; +import createTempFile from 'tempfile'; +import conventionalChangelog from 'conventional-changelog'; +import { resolve } from 'path'; +import { createReadStream, createWriteStream } from 'fs'; +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; +import stream from 'stream'; +import { promisify } from 'util'; + +const pipeline = promisify(stream.pipeline); + +const changelogFile = resolve(dirname(fileURLToPath(import.meta.url)), '../../CHANGELOG.md'); + +const changelogStream = conventionalChangelog({ + preset: 'angular', + releaseCount: 1, + tagPrefix: 'n8n@', + transform: (commit, callback) => { + callback(null, commit.header.includes('(no-changelog)') ? undefined : commit); + }, +}).on('error', (err) => { + console.error(err.stack); + process.exit(1); +}); + +// Since we can't read and write from the same file at the same time, +// we use a temporary file to output the updated changelog to. +const tmpFile = createTempFile(); +await pipeline( + changelogStream, + addStream(createReadStream(changelogFile)), + createWriteStream(tmpFile), +); + +await pipeline(createReadStream(tmpFile), createWriteStream(changelogFile)); diff --git a/.github/workflows/release-create-pr.yml b/.github/workflows/release-create-pr.yml index a7942cd6ec..79cf65e6b6 100644 --- a/.github/workflows/release-create-pr.yml +++ b/.github/workflows/release-create-pr.yml @@ -53,8 +53,8 @@ jobs: env: RELEASE_TYPE: ${{ github.event.inputs.release-type }} - - name: Generate Changelog - run: npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -t n8n@ + - name: Update Changelog + run: node .github/scripts/update-changelog.mjs - name: Push the release branch, and Create the PR uses: peter-evans/create-pull-request@v4