Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add in beforeVersion lifecycle hook #2334

Merged
merged 2 commits into from Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/pages/docs/plugins/release-lifecycle-hooks.mdx
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
Expand Up @@ -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<
[
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/make-hooks.ts
Expand Up @@ -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"]),
Expand Down