Skip to content

Commit

Permalink
[skip ci] Add auto plugin for adding next release changelogs to chang…
Browse files Browse the repository at this point in the history
…elog file
  • Loading branch information
KetanReddy committed Dec 2, 2024
1 parent 1c7b805 commit 842c79c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .autorc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"labels": "release"
}
],
"./scripts/delete-old-prerelease.js"
"./scripts/delete-old-prerelease.js",
"./scripts/next-changelogs.js"
]
}
34 changes: 34 additions & 0 deletions scripts/next-changelogs.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 842c79c

Please sign in to comment.