Skip to content

feat: add lefthook pre-commit hooks with gitleaks secret scanning - #2019

Open
panish16 wants to merge 2 commits into
bcgov:mainfrom
panish16:feat/git-hooks-gitleaks
Open

panish16 wants to merge 2 commits into
bcgov:mainfrom
panish16:feat/git-hooks-gitleaks

Conversation

@panish16

@panish16 panish16 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of the Git Hooks RFC rollout (bcgov/entity#34619). Now unblocked - the hold on namex changes (pending the solr migration) was lifted 2026-09-14.

No root package.json existed, so this adds a minimal hooks-only one, matching the approach used on bcgov/ppr#2364 (also a repo with no root package.json).

Scoped to secret scanning only - bare npx gitleaks-secret-scanner, no custom install script, matching the pattern now live on bcregistry/connect/ppr. This repo has 16 separately-versioned services (api, jobs, solr-admin-app, solr-feeder, solr-synonyms-api, etc.), each with its own CI-enforced lint already. Intentionally not attempting to replicate per-service lint wiring the way ppr's pilot did for its 3 services - that's a much larger, separate effort if wanted later.

prepare skips lefthook install entirely when CI=true, rather than just swallowing a failure:

"prepare": "[ \"$CI\" = \"true\" ] || lefthook install"

lefthook's own npm postinstall already skips itself under CI=true by default; our prepare script calling the CLI directly bypassed that, which is what broke bcgov/bcregistry#281's CD build (no git in that image). || exit 0 (used on bcregistry/ppr) stops the crash but still attempts the install every time in CI. This skips it outright, since hooks have no purpose in a non-interactive build.

Verified with real git commit, not just local dry-run: hook installs, and a fake secret gets caught and blocks the commit whether it's at repo root or nested under a subfolder like api/.

Part of the Git Hooks RFC rollout (bcgov/entity#34619). No root
package.json existed, so this adds a minimal hooks-only one, matching
the approach used on bcgov/ppr#2364.

Scoped to secret scanning only (bare 'npx gitleaks-secret-scanner',
no custom install script, matching bcregistry/connect/ppr) - this repo
has 16 separately-versioned services each with their own CI-enforced
lint, so this intentionally doesn't attempt to replicate per-service
lint wiring the way ppr's pilot did; that's a separate, larger effort
if wanted later.

prepare is guarded with '|| exit 0' from the start, learned from
bcgov/bcregistry#281 breaking CD after merging this same base setup
unguarded.
lefthook's own npm postinstall already skips itself under CI=true by
default (only installs if LEFTHOOK=1/true is explicitly set - see
https://lefthook.dev/usage/envs/LEFTHOOK.html). Our prepare script
called 'lefthook install' directly though, which bypasses that and
always runs - that's what broke bcgov/bcregistry#281's CD build (no
git in the image).

'|| exit 0' (the fix used on bcregistry/ppr) stops the failure from
crashing the install, but still attempts the install in CI every
time. This skips it outright when CI is set, since hooks have no
purpose in a non-interactive build anyway.
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant