Skip to content

Commit

Permalink
DAOS-623 ci: Modify githooks to allow skip (daos-stack#13885)
Browse files Browse the repository at this point in the history
*Allow one to set DAOS_SKIP=exp1,exp2 to skip
git hooks on a case by case basis as needed.
*Unify the scripts in one file

Signed-off-by: Jeff Olivier <[email protected]>
  • Loading branch information
jolivier23 authored Feb 28, 2024
1 parent de031fd commit 8d8d224
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
14 changes: 1 addition & 13 deletions utils/githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#!/bin/bash
set -eu

run-parts() {
local dir="$1"
shift

for i in $(LC_ALL=C; echo ${dir%/}/*[^~,]); do
# don't run vim .swp files
[ "${i%.sw?}" != "${i}" ] && continue
$i "$@"
done
}

run-parts utils/githooks/${0##*/}.d "$@" 1>&2
. utils/githooks/hook_base.sh
13 changes: 11 additions & 2 deletions utils/githooks/commit-msg.d/10-watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def find_hooks():
return hooks


def emit_watermark(msg):
"""Print the watermark to the commit message"""
msg.write("Required-githooks: true\n")
skipped = os.environ.get("DAOS_GITHOOK_SKIP", None)
if skipped:
msg.write(f"Skipped-githooks: {skipped}\n")
msg.write("\n")


def run_check():
"""Run the checks for the required commit hooks"""
empty_commit = True
Expand Down Expand Up @@ -60,10 +69,10 @@ def run_check():
for line in msg:
if not hook_emitted:
if line.startswith("Signed-off-by"):
commit_msg.write("Required-githooks: true\n\n")
emit_watermark(commit_msg)
hook_emitted = True
elif line.startswith("#"):
commit_msg.write("Required-githooks: true\n\n")
emit_watermark(commit_msg)
hook_emitted = True
commit_msg.write(line)

Expand Down
34 changes: 34 additions & 0 deletions utils/githooks/hook_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -eu

. utils/githooks/find_base.sh
export TARGET

hook=${0##*/}
rm -f ".${hook}"

IFS=', ' read -r -a skip_list <<< "${DAOS_GITHOOK_SKIP:-}"

run-parts() {
local dir="$1"
shift

for i in $(LC_ALL=C; echo "${dir%/}"/*[^~,]); do
# don't run vim .swp files
[ "${i%.sw?}" != "${i}" ] && continue
skip_item=false
for skip in "${skip_list[@]}"; do
if [[ "${i}" =~ ${skip} ]]; then
skip_item=true
echo "Skipping ${i}"
break
fi
done
$skip_item && continue
$i "$@"
done
}

run-parts utils/githooks/"${hook}".d "$@" 1>&2

touch ".${hook}"
21 changes: 1 addition & 20 deletions utils/githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
#!/bin/bash
set -eu

. utils/githooks/find_base.sh
export TARGET

hook=${0##*/}
rm -f ".${hook}"

run-parts() {
local dir="$1"
shift

for i in $(LC_ALL=C; echo "${dir%/}"/*[^~,]); do
# don't run vim .swp files
[ "${i%.sw?}" != "${i}" ] && continue
$i "$@"
done
}

run-parts utils/githooks/"${hook}".d "$@" 1>&2

touch ".${hook}"
. utils/githooks/hook_base.sh
19 changes: 1 addition & 18 deletions utils/githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#!/bin/bash
set -eu

hook=${0##*/}
rm -f ".${hook}"

run-parts() {
local dir="$1"
shift

for i in $(LC_ALL=C; echo "${dir%/}"/*[^~,]); do
# don't run vim .swp files
[ "${i%.sw?}" != "${i}" ] && continue
$i "$@"
done
}

run-parts utils/githooks/"${hook}".d "$@" 1>&2

touch ".${hook}"
. utils/githooks/hook_base.sh

0 comments on commit 8d8d224

Please sign in to comment.