Skip to content

Instantly share code, notes, and snippets.

@fluxrad
Created April 11, 2012 19:04

Revisions

  1. fluxrad revised this gist Jun 7, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    #!/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*
  2. fluxrad revised this gist Jun 7, 2012. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,12 @@
    #!/bin/bash
    # pre-commit git hook to check the validity of a puppet manifest

    # 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|erb)'`
    for file in `git diff --name-only --cached | grep -E '\.(pp)'`
    do
    # Only check new/modified files
    if [[ -f $file ]]
    @@ -12,6 +16,7 @@ do
    --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
    @@ -29,7 +34,8 @@ 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|erb)'`
    for file in `git diff --name-only --cached | grep -E '\.(pp)'`
    do
    if [[ -f $file ]]
    then
  3. fluxrad revised this gist Apr 18, 2012. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,16 @@
    # pre-commit git hook to check the validity of a puppet manifest

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

    # Set us up to bail if we receive any syntax errors
    @@ -26,9 +29,8 @@ 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 ".pp"`
    for file in `git diff --name-only --cached | grep -E '\.(pp|erb)'`
    do
    # ignore renamed/removed files
    if [[ -f $file ]]
    then
    puppet parser validate --mode user $file
  4. fluxrad revised this gist Apr 11, 2012. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -28,13 +28,17 @@ echo "### Checking if puppet manifests are valid ###"
    # for file in `find . -name "*.pp"`
    for file in `git diff --name-only --cached | grep ".pp"`
    do
    puppet parser validate --mode user $file
    if [[ $? -ne 0 ]]
    # ignore renamed/removed files
    if [[ -f $file ]]
    then
    echo "ERROR: puppet parser failed at: $file"
    syntax_is_bad=1
    else
    echo "OK: $file looks valid"
    puppet parser validate --mode user $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 ""
  5. fluxrad revised this gist Apr 11, 2012. 1 changed file with 17 additions and 8 deletions.
    25 changes: 17 additions & 8 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,28 @@
    #!/bin/bash
    # .git/hooks/pre-commit
    # pre-commit git hook to check the validity of a puppet manifest

    echo "### Checking puppet syntax ###"
    echo "### Checking puppet syntax, for science! ###"
    for file in `git diff --name-only --cached`
    do
    puppet-lint --with-filename $file

    # Set us up to bail if we receive any syntax errors
    if [[ $? -ne 0 ]]
    # Only check new/modified files
    if [[ -f $file ]]
    then
    syntax_is_bad=1
    puppet-lint \
    --no-80chars-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 puppet manifests are valid ###"
    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"`
    @@ -37,4 +44,6 @@ then
    echo "FATAL: Syntax is bad. See above errors"
    echo "Bailing"
    exit 1
    else
    echo "Everything looks good."
    fi
  6. fluxrad revised this gist Apr 11, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/bin/bash
    # .git/hooks/pre-commit
    # pre-commit git hook to check the validity of a puppet manifest

    echo "### Checking puppet syntax ###"
  7. fluxrad created this gist Apr 11, 2012.
    39 changes: 39 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash
    # pre-commit git hook to check the validity of a puppet manifest

    echo "### Checking puppet syntax ###"
    for file in `git diff --name-only --cached`
    do
    puppet-lint --with-filename $file

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

    echo "### Checking 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 ".pp"`
    do
    puppet parser validate --mode user $file
    if [[ $? -ne 0 ]]
    then
    echo "ERROR: puppet parser failed at: $file"
    syntax_is_bad=1
    else
    echo "OK: $file looks valid"
    fi
    done
    echo ""

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