From 583d065ccf8743e38a13ed385da6338d07359599 Mon Sep 17 00:00:00 2001 From: Adil Malik Date: Tue, 28 Feb 2023 17:32:58 -0700 Subject: [PATCH 1/2] feat: add in beforeVersion lifecycle hook --- .../docs/plugins/release-lifecycle-hooks.mdx | 13 +++++++++ packages/core/src/auto.ts | 28 +++++++++++++++---- packages/core/src/utils/make-hooks.ts | 1 + 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docs/pages/docs/plugins/release-lifecycle-hooks.mdx b/docs/pages/docs/plugins/release-lifecycle-hooks.mdx index 4d77ea5be..652e7d1a2 100644 --- a/docs/pages/docs/plugins/release-lifecycle-hooks.mdx +++ b/docs/pages/docs/plugins/release-lifecycle-hooks.mdx @@ -95,6 +95,19 @@ _Other examples:_ - [all-contributors](../generated/all-contributors) - Make a commit for new contributions +## beforeVersion + +Ran before the package has been versioned. Useful for iterating through the list of +commits that are going to be included in the current release, and applying/overriding +the version bump (major/minor/patch) labels applied to their corresponding PRs. + +```ts +auto.hooks.beforeVersion.tapPromise( + "NPM", + async ({ dryRun, commits, from }) => {} +); +``` + ## version Increment the version the package. diff --git a/packages/core/src/auto.ts b/packages/core/src/auto.ts index 6643efc2c..523728ad5 100644 --- a/packages/core/src/auto.ts +++ b/packages/core/src/auto.ts @@ -238,6 +238,17 @@ export interface IAutoHooks { } ] >; + /** Ran before the package has been versioned. */ + beforeVersion: AsyncSeriesHook< + [ + DryRunOption & { + /** Commit to start calculating the version from */ + from: string; + /** The commits included in the release */ + commits: IExtendedCommit[]; + } + ] + >; /** Version the package. This is a good opportunity to `git tag` the release also. */ version: AsyncSeriesHook< [ @@ -1713,6 +1724,18 @@ export default class Auto { throw this.createErrorMessage(); } + const lastRelease = options.from || (await this.git.getLatestRelease()); + const commitsInRelease = await this.release.getCommitsInRelease( + lastRelease + ); + + this.logger.verbose.info("Calling before version hook"); + await this.hooks.beforeVersion.promise({ + dryRun: options.dryRun, + commits: commitsInRelease, + from: lastRelease, + }); + const bump = await this.getVersion(options); this.logger.log.success( @@ -1724,11 +1747,6 @@ export default class Auto { return; } - const lastRelease = options.from || (await this.git.getLatestRelease()); - const commitsInRelease = await this.release.getCommitsInRelease( - lastRelease - ); - await this.makeChangelog({ ...options, quiet: undefined, diff --git a/packages/core/src/utils/make-hooks.ts b/packages/core/src/utils/make-hooks.ts index c2abab99e..5496efc99 100644 --- a/packages/core/src/utils/make-hooks.ts +++ b/packages/core/src/utils/make-hooks.ts @@ -29,6 +29,7 @@ export const makeHooks = (): IAutoHooks => ({ getPreviousVersion: new AsyncSeriesBailHook(), getRepository: new AsyncSeriesBailHook(), prCheck: new AsyncSeriesBailHook(["prInformation"]), + beforeVersion: new AsyncSeriesHook(["context"]), version: new AsyncSeriesHook(["version"]), afterVersion: new AsyncSeriesHook(["context"]), publish: new AsyncSeriesHook(["version"]), From a80cacf3df13aa850bdcdd58d706187bec211d75 Mon Sep 17 00:00:00 2001 From: Adil Malik Date: Tue, 28 Feb 2023 17:40:26 -0700 Subject: [PATCH 2/2] chore: update docs --- docs/pages/docs/plugins/release-lifecycle-hooks.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/docs/plugins/release-lifecycle-hooks.mdx b/docs/pages/docs/plugins/release-lifecycle-hooks.mdx index 652e7d1a2..3092bce30 100644 --- a/docs/pages/docs/plugins/release-lifecycle-hooks.mdx +++ b/docs/pages/docs/plugins/release-lifecycle-hooks.mdx @@ -99,7 +99,7 @@ _Other examples:_ Ran before the package has been versioned. Useful for iterating through the list of commits that are going to be included in the current release, and applying/overriding -the version bump (major/minor/patch) labels applied to their corresponding PRs. +the version bump (major/minor/patch) labels applied to the PRs corresponding to those commits. ```ts auto.hooks.beforeVersion.tapPromise(