ci: Update changelog generation to work with node 18

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-07-26 10:28:54 +02:00
parent 1438a737b3
commit 5b99f1e177
2 changed files with 7 additions and 15 deletions

View file

@ -1,6 +1,5 @@
{ {
"dependencies": { "dependencies": {
"add-stream": "^1.0.0",
"conventional-changelog": "^4.0.0", "conventional-changelog": "^4.0.0",
"glob": "^10.3.0", "glob": "^10.3.0",
"semver": "^7.5.4", "semver": "^7.5.4",

View file

@ -1,16 +1,12 @@
import addStream from 'add-stream';
import createTempFile from 'tempfile'; import createTempFile from 'tempfile';
import conventionalChangelog from 'conventional-changelog'; import conventionalChangelog from 'conventional-changelog';
import { resolve } from 'path'; import { resolve } from 'path';
import { createReadStream, createWriteStream } from 'fs'; import { createReadStream, createWriteStream } from 'fs';
import { dirname } from 'path'; import { dirname } from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import stream from 'stream'; import { pipeline } from 'stream/promises';
import { promisify } from 'util';
import packageJson from '../../package.json' assert { type: 'json' }; import packageJson from '../../package.json' assert { type: 'json' };
const pipeline = promisify(stream.pipeline);
const baseDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); const baseDir = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
const fullChangelogFile = resolve(baseDir, 'CHANGELOG.md'); const fullChangelogFile = resolve(baseDir, 'CHANGELOG.md');
const versionChangelogFile = resolve(baseDir, `CHANGELOG-${packageJson.version}.md`); const versionChangelogFile = resolve(baseDir, `CHANGELOG-${packageJson.version}.md`);
@ -27,16 +23,13 @@ const changelogStream = conventionalChangelog({
process.exit(1); process.exit(1);
}); });
// We need to duplicate the stream here to pipe the changelog into two separate files // Write the new changelog to a new temporary file, so that the contents can be used in the PR description
const stream1 = new stream.PassThrough(); await pipeline(changelogStream, createWriteStream(versionChangelogFile));
const stream2 = new stream.PassThrough();
changelogStream.pipe(stream1);
changelogStream.pipe(stream2);
await pipeline(stream1, createWriteStream(versionChangelogFile));
// Since we can't read and write from the same file at the same time, // 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. // we use a temporary file to output the updated changelog to.
const tmpFile = createTempFile(); const tmpFile = createTempFile();
await pipeline(stream2, addStream(createReadStream(fullChangelogFile)), createWriteStream(tmpFile)), const tmpStream = createWriteStream(tmpFile);
await pipeline(createReadStream(versionChangelogFile), tmpStream, { end: false });
await pipeline(createReadStream(fullChangelogFile), tmpStream);
await pipeline(createReadStream(tmpFile), createWriteStream(fullChangelogFile)); await pipeline(createReadStream(tmpFile), createWriteStream(fullChangelogFile));