Skip to content

Commit e638278

Browse files
authored
fix(ng-dev/release): prepare-commit-message hook accidentally running when bump commit is created (#247)
The `prepare-commit-message` hook can still accidentally run when the changelog / version bump commit is created. This is problematic because when a version branch is checked out (like the patch branch), the node modules are not necessarily updated/re-installed, and the node modules from master remain installed. This can cause runtime errors when Git hooks accidentally run with a tool from the node modules (like `ng-dev` itself). We fix this by also setting the `HUSKY` environment variable, similar to how the merge tool does. We can assume that Husky is used in all repositories. This should be our standard for hooks.
1 parent 583c3cf commit e638278

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ng-dev/release/publish/actions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ export abstract class ReleaseAction {
386386
// Note: `git add` would not be needed if the files are already known to
387387
// Git, but the specified files could also be newly created, and unknown.
388388
this.git.run(['add', ...files]);
389+
// Note: `--no-verify` skips the majority of commit hooks here, but there are hooks
390+
// like `prepare-commit-message` which still run. We have set the `HUSKY=0` environment
391+
// variable at the start of the publish command to ignore such hooks as well.
389392
this.git.run(['commit', '-q', '--no-verify', '-m', message, ...files]);
390393
}
391394

ng-dev/release/publish/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ export class ReleaseTool {
6060
return CompletionState.MANUALLY_ABORTED;
6161
}
6262

63+
// Set the environment variable to skip all git commit hooks triggered by husky. We are unable to
64+
// rely on `--no-verify` as some hooks still run, notably the `prepare-commit-msg` hook.
65+
// Running hooks has the downside of potentially running code (like the `ng-dev` tool) when a version
66+
// branch is checked out, but the node modules are not re-installed. The tool switches branches
67+
// multiple times per execution, and it is not desirable re-running Yarn all the time.
68+
process.env['HUSKY'] = '0';
69+
6370
const repo: ReleaseRepoWithApi = {owner, name, api: this._git.github, nextBranchName};
6471
const releaseTrains = await fetchActiveReleaseTrains(repo);
6572

0 commit comments

Comments
 (0)