summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Westcott IV <32551173+john-westcott-iv@users.noreply.github.com>2022-03-24 15:58:14 +0100
committerGitHub <noreply@github.com>2022-03-24 15:58:14 +0100
commitb9cdd6f2c82ad2ddbb7b49e053abb1aee11af745 (patch)
treecbfffc9229529f378984bd93cd3def320d73ae4a
parentMerge pull request #11941 from shanemcd/update-devel-image-refs (diff)
downloadawx-b9cdd6f2c82ad2ddbb7b49e053abb1aee11af745.tar.xz
awx-b9cdd6f2c82ad2ddbb7b49e053abb1aee11af745.zip
Adding ability to run user level pre-commit hooks (#11923)
* Adding ability to run user level pre-commit hooks * Adding pre-commit docs in CONTRIBUTING.md
-rw-r--r--.gitignore3
-rw-r--r--CONTRIBUTING.md9
-rwxr-xr-xpre-commit.sh19
3 files changed, 31 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 79d65e0654..3d2c6c7ec0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,9 @@ reference-schema.json
.tags
.tags1
+# User level pre-commit hooks
+pre-commit-user
+
# Tower
awx-dev
awx/settings/local_*.py*
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 57c2d79f21..535fb0db66 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -17,6 +17,7 @@ Have questions about this document or anything not covered here? Come chat with
- [Building API Documentation](#building-api-documentation)
- [Accessing the AWX web interface](#accessing-the-awx-web-interface)
- [Purging containers and images](#purging-containers-and-images)
+ - [Pre commit hooks](#pre-commit-hooks)
- [What should I work on?](#what-should-i-work-on)
- [Submitting Pull Requests](#submitting-pull-requests)
- [PR Checks run by Zuul](#pr-checks-run-by-zuul)
@@ -104,6 +105,14 @@ When necessary, remove any AWX containers and images by running the following:
(host)$ make docker-clean
```
+### Pre commit hooks
+
+When you attempt to perform a `git commit` there will be a pre-commit hook that gets run before the commit is allowed to your local repository. For example, python's [black](https://pypi.org/project/black/) will be run to test the formatting of any python files.
+
+While you can use environment variables to skip the pre-commit hooks GitHub will run similar tests and prevent merging of PRs if the tests do not pass.
+
+ If you would like to add additional commit hooks for your own usage you can create a directory in the root of the repository called `pre-commit-user`. Any executable file in that directory will be executed as part of the pre-commit hooks. If any of the pre-commit checks fail the commit will be halted. For your convenience in user scripts, a variable called `CHANGED_FILES` will be set with any changed files present in the commit.
+
## What should I work on?
For feature work, take a look at the current [Enhancements](https://github.com/ansible/awx/issues?q=is%3Aissue+is%3Aopen+label%3Atype%3Aenhancement).
diff --git a/pre-commit.sh b/pre-commit.sh
index 80a49fb47c..c97568dd9d 100755
--- a/pre-commit.sh
+++ b/pre-commit.sh
@@ -6,3 +6,22 @@ if [ -z $AWX_IGNORE_BLACK ] ; then
exit 1)
fi
fi
+
+if [ -z $AWX_IGNORE_USER ] ; then
+ FAIL=0
+ export CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM)
+ if [ -d ./pre-commit-user ] ; then
+ for SCRIPT in `find ./pre-commit-user -executable -type f` ; do
+ echo "Running user pre-commit hook $SCRIPT"
+ $SCRIPT
+ if [ $? != 0 ] ; then
+ echo "User test $SCRIPT failed"
+ FAIL=1
+ fi
+ done
+ fi
+ if [ $FAIL == 1 ] ; then
+ echo "One or more user tests failed, see messages above"
+ exit 1
+ fi
+fi