Git Product home page Git Product logo

puppet-pre-commit-hook's Introduction

A Puppet pre-commit hook

This is inspired/editted from the pre-commit hook found on the following blog: http://techblog.roethof.net/puppet/a-puppet-git-pre-commit-hook-is-always-easy-to-have/

All credits should really go to Ronny Roethof, I merely editted it and added some ERB template checking.

The code is made available here under the MIT license.

What does this do?

For every commit you make into your repository, this script will check the syntax of your code (both Puppet (.pp) and Ruby Templates (.erb)) to make sure they are valid. This does not check the actual workings of your Puppet code, you should look into rspec or cucumber testing for that.

If any invalid syntax is found, it will abort the commit and you won't be able to commit your faulty code that will break production. Yay!

Installation

Go to your git repository, create the file .git/hooks/pre-commit and place the content of this repo in it. Make it execute (chmod +x $file).

There is also a simple installer provided called install. Provide a directory that contains your puppet repositories (default: ..). Running this will attempt symlink the .git/hooks/pre-commit to this hook in all directories at the specified location without regard to whether it is a valid git repository. This may simplify installation when you have multiple puppet repos in the same directory.

$ ./install ~/git/puppet/
Installing hook to all directories underneath /home/rnelson0/git/puppet/
Adding hook to directory controlrepo
Adding hook to directory custom_facts
Adding hook to directory profile
Adding hook to directory role
Setting the executable bit on the hook.
Installation complete.

PDK vs Bundler

The pre-commit hook attempts to auto-detect the availability of the PDK or a bundler setup, with a preference for the PDK. If you have the PDK installed but prefer to use bundler, you may override the default behavior by:

  • Creating ~/.prefer_bundler (global override)
  • Creating ./.prefer_bundler (override only in the current directory)
  • Set PREFER_BUNDLER to any non-null value (override only for the current command/shell instance)

What does it look like ?

Every commit will check the changed files and will report on them as such.

 $ git commit modules/name/ -m "Your commit message"

*** Checking puppet code for style ***
PASSED: modules/name/manifests/init.pp
PASSED: modules/name/tests/init.pp

*** Checking puppet manifest syntax ***
PASSED: modules/name/manifests/init.pp
PASSED: modules/name/tests/init.pp

*** Checking ruby template(erb) syntax ***
PASSED: modules/name/templates/template-file.erb

No Errors Found, Commit ACCEPTED
[develop adb6889] Your commit message
 3 files changed, 120 insertions(+)
  create mode 100644 modules/name/manifests/init.pp
  create mode 100644 modules/name/templates/template-file.erb
  create mode 100644 modules/name/tests/init.pp

puppet-pre-commit-hook's People

Contributors

coopernetes avatar geoffdavis avatar jaketrogers avatar jmtd avatar krionux avatar mattiasgeniar avatar mihall-primus avatar rnelson0 avatar sciurus avatar testingoauth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-pre-commit-hook's Issues

Investigate parallel processing the pre-commit hook

On a large codebase, the pre-commit hook now takes 5-15 seconds to complete.

With a hundred commits a day, that's killing productivity and causes context switching to other tasks.

I should investigate if pre-commit hooks are capable of doing parallel tasks (lint check, validate, erb template checks) and still be able to report back to the git client on the state.

Investigate reducing calls to the PDK

When using the PDK, each call to it must spin up the PDK. This can be costly as currently every modified .pp file calls the PDK twice, in serial. While the two calls are unavoidable (one for validation, one for linting), we should be able to group all the files into each call to save time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.