sh Puppet pre-commit hook

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Puppet pre-commit hook相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# pre-commit git hook to check the validity of a puppet manifest
#
# Prerequisites:
#   gem install puppet-lint puppet
#
# Install:
#  /path/to/repo/.git/hooks/pre-comit

# Source RVM if needed
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

echo "### Checking puppet syntax, for science! ###"
# for file in `git diff --name-only --cached | grep -E '\.(pp|erb)'`
for file in `git diff --name-only --cached | grep -E '\.(pp)'`
do
    # Only check new/modified files
    if [[ -f $file ]]
    then
        puppet-lint \
            --no-documentation-check \
            --no-80chars-check \
            --no-autoloader_layout-check \
            --no-nested_classes_or_defines-check \
            --no-only_variable_string-check \
            --no-2sp_soft_tabs-check \
            --with-filename $file

        # Set us up to bail if we receive any syntax errors
        if [[ $? -ne 0 ]]
        then
            syntax_is_bad=1
        else
            echo "$file looks good"
        fi
    fi
done
echo ""

echo "### Checking if puppet manifests are valid ###"
# validating the whole manifest takes too long. uncomment this
# if you want to test the whole shebang.
# for file in `find . -name "*.pp"`
# for file in `git diff --name-only --cached | grep -E '\.(pp|erb)'`
for file in `git diff --name-only --cached | grep -E '\.(pp)'`
do
    if [[ -f $file ]]
    then
        puppet parser validate $file
        if [[ $? -ne 0 ]]
        then
            echo "ERROR: puppet parser failed at: $file"
            syntax_is_bad=1
        else
            echo "OK: $file looks valid"
        fi
    fi
done
echo ""

if [[ $syntax_is_bad -eq 1 ]]
then
    echo "FATAL: Syntax is bad. See above errors"
    echo "Bailing"
    exit 1
else
    echo "Everything looks good."
fi

以上是关于sh Puppet pre-commit hook的主要内容,如果未能解决你的问题,请参考以下文章

Git钩子:'.git/hooks/pre-commit':不允许操作

.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory

Subversion - pre-commit hooks开发

json 使用pre-commit git hook检查PHPCS的PSR-2验证。

json 使用pre-commit git hook检查PHPCS的PSR-2验证。

Windows Pre-commit hook for comment length Subversion