Hooks
Run shell commands or functions before, after or on the failure of each step of a release, and rewrite the generated changelogs.
import { defineConfig } from 'relizy'
export default defineConfig({
hooks: {
'before:publish': 'pnpm test',
'success:release': async (config, dryRun, context) => {
if (!dryRun) {
await notifyTeam(context?.release)
}
},
},
})Hook Names
- Type:
HookConfig, a key<type>:<step>for each step - Default: none
| Type | Runs |
|---|---|
before | before the step |
success | after the step completes |
error | when the step fails, before it rethrows |
| Step | What it covers | Run by |
|---|---|---|
bump | Version bump | relizy bump, relizy release |
changelog | CHANGELOG.md files | relizy changelog, relizy release |
publish | Publication to the registry | relizy publish, relizy release |
commit-and-tag | Release commit and tags | relizy release |
push | Push of the commit and the tags | relizy release |
provider-release | GitHub or GitLab releases | relizy provider-release, relizy release |
social | Every social post | relizy social, relizy release |
twitter | The tweet | relizy social, relizy release |
slack | The Slack message | relizy social, relizy release |
teams | The Teams cards | relizy social, relizy release |
sync | Sync of the branches | relizy sync, relizy release |
release | The whole release | relizy release |
The PR comment has no hooks. A step disabled by the config or a flag (--no-publish) runs none of its hooks.
Parameters
A hook is a shell command (a string, run from cwd) or a function, sync or async:
(config: ResolvedRelizyConfig, dryRun: boolean, context?: HookContext) => anyconfig: the resolved config, defaults includeddryRun:truewith--dry-run, where the hooks still run: check it before any side effectcontext: the release, when it is known: inrelizy releaseonce the bump is done, and in a command given a bump result.before:release,before:bumpanderror:bumpnever get it, nor the standalonerelizy changelog,publish,provider-releaseandsocial.bumpResult(BumpResultTruthy): the result of the bumprelease(ReleaseOverview): the packages and versions of the release by version group; in thetwitter,slackandteamshooks, what the post announces
export default defineConfig({
hooks: {
'success:release': (config, dryRun, context) => {
for (const group of context?.release.groups ?? []) {
console.log(group.title, group.version ?? group.packages.map(pkg => `${pkg.name}@${pkg.newVersion}`).join(', '))
}
},
},
})See the HookContext and ReleaseOverview types.
generate:changelog
- Type:
(config, dryRun, { commits: GitCommit[], changelog: string }) => string | void | null | undefined | Promise<...>
Rewrites a generated changelog: called once for the changelog of each package and for the root changelog (in independent mode, the root changelog gathers the rewritten changelogs of the packages, without a call of its own), as written in the CHANGELOG.md files (not for the provider releases nor the social posts). Return a string to replace changelog, or nothing to keep it. With version groups, config is the config of the group of the changelog. To rewrite the release notes and the posts with AI, see AI.
export default defineConfig({
hooks: {
'generate:changelog': (config, dryRun, { commits, changelog }) => {
return commits.length > 0 ? `${changelog}\n\nThanks to every contributor!` : undefined
},
},
})Order
relizy bump, changelog, publish and provider-release run before:<step>, then success:<step> or error:<step>; relizy changelog also runs generate:changelog for each changelog. relizy publish with nothing to publish runs neither success:publish nor error:publish.
relizy social runs:
before:socialbefore:twitter, thensuccess:twitterorerror:twitter, when Twitter is enabled and a version is posted (seeonlyStableandexclude)before:slack, thensuccess:slackorerror:slack, likewise for Slack (seeannouncementstoo)before:teams, thensuccess:teamsorerror:teams, likewise for Teamssuccess:social, orerror:socialwhen a post failed or the step itself failed (reading the release, a failing hook)
relizy release runs, for its enabled steps:
before:release- Bump:
before:bump,success:bumporerror:bump - Changelog:
before:changelog,generate:changelog,success:changelogorerror:changelog - Publish:
before:publish,success:publishorerror:publish - Commit and tag:
before:commit-and-tag,success:commit-and-tagorerror:commit-and-tag - Push:
before:push,success:pushorerror:push - Branch sync:
before:sync,success:sync, orerror:syncwhen a branch did not get the release - Provider release:
before:provider-release,success:provider-releaseorerror:provider-release - Social posts: the hooks of
relizy social - PR comment (no hooks)
success:release, orerror:releasewhen the release failed
When nothing is released (no commit triggers a bump), relizy release stops after the bump: neither success:release nor error:release runs. A refused or cancelled prompt runs no error:* hook.
Errors
A function hook that throws, or a command exiting with a non-zero code, fails its step: the error:<step> hook runs and the command stops (in relizy release, error:release runs too). A failed provider release, social post or branch sync does not stop relizy release: its error:provider-release hook runs (or error:twitter, error:slack or error:teams, then error:social, or error:sync), the step is marked as failed in the summary, and the release ends with success:release. A failed PR comment only warns.
export default defineConfig({
hooks: {
'before:publish': 'pnpm test',
'error:publish': (config, dryRun) => {
console.error('Publish failed, the release files are restored')
},
},
})Version Groups
With version groups, each hook runs once per command, with the global config: one bump, one publish, one post per platform for the whole release. Only generate:changelog receives the config of a group, where monorepo.versionMode and monorepo.packages are the ones of the group. Read the groups of the release from context.release.