[FIX] web: fix tooling failing to run due to bash-specific syntax

In #86163 we added a check on the branch name to avoid running the
tooling on stable branches, however this check used bash-specific
syntax. While the hashbang in the pre-commit hook specifies that the
hook should be run using bash, we were using the npm module "husky" to
manage git hooks, which would ignore this hashbang and always run the
hook using sh, causing the hook to fail in all cases.

After some consideration, we have decided to stop using husky, as its
main purpose is to make hook management easier in npm-based projects.
Since we already need a script to enable the tooling, we can do
essentially the same thing that husky is doing but with more control
over the process with no drawbacks.

closes odoo/odoo#87436

X-original-commit: 3104ab16ecf88d4f7b1618db4d62e7f57df34e6c
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
This commit is contained in:
Samuel Degueldre
2022-03-29 12:00:11 +02:00
committed by Simon Genin (ges)
parent ccdd00303d
commit 92497ed4f1
7 changed files with 40 additions and 54 deletions
-1
View File
@@ -34,7 +34,6 @@ setup/win32/static/postgresql*.exe
node_modules
package-lock.json
package.json
.husky
# various virtualenv
/bin/
-1
View File
@@ -1 +0,0 @@
_
-2
View File
@@ -3,7 +3,6 @@
"version": "0.0.1",
"description": "JS Config for better DX in javascript",
"scripts": {
"prepare": "husky install",
"format-web": "prettier-eslint --write 'addons/web/static/src/**/*.js' 'addons/web/static/tests/**/*.js' 'addons/web/doc/**/*.md'",
"format-staged": "lint-staged",
"lint-web": "prettier-eslint --list-different 'addons/web/static/src/**/*.js' 'addons/web/static/tests/**/*.js' 'addons/web/doc/**/*.md'",
@@ -13,7 +12,6 @@
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"prettier": "2.2.1",
"prettier-eslint-cli": "^5.0.1"
+15 -18
View File
@@ -1,7 +1,18 @@
#!/bin/bash
community=$(cd -- "$(dirname "$0")" &> /dev/null && cd ../../.. && pwd)
script="$0"
basename="$(dirname "$script")"
disableInDir () {
cd "$1"
git config --unset core.hooksPath
rm .eslintignore
rm .prettierignore
rm .eslintrc.json
rm .prettierrc.json
rm package.json
rm package-lock.json
rm -r node_modules
cd - &> /dev/null
}
read -p "Do you want to delete the tooling installed in enterprise too ? [y, n]" willingToDeleteToolingInEnterprise
if [[ $willingToDeleteToolingInEnterprise != "n" ]]
@@ -10,25 +21,11 @@ then
pathToEnterprise=${pathToEnterprise:-../enterprise}
fi
rm -rf "$basename/../../../.husky"
rm -rf "$basename/../../../.eslintignore"
rm -rf "$basename/../../../.prettierignore"
rm -rf "$basename/../../../.eslintrc.json"
rm -rf "$basename/../../../.prettierrc.json"
rm -rf "$basename/../../../package.json"
rm -rf "$basename/../../../package-lock.json"
rm -rf "$basename/../../../node_modules"
disableInDir "$community"
if [[ $willingToDeleteToolingInEnterprise != "n" ]]
then
rm -rf "$basename/../../../$pathToEnterprise/.husky"
rm -rf "$basename/../../../$pathToEnterprise/.eslintignore"
rm -rf "$basename/../../../$pathToEnterprise/.prettierignore"
rm -rf "$basename/../../../$pathToEnterprise/.eslintrc.json"
rm -rf "$basename/../../../$pathToEnterprise/.prettierrc.json"
rm -rf "$basename/../../../$pathToEnterprise/package.json"
rm -rf "$basename/../../../$pathToEnterprise/package-lock.json"
rm -rf "$basename/../../../$pathToEnterprise/node_modules"
disableInDir "$pathToEnterprise"
fi
+22 -25
View File
@@ -1,7 +1,25 @@
#!/bin/bash
community=$(cd -- "$(dirname "$0")" &> /dev/null && cd ../../.. && pwd)
tooling="$community/addons/web/tooling"
script="$0"
basename="$(dirname "$script")"
enableInDir () {
cd $1
hooksPath="$(realpath --relative-to=. "$tooling/hooks")"
git config core.hooksPath "$hooksPath"
cp "$tooling/_eslintignore" .eslintignore
cp "$tooling/_prettierignore" .prettierignore
cp "$tooling/_eslintrc.json" .eslintrc.json
cp "$tooling/_prettierrc.json" .prettierrc.json
cp "$tooling/_package.json" package.json
if [[ $2 == "copy" ]]; then
# copy over node_modules and package-lock to avoid double "npm install"
cp "$community/package-lock.json" package-lock.json
cp -r "$community/node_modules" node_modules
else
npm install
fi
cd - &> /dev/null
}
read -p "Do you want the tooling installed in enterprise too ? [y, n]" willingToInstallToolingInEnterprise
if [[ $willingToInstallToolingInEnterprise != "n" ]]
@@ -10,32 +28,11 @@ then
pathToEnterprise=${pathToEnterprise:-../enterprise}
fi
cp -r "$basename/_husky" "$basename/../../../.husky"
cp "$basename/_eslintignore" "$basename/../../../.eslintignore"
cp "$basename/_prettierignore" "$basename/../../../.prettierignore"
cp "$basename/_eslintrc.json" "$basename/../../../.eslintrc.json"
cp "$basename/_prettierrc.json" "$basename/../../../.prettierrc.json"
cp "$basename/_package.json" "$basename/../../../package.json"
enableInDir "$community"
if [[ $willingToInstallToolingInEnterprise != "n" ]]
then
cp -r "$basename/_husky" "$basename/../../../$pathToEnterprise/.husky"
cp "$basename/_eslintignore" "$basename/../../../$pathToEnterprise/.eslintignore"
cp "$basename/_prettierignore" "$basename/../../../$pathToEnterprise/.prettierignore"
cp "$basename/_eslintrc.json" "$basename/../../../$pathToEnterprise/.eslintrc.json"
cp "$basename/_prettierrc.json" "$basename/../../../$pathToEnterprise/.prettierrc.json"
cp "$basename/_package.json" "$basename/../../../$pathToEnterprise/package.json"
fi
cd "$basename"
npm install
cd -
if [[ $willingToInstallToolingInEnterprise != "n" ]]
then
cd "$basename/../../../$pathToEnterprise"
npm install
cd -
enableInDir "$pathToEnterprise" copy
fi
echo ""
@@ -1,6 +1,4 @@
#!/bin/bash
. "$(dirname "$0")/_/husky.sh"
# run tooling only on branches that start with master to avoid linting noise in stable
if [[ $(git branch --show-current) == master* ]]; then
npm run format-staged
+3 -5
View File
@@ -1,7 +1,5 @@
#!/bin/bash
community=$(cd -- "$(dirname "$0")" &> /dev/null && cd ../../.. && pwd)
script="$0"
basename="$(dirname "$script")"
"$basename/disable.sh"
"$basename/enable.sh"
"$community/addons/web/tooling/disable.sh"
"$community/addons/web/tooling/enable.sh"