-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Add auto plugin for adding next release changelogs to chang…
…elog file
- Loading branch information
1 parent
1c7b805
commit 842c79c
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |