Skip to content

Commit

Permalink
Merge pull request #2334 from amalik2/beforeVersion
Browse files Browse the repository at this point in the history
feat: add in beforeVersion lifecycle hook
  • Loading branch information
hipstersmoothie authored Mar 1, 2023
2 parents 296fa0e + a80cacf commit f7827d4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/pages/docs/plugins/release-lifecycle-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 the PRs corresponding to those commits.

```ts
auto.hooks.beforeVersion.tapPromise(
"NPM",
async ({ dryRun, commits, from }) => {}
);
```

## version

Increment the version the package.
Expand Down
28 changes: 23 additions & 5 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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<
[
Expand Down Expand Up @@ -1727,6 +1738,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(
Expand All @@ -1738,11 +1761,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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/make-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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"]),
Expand Down

0 comments on commit f7827d4

Please sign in to comment.