Add basic setup for precommit (#749) (#764)

* Add basic setup for precommit

* Update README.md with instructions on installing precommit hooks

---------

Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
Co-authored-by: Bartlomiej Wroblewski <bwroblewski10@gmail.com>

[ROCm/composable_kernel commit: 237f9cd3aa]
This commit is contained in:
Adam Osewski
2023-07-06 18:01:06 +02:00
committed by GitHub
parent aff6040b5b
commit f5b4375a3d
5 changed files with 70 additions and 0 deletions

17
script/check_copyright_year.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
current_year=$(date +%Y)
exit_code=0
for file in $@; do
if grep -q "Copyright (c)" $file
then
if ! grep -q "Copyright (c).*$current_year" $file
then
echo "ERROR: File $file has a copyright notice without the current year ($current_year)."
exit_code=1
fi
fi
done
exit $exit_code

20
script/install_precommit.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
run_and_check() {
"$@"
status=$?
if [ $status -ne 0 ]; then
echo "Error with \"$@\": Exited with status $status"
exit $status
fi
return $status
}
echo "I: Installing tools required for pre-commit checks..."
run_and_check apt install clang-format-10
echo "I: Installing pre-commit itself..."
run_and_check pip3 install pre-commit
run_and_check pre-commit install
echo "I: Installation successful."

1
script/uninstall_precommit.sh Executable file
View File

@@ -0,0 +1 @@
pre-commit uninstall