Skip to content

Commit

Permalink
[FIX] web: fix tooling failing to run due to bash-specific syntax
Browse files Browse the repository at this point in the history
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 #86888

Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
  • Loading branch information
sdegueldre authored and SimonGenin committed Mar 22, 2022
1 parent d9bc8dd commit 3104ab1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 54 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -34,7 +34,6 @@ setup/win32/static/postgresql*.exe
node_modules
package-lock.json
package.json
.husky

# various virtualenv
/bin/
Expand Down
1 change: 0 additions & 1 deletion addons/web/tooling/_husky/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions addons/web/tooling/_package.json
Expand Up @@ -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'",
Expand All @@ -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"
Expand Down
33 changes: 15 additions & 18 deletions addons/web/tooling/disable.sh
@@ -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" ]]
Expand All @@ -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


Expand Down
47 changes: 22 additions & 25 deletions addons/web/tooling/enable.sh
@@ -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" ]]
Expand All @@ -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 ""
Expand Down
@@ -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
Expand Down
8 changes: 3 additions & 5 deletions addons/web/tooling/reload.sh
@@ -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"

0 comments on commit 3104ab1

Please sign in to comment.