mirror of
				https://github.com/XRPLF/clio.git
				synced 2025-11-04 11:55:51 +00:00 
			
		
		
		
	chore: Use only pre-commit hooks (#2057)
Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										84
									
								
								pre-commit-hooks/check-doxygen-docs.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										84
									
								
								pre-commit-hooks/check-doxygen-docs.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,84 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Note: This script is intended to be run from the root of the repository.
 | 
			
		||||
#
 | 
			
		||||
# Not really a hook but should be used to check the completeness of documentation for added code, otherwise CI will come for you.
 | 
			
		||||
# It's good to have /tmp as the output so that consecutive runs are fast but no clutter in the repository.
 | 
			
		||||
 | 
			
		||||
echo "+ Checking documentation..."
 | 
			
		||||
 | 
			
		||||
ROOT=$(pwd)
 | 
			
		||||
DOXYGEN=$(command -v doxygen)
 | 
			
		||||
TMPDIR=${ROOT}/.cache/doxygen
 | 
			
		||||
TMPFILE=${TMPDIR}/docs.log
 | 
			
		||||
DOCDIR=${TMPDIR}/out
 | 
			
		||||
 | 
			
		||||
# Check doxygen is at all installed
 | 
			
		||||
if [ -z "$DOXYGEN" ]; then
 | 
			
		||||
    # No hard error if doxygen is not installed yet
 | 
			
		||||
    cat <<EOF
 | 
			
		||||
 | 
			
		||||
                                   WARNING
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
        'doxygen' is required to check documentation.
 | 
			
		||||
        Please install it for next time.
 | 
			
		||||
 | 
			
		||||
        Your changes may fail to pass CI once pushed.
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
EOF
 | 
			
		||||
    exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Check version of doxygen is at least 1.12
 | 
			
		||||
version=$($DOXYGEN --version | grep -o '[0-9\.]*')
 | 
			
		||||
 | 
			
		||||
if [[ "1.12.0" > "$version" ]]; then
 | 
			
		||||
    # No hard error if doxygen version is not the one we want - let CI deal with it
 | 
			
		||||
    cat <<EOF
 | 
			
		||||
 | 
			
		||||
                                    ERROR
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
        A minimum of version 1.12 of `which doxygen` is required.
 | 
			
		||||
        Your version is $version. Please upgrade it for next time.
 | 
			
		||||
 | 
			
		||||
        Your changes may fail to pass CI once pushed.
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
EOF
 | 
			
		||||
    exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
mkdir -p ${DOCDIR} > /dev/null 2>&1
 | 
			
		||||
pushd ${DOCDIR} > /dev/null 2>&1
 | 
			
		||||
 | 
			
		||||
cat ${ROOT}/docs/Doxyfile | \
 | 
			
		||||
sed \
 | 
			
		||||
    -e "s/\${LINT}/YES/" \
 | 
			
		||||
    -e "s!\${SOURCE}!${ROOT}!" \
 | 
			
		||||
    -e "s/\${USE_DOT}/NO/" \
 | 
			
		||||
    -e "s/\${EXCLUDES}/impl/" \
 | 
			
		||||
| ${DOXYGEN} - 2> ${TMPFILE} 1> /dev/null
 | 
			
		||||
 | 
			
		||||
# We don't want to check for default values and typedefs as well as for member variables
 | 
			
		||||
OUT=$(cat ${TMPFILE} \
 | 
			
		||||
    | grep -v "=default" \
 | 
			
		||||
    | grep -v "\(variable\)" \
 | 
			
		||||
    | grep -v "\(typedef\)")
 | 
			
		||||
 | 
			
		||||
rm -rf ${TMPFILE} > /dev/null 2>&1
 | 
			
		||||
popd > /dev/null 2>&1
 | 
			
		||||
 | 
			
		||||
if [[ ! -z "$OUT" ]]; then
 | 
			
		||||
    cat <<EOF
 | 
			
		||||
 | 
			
		||||
                                    ERROR
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
                      Found issues with documentation:
 | 
			
		||||
 | 
			
		||||
$OUT
 | 
			
		||||
-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
EOF
 | 
			
		||||
    exit 2
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										32
									
								
								pre-commit-hooks/fix-local-includes.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								pre-commit-hooks/fix-local-includes.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Note: This script is intended to be run from the root of the repository.
 | 
			
		||||
#
 | 
			
		||||
# This script checks will fix local includes in the C++ code.
 | 
			
		||||
 | 
			
		||||
# paths to fix include statements
 | 
			
		||||
sources="src tests"
 | 
			
		||||
 | 
			
		||||
echo "+ Fixing local includes..."
 | 
			
		||||
 | 
			
		||||
function grep_code {
 | 
			
		||||
    grep -l "${1}" ${sources} -r --include \*.hpp --include \*.cpp
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GNU_SED=$(sed --version 2>&1 | grep -q 'GNU' && echo true || echo false)
 | 
			
		||||
 | 
			
		||||
if [[ "$GNU_SED" == "false" ]]; then # macOS sed
 | 
			
		||||
    # make all includes to be <...> style
 | 
			
		||||
    grep_code '#include ".*"' | xargs sed -i '' -E 's|#include "(.*)"|#include <\1>|g'
 | 
			
		||||
 | 
			
		||||
    # make local includes to be "..." style
 | 
			
		||||
    main_src_dirs=$(find ./src -maxdepth 1 -type d -exec basename {} \; | tr '\n' '|' | sed 's/|$//' | sed 's/|/\\|/g')
 | 
			
		||||
    grep_code "#include <\($main_src_dirs\)/.*>" | xargs sed -i '' -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g"
 | 
			
		||||
else
 | 
			
		||||
    # make all includes to be <...> style
 | 
			
		||||
    grep_code '#include ".*"' | xargs sed -i -E 's|#include "(.*)"|#include <\1>|g'
 | 
			
		||||
 | 
			
		||||
    # make local includes to be "..." style
 | 
			
		||||
    main_src_dirs=$(find ./src -maxdepth 1 -type d  -exec basename {} \; | paste -sd '|' | sed 's/|/\\|/g')
 | 
			
		||||
    grep_code "#include <\($main_src_dirs\)/.*>" | xargs sed -i -E "s|#include <(($main_src_dirs)/.*)>|#include \"\1\"|g"
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										3
									
								
								pre-commit-hooks/lfs/post-checkout
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								pre-commit-hooks/lfs/post-checkout
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
 | 
			
		||||
git lfs post-checkout "$@"
 | 
			
		||||
							
								
								
									
										3
									
								
								pre-commit-hooks/lfs/post-commit
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								pre-commit-hooks/lfs/post-commit
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
 | 
			
		||||
git lfs post-commit "$@"
 | 
			
		||||
							
								
								
									
										3
									
								
								pre-commit-hooks/lfs/post-merge
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								pre-commit-hooks/lfs/post-merge
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
 | 
			
		||||
git lfs post-merge "$@"
 | 
			
		||||
							
								
								
									
										3
									
								
								pre-commit-hooks/lfs/pre-push
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								pre-commit-hooks/lfs/pre-push
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
 | 
			
		||||
git lfs pre-push "$@"
 | 
			
		||||
							
								
								
									
										54
									
								
								pre-commit-hooks/verify-commits.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										54
									
								
								pre-commit-hooks/verify-commits.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# git for-each-ref refs/tags  # see which tags are annotated and which are lightweight. Annotated tags are "tag" objects.
 | 
			
		||||
# # Set these so your commits and tags are always signed
 | 
			
		||||
# git config commit.gpgsign true
 | 
			
		||||
# git config tag.gpgsign true
 | 
			
		||||
 | 
			
		||||
verify_commit_signed() {
 | 
			
		||||
    if git verify-commit HEAD &> /dev/null; then
 | 
			
		||||
        :
 | 
			
		||||
        # echo "HEAD commit seems signed..."
 | 
			
		||||
    else
 | 
			
		||||
        echo "HEAD commit isn't signed!"
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
verify_tag() {
 | 
			
		||||
    if git describe --exact-match --tags HEAD &> /dev/null; then
 | 
			
		||||
        : # You might be ok to push
 | 
			
		||||
        # echo "Tag is annotated."
 | 
			
		||||
        return 0
 | 
			
		||||
    else
 | 
			
		||||
        echo "Tag for [$version] not an annotated tag."
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
verify_tag_signed() {
 | 
			
		||||
    if git verify-tag "$version" &> /dev/null ; then
 | 
			
		||||
        : # ok, I guess we'll let you push
 | 
			
		||||
        # echo "Tag appears signed"
 | 
			
		||||
        return 0
 | 
			
		||||
    else
 | 
			
		||||
        echo "$version tag isn't signed"
 | 
			
		||||
        echo "Sign it with [git tag -ams\"$version\" $version]"
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
while read local_ref local_oid remote_ref remote_oid; do
 | 
			
		||||
    # Check some things if we're pushing a branch called "release/"
 | 
			
		||||
    if echo "$remote_ref" | grep ^refs\/heads\/release\/ &> /dev/null ; then
 | 
			
		||||
        version=$(git tag --points-at HEAD)
 | 
			
		||||
        echo "Looks like you're trying to push a $version release..."
 | 
			
		||||
        echo "Making sure you've signed and tagged it."
 | 
			
		||||
        if verify_commit_signed && verify_tag && verify_tag_signed ; then
 | 
			
		||||
            : # Ok, I guess you can push
 | 
			
		||||
        else
 | 
			
		||||
            exit 1
 | 
			
		||||
        fi
 | 
			
		||||
    fi
 | 
			
		||||
done
 | 
			
		||||
		Reference in New Issue
	
	Block a user