Skip to content

Commit 41d2077

Browse files
committed
feat: Setting up a hook to manage puppet documentation
This hook manage documentation with the puppet string command Signed-off-by: julien.girard <[email protected]>
1 parent 8106e1d commit 41d2077

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.pre-commit-hooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
language: ruby
4646
name: Validate Puppet manifests
4747

48+
- id: puppet-strings
49+
additional_dependencies: ['puppet-strings']
50+
description: Validate puppet documentation is up to date
51+
entry: puppet-strings
52+
files: \.pp$
53+
language: ruby
54+
name: Validate puppet documentation
55+
4856
- id: r10k-validate
4957
additional_dependencies: ['r10k']
5058
description: Validate syntax of Puppetfile using r10k

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Provides the following hooks:
2020
* **puppet-validate:** uses [`puppet parser validate`][puppet-parser] to check the syntax of
2121
Puppet manifests.
2222

23+
* **puppet-strings:** uses [`puppet strings generate`][puppet-strings] to check the puppet documentation
24+
2325
* **r10k-validate:** uses [r10k][r10k] to validate [Puppetfile][puppetfile] syntax.
2426

2527
* **ruby-validate:** uses [`ruby -c`][ruby-c] to validate the syntax of ruby code.
@@ -30,6 +32,7 @@ Provides the following hooks:
3032
[g10k]: https://github.com/xorpaul/g10k
3133
[puppetfile]: https://puppet.com/docs/pe/latest/puppetfile.html
3234
[puppet-parser]: https://puppet.com/docs/puppet/latest/man/parser.html#EXAMPLES
35+
[puppet-strings]: https://puppet.com/docs/puppet/7/puppet_strings.html
3336
[r10k]: https://github.com/puppetlabs/r10k
3437
[rubocop]: https://github.com/rubocop-hq/rubocop
3538
[ruby-c]: https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/options.html
@@ -93,6 +96,9 @@ Provides the following hooks:
9396
Any other arguments to `puppet-validate` will be fed directly to
9497
`puppet parser validate`, as long as they are in the format `--arg=value`.
9598

99+
Any other arguments to `puppet-strings` will be fed directly to
100+
`puppet strings generate`.
101+
96102
By default, the latest versions of `puppet` and `puppet-lint` are used. If
97103
you'd like to use a different version, you can pass `additional_dependencies`
98104
when definining the hooks.

pre_commit_fake_gem.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Gem::Specification.new do |s|
66
s.description = 'pre-commit hooks for Puppet projects'
77

88
s.bindir = 'ruby-stubs'
9-
s.executables = ['bolt-validate', 'erb-validate', 'epp-validate', 'g10k-validate', 'puppet-validate', 'r10k-validate', 'ruby-validate']
9+
s.executables = ['bolt-validate', 'erb-validate', 'epp-validate', 'g10k-validate', 'puppet-validate', 'puppet-strings', 'r10k-validate', 'ruby-validate']
1010
end

ruby-stubs/puppet-strings

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'English'
2+
3+
status = 0
4+
options = []
5+
ARGV.each do |arg|
6+
# The following command will execute puppet strings to generate documentation
7+
# As puppet strings does not return a non-zero rc when file changes
8+
# We need to manually check it with a git command.
9+
# The second part of the command will output the number of modified files
10+
# outside the git stage zone for the doc folder (output folder of the
11+
# puppet strings command).
12+
output = `puppet strings generate -- "#{arg}" 2>&1 && exit $(git status --porcelain doc | grep -v '^A' | wc -l)`
13+
next if $CHILD_STATUS.exitstatus == 0
14+
puts "#{arg}: failed Puppet validation"
15+
puts output
16+
status = 1
17+
end
18+
19+
exit status
20+
21+
# vim: ft=ruby

0 commit comments

Comments
 (0)