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": {
"add-stream": "^1.0.0",
"conventional-changelog": "^4.0.0",
"glob": "^10.3.0",
"semver": "^7.5.4",

View file

@ -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)),
const tmpStream = createWriteStream(tmpFile);
await pipeline(createReadStream(versionChangelogFile), tmpStream, { end: false });
await pipeline(createReadStream(fullChangelogFile), tmpStream);
await pipeline(createReadStream(tmpFile), createWriteStream(fullChangelogFile));