diff --git a/.github/scripts/package.json b/.github/scripts/package.json index 3d48686a5f..6033dd191c 100644 --- a/.github/scripts/package.json +++ b/.github/scripts/package.json @@ -1,6 +1,5 @@ { "dependencies": { - "add-stream": "^1.0.0", "conventional-changelog": "^4.0.0", "glob": "^10.3.0", "semver": "^7.5.4", diff --git a/.github/scripts/update-changelog.mjs b/.github/scripts/update-changelog.mjs index 1b41a671be..c0cce214a9 100644 --- a/.github/scripts/update-changelog.mjs +++ b/.github/scripts/update-changelog.mjs @@ -1,16 +1,12 @@ -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'; +import { pipeline } from 'stream/promises'; import packageJson from '../../package.json' assert { type: 'json' }; -const pipeline = promisify(stream.pipeline); - const baseDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); const fullChangelogFile = resolve(baseDir, 'CHANGELOG.md'); const versionChangelogFile = resolve(baseDir, `CHANGELOG-${packageJson.version}.md`); @@ -27,16 +23,13 @@ const changelogStream = conventionalChangelog({ process.exit(1); }); -// We need to duplicate the stream here to pipe the changelog into two separate files -const stream1 = new stream.PassThrough(); -const stream2 = new stream.PassThrough(); -changelogStream.pipe(stream1); -changelogStream.pipe(stream2); - -await pipeline(stream1, createWriteStream(versionChangelogFile)); +// Write the new changelog to a new temporary file, so that the contents can be used in the PR description +await pipeline(changelogStream, createWriteStream(versionChangelogFile)); // 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(stream2, addStream(createReadStream(fullChangelogFile)), createWriteStream(tmpFile)), - await pipeline(createReadStream(tmpFile), createWriteStream(fullChangelogFile)); +const tmpStream = createWriteStream(tmpFile); +await pipeline(createReadStream(versionChangelogFile), tmpStream, { end: false }); +await pipeline(createReadStream(fullChangelogFile), tmpStream); +await pipeline(createReadStream(tmpFile), createWriteStream(fullChangelogFile));