diff --git a/.autorc b/.autorc index 067d94bcb..b5e5b3720 100644 --- a/.autorc +++ b/.autorc @@ -22,6 +22,7 @@ "labels": "release" } ], - "./scripts/delete-old-prerelease.js" + "./scripts/delete-old-prerelease.js", + "./scripts/next-changelogs.js" ] } \ No newline at end of file diff --git a/scripts/next-changelogs.js b/scripts/next-changelogs.js new file mode 100644 index 000000000..30e665b9d --- /dev/null +++ b/scripts/next-changelogs.js @@ -0,0 +1,34 @@ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable no-unused-vars */ +/* eslint-disable no-await-in-loop */ +const { execSync } = require("child_process"); + +const getLatestReleaseTag = () => { + const tags = execSync("git tag --sort=-creatordate", { encoding: "utf8" }); + return tags + .split("\n") + .map((t) => t.trim()) + .filter( + (tag) => + tag.includes("-next.") || + tag.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/), + ); +}; + +class NextChangelogsPlugin { + name = "next-changelogs"; + + apply(auto) { + auto.hooks.next.tapPromise(this.name, async ({ dryRun }) => { + const latestRelease = getLatestReleaseTag(); + + if (dryRun) { + auto.logger.log.info(`Dry run: making changelog for: ${latestRelease}`); + } else { + await auto.changelog({ from: latestRelease }); + } + }); + } +} + +module.exports = NextChangelogsPlugin;