summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenShift Bot <eparis+openshiftbot@redhat.com>2017-05-01 09:03:06 -0500
committerGitHub <noreply@github.com>2017-05-01 09:03:06 -0500
commita3f5c0ce84f32ada05d718d3e6e5a505ec0f9221 (patch)
tree3c51f5d717561f9275238d780a2b00a682f0fb8c
parent0d2d82f2718cd4674020821c9f00371aa5bc6ee0 (diff)
parentd8a70bbd179c59e121a652f2b590f65ed7889eab (diff)
downloadopenshift-a3f5c0ce84f32ada05d718d3e6e5a505ec0f9221.tar.gz
openshift-a3f5c0ce84f32ada05d718d3e6e5a505ec0f9221.tar.bz2
openshift-a3f5c0ce84f32ada05d718d3e6e5a505ec0f9221.tar.xz
openshift-a3f5c0ce84f32ada05d718d3e6e5a505ec0f9221.zip
Merge pull request #4027 from tbielawa/contrib_pre-commit_hook
Merged by openshift-bot
-rw-r--r--CONTRIBUTING.md7
-rw-r--r--hack/hooks/README.md37
-rw-r--r--hack/hooks/verify_generated_modules/README.md19
-rwxr-xr-xhack/hooks/verify_generated_modules/pre-commit55
4 files changed, 118 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a2c582722..1c0fa73ad 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -150,6 +150,13 @@ be reinstalled.
Here are some useful tips that might improve your workflow while working on this repository.
+#### Git Hooks
+
+Git hooks are included in this repository to aid in development. Check
+out the README in the
+[hack/hooks](http://github.com/openshift/openshift-ansible/blob/master/hack/hooks/README.md)
+directory for more information.
+
#### Activating a virtualenv managed by tox
If you want to enter a virtualenv created by tox to do additional debugging, you
diff --git a/hack/hooks/README.md b/hack/hooks/README.md
new file mode 100644
index 000000000..ef870540a
--- /dev/null
+++ b/hack/hooks/README.md
@@ -0,0 +1,37 @@
+# OpenShift-Ansible Git Hooks
+
+## Introduction
+
+This `hack` sub-directory holds
+[git commit hooks](https://www.atlassian.com/git/tutorials/git-hooks#conceptual-overview)
+you may use when working on openshift-ansible contributions. See the
+README in each sub-directory for an overview of what each hook does
+and if the hook has any specific usage or setup instructions.
+
+## Usage
+
+Basic git hook usage is simple:
+
+1) Copy (or symbolic link) the hook to the `$REPO_ROOT/.git/hooks/` directory
+2) Make the hook executable (`chmod +x $PATH_TO_HOOK`)
+
+## Multiple Hooks of the Same Type
+
+If you want to install multiple hooks of the same type, for example:
+multiple `pre-commit` hooks, you will need some kind of *hook
+dispatcher*. For an example of an easy to use hook dispatcher check
+out this gist by carlos-jenkins:
+
+* [multihooks.py](https://gist.github.com/carlos-jenkins/89da9dcf9e0d528ac978311938aade43)
+
+## Contributing Hooks
+
+If you want to contribute a new hook there are only a few criteria
+that must be met:
+
+* The hook **MUST** include a README describing the purpose of the hook
+* The README **MUST** describe special setup instructions if they are required
+* The hook **MUST** be in a sub-directory of this directory
+* The hook file **MUST** be named following the standard git hook
+ naming pattern (i.e., pre-commit hooks **MUST** be called
+ `pre-commit`)
diff --git a/hack/hooks/verify_generated_modules/README.md b/hack/hooks/verify_generated_modules/README.md
new file mode 100644
index 000000000..093fcf76a
--- /dev/null
+++ b/hack/hooks/verify_generated_modules/README.md
@@ -0,0 +1,19 @@
+# Verify Generated Modules
+
+Pre-commit hook for verifying that generated library modules match
+their EXPECTED content. Library modules are generated from fragments
+under the `roles/lib_(openshift|utils)/src/` directories.
+
+If the attempted commit modified files under the
+`roles/lib_(openshift|utils)/` directories this script will run the
+`generate.py --verify` command.
+
+This script will **NOT RUN** if module source fragments are modified
+but *not part of the commit*. I.e., you can still make commits if you
+modified module fragments AND other files but are *not comitting the
+the module fragments*.
+
+# Setup Instructions
+
+Standard installation procedure. Copy the hook to the `.git/hooks/`
+directory and ensure it is executable.
diff --git a/hack/hooks/verify_generated_modules/pre-commit b/hack/hooks/verify_generated_modules/pre-commit
new file mode 100755
index 000000000..8a319fd7e
--- /dev/null
+++ b/hack/hooks/verify_generated_modules/pre-commit
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+######################################################################
+# Pre-commit hook for verifying that generated library modules match
+# their EXPECTED content. Library modules are generated from fragments
+# under the 'roles/lib_(openshift|utils)/src/' directories.
+#
+# If the attempted commit modified files under the
+# 'roles/lib_(openshift|utils)/' directories this script will run the
+# 'generate.py --verify' command.
+#
+# This script will NOT RUN if module source fragments are modified but
+# not part of the commit. I.e., you can still make commits if you
+# modified module fragments AND other files but are not comitting the
+# the module fragments.
+
+# Did the commit modify any source module files?
+CHANGES=`git diff-index --stat --cached HEAD | grep -E '^ roles/lib_(openshift|utils)/src/(class|doc|ansible|lib)/'`
+RET_CODE=$?
+ABORT=0
+
+if [ "${RET_CODE}" -eq "0" ]; then
+ # Modifications detected. Run the verification scripts.
+
+ # Which was it?
+ if $(echo $CHANGES | grep -q 'roles/lib_openshift/'); then
+ echo "Validating lib_openshift..."
+ ./roles/lib_openshift/src/generate.py --verify
+ if [ "${?}" -ne "0" ]; then
+ ABORT=1
+ fi
+ fi
+
+ if $(echo $CHANGES | grep -q 'roles/lib_utils/'); then
+ echo "Validating lib_utils..."
+ ./roles/lib_utils/src/generate.py --verify
+ if [ "${?}" -ne "0" ]; then
+ ABORT=1
+ fi
+ fi
+
+ if [ "${ABORT}" -eq "1" ]; then
+ cat <<EOF
+
+ERROR: Module verification failed. Generated files do not match fragments.
+
+Choices to continue:
+ 1) Run './roles/lib_(openshift|utils)/src/generate.py' from the root of
+ the repo to regenerate the files
+ 2) Skip verification with '--no-verify' option to 'git commit'
+EOF
+ fi
+fi
+
+exit $ABORT