forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Replace Husky/Lint-staged with Lefthook (grafana#66608)
* Switch from husky+precommit to lefthook Migrate from husky/precommit to lefthook h old husky precommit lefthook so far remove husky folder switch to new lefthook package Add postinstall script to clean up after husky preinstall to remove husky config package.json package.json package.json script v Reduce lefthook output Cleanup testing reduce output testing betterer testing betterer testing betterer testing betterer testing betterer testing betterer testing betterer skip skipping execution info small cleanup remove comment from testing clean up old husky hooks in .git/hooks path run scripts in parallel update codeowners don't auto-install lefthook install lefthook with make command fix yarn checksum * update codeowners * don't use source because it isn't available in ubuntu/debian's /bin/sh * Ensure lefthook commits files fixed by precommit hooks * add comment to lefthook.rc explaining what it does * add i18n:pseudo precommit * Don't create .husky/safe-to-delete file anymore * cleanup old lint-staged config * contribute docs * update lefthook to 1.4.8 * Move frontend encouragement docs * rewrite husky cleanup script in bash so we can run it with make * Make old husky precommit script reject commits until husky is removed * log precommit warning for everyone * fix package.json * run lefthook hooks from old husky hook * run lefthook hooks from old husky hook * comments * codeowners * codeowners
- Loading branch information
Showing
14 changed files
with
731 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT | ||
|
||
go 1.20 | ||
|
||
require github.com/evilmartians/lefthook v1.4.8 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
#!/bin/sh | ||
|
||
# Ignore husky hooks if no frontend code has been changed | ||
git diff --cached --name-only | grep -v --quiet "^pkg/" || exit 0 | ||
# Catch devs who have installed lefthook, went back into the past and reinstalled husky, | ||
# then came back into lefthook-land. | ||
if [ -f ".git/hooks/pre-commit" ]; then | ||
if grep -q lefthook ".git/hooks/pre-commit"; then | ||
# Remove husky from their git config | ||
env SILENT=1 ./scripts/cleanup-husky.sh | ||
|
||
. "$(dirname "$0")/_/husky.sh" | ||
# And run the lefthook precommit hook instead of this | ||
./.git/hooks/pre-commit "$@" | ||
exit $? | ||
fi | ||
fi | ||
|
||
yarn run precommit | ||
# This precommit hook exists only for people who still have hooksPath=.husky in their git config | ||
# from when we used husky. This is intended to run only on first commit after pulling the lefthook changes. | ||
# | ||
# Either setting up lefthook, or running the clean command will unset the hooksPath git config so this | ||
# hook is no longer ran when committing. | ||
|
||
echo "\n⚠️⚠️⚠️ \e[1mImportant: Pre-commit hooks are now opt-in.\e[0m ⚠️⚠️⚠️" | ||
echo "To install the new pre-commit hooks:" | ||
echo " $ \e[96mmake lefthook-install\e[0m" | ||
echo "Or, silence this message by cleaning up the old hooks" | ||
echo " $ \e[96mmake cleanup-old-git-hooks\e[0m" | ||
echo "\nPre-commit hooks will not run on this commit and it will be committed even if it contains lint errors." | ||
echo "See https://github.com/grafana/grafana/blob/main/contribute/developer-guide.md#configure-precommit-hooks for more info\n" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This file is used by lefthook to 'expose' the bingo-installed lefthook under | ||
# the name `lefthook`, as expected by the lefthook pre-commit scripts | ||
|
||
. .bingo/variables.env | ||
|
||
lefthook () { | ||
${LEFTHOOK} "$@" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
skip_output: | ||
- meta | ||
- execution_out | ||
- skips | ||
|
||
min_version: 1.4.3 | ||
|
||
rc: ./lefthook.rc | ||
|
||
pre-commit: | ||
parallel: true | ||
commands: | ||
frontend-betterer: | ||
glob: '*.{ts,tsx}' | ||
run: yarn betterer precommit {staged_files} | ||
stage_fixed: true | ||
|
||
frontend-lint: | ||
glob: '*.{js,ts,tsx}' | ||
run: | | ||
yarn eslint --ext .js,.tsx,.ts --cache --fix {staged_files} | ||
yarn prettier --write {staged_files} | ||
stage_fixed: true | ||
|
||
internationalization: | ||
glob: 'public/locales/en-US/grafana.json' | ||
run: yarn i18n:pseudo | ||
stage_fixed: true | ||
|
||
other-format: | ||
glob: '*.{json,scss,md,mdx}' | ||
run: yarn prettier --write {staged_files} | ||
stage_fixed: true | ||
|
||
backend-format: | ||
glob: '*pkg/**/*.go' | ||
run: gofmt -w -s {staged_files} | ||
stage_fixed: true | ||
|
||
cue-fix-kinds: | ||
glob: '*kinds/**/*.cue' | ||
run: make fix-cue | ||
stage_fixed: true | ||
|
||
cue-fix-public: | ||
glob: '*public/app/plugins/**/**/*.cue' | ||
run: make fix-cue | ||
stage_fixed: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
|
||
|
||
# Husky modified your git config to store git hooks in the repo, so do that change | ||
currentHooksPath=$(git config core.hooksPath || true) | ||
if [[ $currentHooksPath == ".husky" ]]; then | ||
if [ -z "$SILENT" ]; then | ||
echo "Unsetting git hooks path because it was previously set to .husky." | ||
echo "If you had custom git hooks in .husky you may want to move them to .git/hooks" | ||
fi | ||
|
||
git config --unset core.hooksPath | ||
fi | ||
|
||
oldHuskyHookNames=( | ||
"applypatch-msg" | ||
"commit-msg" | ||
"post-applypatch" | ||
"post-checkout" | ||
"post-commit" | ||
"post-merge" | ||
"post-receive" | ||
"post-rewrite" | ||
"post-update" | ||
"pre-applypatch" | ||
"pre-auto-gc" | ||
"pre-merge-commit" | ||
"pre-push" | ||
"pre-rebase" | ||
"pre-receive" | ||
"push-to-checkout" | ||
"sendemail-validate" | ||
"update" | ||
) | ||
|
||
# | ||
# Also extra-old husky dumped a bunch of hooks into .git/hooks, so check for them | ||
# and rename them so they don't run | ||
for hookName in "${oldHuskyHookNames[@]}"; do | ||
hookPath=".git/hooks/$hookName" | ||
|
||
if [[ -f $hookPath ]]; then | ||
if grep -q husky "$hookPath"; then | ||
newHookPath="$hookPath.old" | ||
|
||
if [ -z "$SILENT" ]; then | ||
echo "Renaming old husky hook $hookPath to $newHookPath" | ||
fi | ||
|
||
mv "$hookPath" "$newHookPath" --suffix=old --backup=numbered | ||
fi | ||
fi | ||
done |
Oops, something went wrong.