UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
Commit 29d51600 authored by Michelle Tran's avatar Michelle Tran
Browse files

Merge branch 'BULL-1712-official' into 'master'

BULL-1712: Pre-commit hook reject if non-WebP image file types are present

See merge request !159
parents 058ba8ce 19122aba
No related branches found
No related tags found
1 merge request!159BULL-1712: Pre-commit hook reject if non-WebP image file types are present
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx pretty-quick --staged && npm run lint
commit_error=0
find -E "./src" "./public" -type f -iregex "^.*\.(png|jpe?g|gif|tiff?|bmp)$" > "./.image_files"
if [ -s "./.image_files" ]
then
if [ -s "./.webp_exclusions" ]
then
cp "./.webp_exclusions" "./.webp_exclusions_escaped"
sed -i.bak -e '/^[[:blank:]]*#.*$/d' -e '/^[[:blank:]]*$/d' "./.webp_exclusions_escaped"
sed -i.bak -E 's/[^a-zA-Z 0-9]/\\&/g' "./.webp_exclusions_escaped"
<"./.webp_exclusions_escaped" tr "\n" "\0" | xargs -0 -I {} sed -i.bak "/^{}$/d" "./.image_files"
rm -f "./.image_files.bak" "./.webp_exclusions_escaped" "./.webp_exclusions_escaped.bak"
fi
git diff --name-only --staged | awk '{print "./" $0;}' > "./.staged_files"
cp "./.image_files" "./.image_files_escaped"
sed -i.bak -E 's/[^a-zA-Z 0-9]/\\&/g' "./.image_files_escaped"
while read -r filepath; do
if ! grep -q "$filepath" "./.staged_files"; then
sed -i.bak "/^$filepath$/d" "./.image_files"
fi
done <"./.image_files_escaped"
if [ -s "./.image_files" ]
then
commit_error=1
while read -r filepath; do
echo "File $filepath needs to be converted to WebP format before committing"
done <"./.image_files"
fi
fi
rm -f "./.image_files" "./.image_files.bak" "./.image_files_escaped" "./.image_files_escaped.bak" "./.staged_files"
if [ $commit_error -eq 1 ]
then
exit 1
fi
npx pretty-quick --staged
npm run lint
# Paths must be in the form ./{path to file}/file.ext
# Paths are case sensitive
./src/assets/images/Uber-Graphic.png
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment