Skip to content

Commit

Permalink
fix(ng-dev/release): prepare-commit-message hook accidentally running…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
devversion authored Oct 1, 2021
1 parent 583c3cf commit e638278
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ng-dev/release/publish/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ export abstract class ReleaseAction {
// Note: `git add` would not be needed if the files are already known to
// Git, but the specified files could also be newly created, and unknown.
this.git.run(['add', ...files]);
// Note: `--no-verify` skips the majority of commit hooks here, but there are hooks
// like `prepare-commit-message` which still run. We have set the `HUSKY=0` environment
// variable at the start of the publish command to ignore such hooks as well.
this.git.run(['commit', '-q', '--no-verify', '-m', message, ...files]);
}

Expand Down
7 changes: 7 additions & 0 deletions ng-dev/release/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export class ReleaseTool {
return CompletionState.MANUALLY_ABORTED;
}

// Set the environment variable to skip all git commit hooks triggered by husky. We are unable to
// rely on `--no-verify` as some hooks still run, notably the `prepare-commit-msg` hook.
// Running hooks has the downside of potentially running code (like the `ng-dev` tool) when a version
// branch is checked out, but the node modules are not re-installed. The tool switches branches
// multiple times per execution, and it is not desirable re-running Yarn all the time.
process.env['HUSKY'] = '0';

const repo: ReleaseRepoWithApi = {owner, name, api: this._git.github, nextBranchName};
const releaseTrains = await fetchActiveReleaseTrains(repo);

Expand Down

0 comments on commit e638278

Please sign in to comment.