Skip to content

Commit

Permalink
Merge pull request #9459 from joshcooper/references_config_12065
Browse files Browse the repository at this point in the history
(PUP-12065) Add task to generate configuration reference
  • Loading branch information
mhashizume authored Aug 29, 2024
2 parents d17d0d8 + c5c7fc8 commit d70f906
Show file tree
Hide file tree
Showing 4 changed files with 2,302 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def self.default_certname
end

def self.hostname_fact
Puppet.runtime[:facter].value 'networking.hostname'
ENV['PUPPET_REFERENCES_HOSTNAME'] || Puppet.runtime[:facter].value('networking.hostname')
end

def self.domain_fact
Puppet.runtime[:facter].value 'networking.domain'
ENV['PUPPET_REFERENCES_DOMAIN'] || Puppet.runtime[:facter].value('networking.domain')
end

def self.default_config_file_name
Expand Down
43 changes: 43 additions & 0 deletions rakelib/generate_references.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'tempfile'

OUTPUT_DIR = 'references'
CONFIGURATION_ERB = File.join(__dir__, 'references/configuration.erb')
CONFIGURATION_MD = File.join(OUTPUT_DIR, 'configuration.md')

def render_erb(erb_file, variables)
# Create a binding so only the variables we specify will be visible
template_binding = OpenStruct.new(variables).instance_eval {binding}
ERB.new(File.read(erb_file), trim_mode: '-').result(template_binding)
end

def puppet_doc(reference)
body = %x{bundle exec puppet doc -r #{reference}}
# Remove the first H1 with the title, like "# Metaparameter Reference"
body.sub!(/^# \w+ Reference *$/, '')
body.chomp
end

# This is adapted from https://github.com/puppetlabs/puppet-docs/blob/1a13be3fc6981baa8a96ff832ab090abc986830e/lib/puppet_references/puppet/puppet_doc.rb#L22-L36
def generate_reference(reference, erb, body, output)
sha = %x{git rev-parse HEAD}.chomp
now = Time.now
variables = {
sha: sha,
now: now,
body: body
}
content = render_erb(erb, variables)
File.write(output, content)
puts "Generated #{output}"
end

namespace :references do
desc "Generate configuration reference"
task :configuration do
ENV['PUPPET_REFERENCES_HOSTNAME'] = "(the system's fully qualified hostname)"
ENV['PUPPET_REFERENCES_DOMAIN'] = "(the system's own domain)"

body = puppet_doc('configuration')
generate_reference('configuration', CONFIGURATION_ERB, body, CONFIGURATION_MD)
end
end
13 changes: 13 additions & 0 deletions rakelib/references/configuration.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
layout: default
built_from_commit: <%= sha %>
title: Configuration Reference
toc: columns
canonical: "/puppet/latest/configuration.html"
---

# Configuration Reference

> **NOTE:** This page was generated from the Puppet source code on <%= now %>

<%= body %>
Loading

0 comments on commit d70f906

Please sign in to comment.