From 842c79c79a348175c41ea9f2bcb2175957d8c792 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 2 Dec 2024 15:18:00 -0800 Subject: [PATCH] [skip ci] Add auto plugin for adding next release changelogs to changelog file --- .autorc | 3 ++- scripts/next-changelogs.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 scripts/next-changelogs.js 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;