This is an automated email from the ASF dual-hosted git repository.

jihoonson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e097ea  Add git hooks that can run multiple scripts (#12300)
0e097ea is described below

commit 0e097ead36a1aa044def1e85ed2ccf52eb5a25d4
Author: Jihoon Son <[email protected]>
AuthorDate: Wed Mar 9 07:16:47 2022 +0900

    Add git hooks that can run multiple scripts (#12300)
    
    * Add git hooks that can run multiple scripts
    
    * scripts to install/uninstall hooks
    
    * better message for uninstall; support pre-push params
---
 dev/intellij-setup.md                              |  2 +-
 hooks/{pre-push.sh => install-hooks.sh}            | 26 +++++++++++++--
 setup-hooks.sh => hooks/pre-commit                 |  3 +-
 .../pre-commits/_pre-commit.sample                 |  3 +-
 hooks/pre-push                                     | 22 +++++++++++++
 .../pre-pushes/_pre-push.sample                    |  3 +-
 hooks/{pre-push.sh => pre-pushes/checkstyle-check} |  1 +
 hooks/{pre-push.sh => run-all-in-dir.py}           | 22 +++++++++++--
 hooks/uninstall-hooks.sh                           | 37 ++++++++++++++++++++++
 9 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/dev/intellij-setup.md b/dev/intellij-setup.md
index 74b09a0..a3d9816 100644
--- a/dev/intellij-setup.md
+++ b/dev/intellij-setup.md
@@ -47,7 +47,7 @@ will generate a report to show the current code coverage on 
the code (not just y
 ## Git Checkstyle Verification Hook (Optional)
 Git Checkstyle pre-commit hook can be installed to automatically run 
checkstyle verification before committing, 
 saving cycle from avoiding the checkstyle failing later in Travis/CI 
environment.
-The hook can be setup easily by running the <DRUID_HOME>/setup-hooks.sh script.
+The hook can be setup easily by running the 
<DRUID_HOME>/hooks/install-hooks.sh script.
 
 ## Metadata
 The installation of a MySQL metadata store is outside the scope of this 
document, but instructions on setting up MySQL can be found at 
[docs/development/extensions-core/mysql.md](/docs/development/extensions-core/mysql.md).
 This assumes you followed the example there and have a database named `druid` 
with proper permissions for a user named `druid` and a password of `diurd`.
diff --git a/hooks/pre-push.sh b/hooks/install-hooks.sh
similarity index 54%
copy from hooks/pre-push.sh
copy to hooks/install-hooks.sh
index c1b5140..506816b 100755
--- a/hooks/pre-push.sh
+++ b/hooks/install-hooks.sh
@@ -1,4 +1,5 @@
 #!/bin/bash -eu
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
@@ -14,5 +15,26 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# set thread count to 2 times of cores to speed up checking
-mvn checkstyle:checkstyle -T 2C --fail-at-end
+function cp_if_not_exist(){
+  if [ -e "$2" ]
+    then
+      echo "$2 already exists!"
+      exit 1
+  else
+    cp -r "$1" "$2"
+  fi
+}
+
+if [ $# != 1 ]
+  then
+    echo 'usage: program {$DRUID_ROOT}'
+    exit 1
+fi
+
+DRUID_ROOT=$1
+
+cp_if_not_exist ${DRUID_ROOT}/hooks/run-all-in-dir.py 
${DRUID_ROOT}/.git/hooks/run-all-in-dir.py
+cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commit 
${DRUID_ROOT}/.git/hooks/pre-commit
+cp_if_not_exist ${DRUID_ROOT}/hooks/pre-push ${DRUID_ROOT}/.git/hooks/pre-push
+cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commits 
${DRUID_ROOT}/.git/hooks/pre-commits
+cp_if_not_exist ${DRUID_ROOT}/hooks/pre-pushes 
${DRUID_ROOT}/.git/hooks/pre-pushes
diff --git a/setup-hooks.sh b/hooks/pre-commit
similarity index 93%
copy from setup-hooks.sh
copy to hooks/pre-commit
index 85c60d1..6cfd4b9 100755
--- a/setup-hooks.sh
+++ b/hooks/pre-commit
@@ -1,4 +1,5 @@
 #!/bin/bash -eu
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
@@ -14,4 +15,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ln -s ../../hooks/pre-push.sh .git/hooks/pre-push
+.git/hooks/run-all-in-dir.py .git/hooks/pre-commits
\ No newline at end of file
diff --git a/setup-hooks.sh b/hooks/pre-commits/_pre-commit.sample
similarity index 94%
copy from setup-hooks.sh
copy to hooks/pre-commits/_pre-commit.sample
index 85c60d1..b6db041 100755
--- a/setup-hooks.sh
+++ b/hooks/pre-commits/_pre-commit.sample
@@ -1,4 +1,5 @@
 #!/bin/bash -eu
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
@@ -14,4 +15,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ln -s ../../hooks/pre-push.sh .git/hooks/pre-push
+echo 'pre-commit sample'
\ No newline at end of file
diff --git a/hooks/pre-push b/hooks/pre-push
new file mode 100755
index 0000000..40c40db
--- /dev/null
+++ b/hooks/pre-push
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+.git/hooks/run-all-in-dir.py .git/hooks/pre-pushes $1 $2
\ No newline at end of file
diff --git a/setup-hooks.sh b/hooks/pre-pushes/_pre-push.sample
similarity index 94%
rename from setup-hooks.sh
rename to hooks/pre-pushes/_pre-push.sample
index 85c60d1..a4ca214 100755
--- a/setup-hooks.sh
+++ b/hooks/pre-pushes/_pre-push.sample
@@ -1,4 +1,5 @@
 #!/bin/bash -eu
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
@@ -14,4 +15,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ln -s ../../hooks/pre-push.sh .git/hooks/pre-push
+echo 'pre-push sample'
\ No newline at end of file
diff --git a/hooks/pre-push.sh b/hooks/pre-pushes/checkstyle-check
similarity index 99%
copy from hooks/pre-push.sh
copy to hooks/pre-pushes/checkstyle-check
index c1b5140..fdfdd09 100755
--- a/hooks/pre-push.sh
+++ b/hooks/pre-pushes/checkstyle-check
@@ -1,4 +1,5 @@
 #!/bin/bash -eu
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
diff --git a/hooks/pre-push.sh b/hooks/run-all-in-dir.py
similarity index 66%
rename from hooks/pre-push.sh
rename to hooks/run-all-in-dir.py
index c1b5140..6922e04 100755
--- a/hooks/pre-push.sh
+++ b/hooks/run-all-in-dir.py
@@ -1,4 +1,5 @@
-#!/bin/bash -eu
+#!/usr/bin/env python3
+
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
@@ -14,5 +15,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# set thread count to 2 times of cores to speed up checking
-mvn checkstyle:checkstyle -T 2C --fail-at-end
+import os
+import sys
+import subprocess
+
+
+if len(sys.argv) < 2:
+       sys.stderr.write('usage: program <hooks directory>\n')
+       sys.exit(1)
+
+hooks_dir = sys.argv[1]
+args = sys.argv[2:]
+
+for hook in os.listdir(hooks_dir):
+       if not hook.startswith("_"):
+               command = [os.path.join(hooks_dir, hook)] + args
+               print("Running {}".format(command))
+               subprocess.run(command, shell=True)
diff --git a/hooks/uninstall-hooks.sh b/hooks/uninstall-hooks.sh
new file mode 100755
index 0000000..e118eb0
--- /dev/null
+++ b/hooks/uninstall-hooks.sh
@@ -0,0 +1,37 @@
+#!/bin/bash -eu
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+if [ $# != 1 ]
+  then
+    echo 'usage: program {$DRUID_ROOT}'
+    exit 1
+fi
+
+DRUID_ROOT=$1
+
+# This script does not remove .git/hooks/pre-commit, .git/hooks/pre-push, or 
any other git hook scripts
+# because those files may have user-custom hooks.
+# Instead, we remove only the files and directories that we are sure it is 
safe to remove.
+rm -f ${DRUID_ROOT}/.git/hooks/run-all-in-dir.py
+rm -rf ${DRUID_ROOT}/.git/hooks/pre-commits
+rm -rf ${DRUID_ROOT}/.git/hooks/pre-pushes
+
+echo "This script does not remove or modify the git hook script files in 
.git/hooks, such as 'pre-commit' or 'pre-push'. Those scripts should be removed 
or modified manually."

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to