Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDK template sync #550

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions config_defaults.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
---
.pdkignore:
paths:
- '/.fixtures.yml'
- '/.gitattributes'
- '/.gitignore'
- '/.gitlab-ci.yml'
- '/.pdkignore'
- '/.rspec'
- '/.rubocop.yml'
- '/.travis.yml'
- '/.yardopts'
- '/appveyor.yml'
- '/Dockerfile'
- '/Gemfile'
- '/Rakefile'
- '/spec/'
.travis.yml:
docker_sets:
docker_defaults:
Expand Down Expand Up @@ -46,43 +62,46 @@ Gemfile:
- gem: puppet-lint-unquoted_string-check
- gem: puppet-lint-variable_contains_upcase
- gem: puppet-lint-absolute_classname-check
- gem: metadata-json-lint
- gem: redcarpet
- gem: rubocop
version: '~> 0.49.1'
- gem: rubocop-rspec
version: '~> 1.15.0'
- gem: mocha
version: '~> 1.4.0'
- gem: coveralls
- gem: simplecov-console
- gem: parallel_tests

- gem: 'puppet-module-posix-default-r#{minor_version}'
platforms: ruby
- gem: 'puppet-module-posix-dev-r#{minor_version}'
platforms: ruby
- gem: 'puppet-module-win-default-r#{minor_version}'
platforms:
- mswin
- mingw
- x64_mingw
- gem: 'puppet-module-win-dev-r#{minor_version}'
platforms:
- mswin
- mingw
- x64_mingw
':development':
- gem: travis
- gem: travis-lint
- gem: guard-rake
- gem: overcommit
version: '>= 0.39.1'
':system_tests':
- gem: 'puppet-module-posix-system-r#{minor_version}'
platforms: ruby
- gem: 'puppet-module-win-system-r#{minor_version}'
platforms:
- mswin
- mingw
- x64_mingw

- gem: winrm
- gem: beaker-rspec
version: '>= 6'
- gem: serverspec
- gem: beaker-hostgenerator
version: '>= 1.1.22'
- gem: beaker-docker
- gem: beaker-puppet
- gem: beaker-puppet_install_helper
- gem: beaker-module_install_helper
require: false
- gem: rbnacl
version: '>= 4'
- gem: rbnacl-libsodium
- gem: bcrypt_pbkdf
':release':
- gem: github_changelog_generator
git: https://github.com/github-changelog-generator/github-changelog-generator
- gem: puppet-blacksmith
- gem: voxpupuli-release
git: https://github.com/voxpupuli/voxpupuli-release-gem
- gem: puppet-strings
Expand Down Expand Up @@ -130,5 +149,6 @@ spec/acceptance/nodesets/ubuntu-server-1604-x64.yml:
delete: true
spec/spec_helper.rb:
mock_with: ':rspec'
strict_level: ":warning"
...
# vim: syntax=yaml
5 changes: 5 additions & 0 deletions moduleroot/.gitattributes.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.rb eol=lf
*.erb eol=lf
*.pp eol=lf
*.sh eol=lf
*.epp eol=lf
41 changes: 23 additions & 18 deletions moduleroot/.gitignore.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
pkg/
Gemfile.lock
Gemfile.local
vendor/
.vendor/
spec/fixtures/manifests/
spec/fixtures/modules/
.vagrant/
.bundle/
.*.sw[op]
.DS_Store
.git/
.metadata
.ruby-version
coverage/
log/
.idea/
.dependencies/
.librarian/
Puppetfile.lock
.yardoc
.yardwarns
*.iml
.*.sw?
.yardoc/
Guardfile
/.bundle/
/.idea/
/.vagrant/
/bin/
/convert_report.txt
/coverage/
/doc/
/Gemfile.local
/Gemfile.lock
/junit/
/log/
/pkg/
/spec/fixtures/manifests/
/spec/fixtures/modules/
/tmp/
/update_report.txt
/vendor/
<% if ! @configs['paths'].nil? -%>
<% @configs['paths'].each do |path| -%>
<%= path %>
Expand Down
30 changes: 30 additions & 0 deletions moduleroot/.pdkignore.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.*.sw[op]
.DS_Store
.git/
.metadata
.ruby-version
.yardoc
.yardwarns
*.iml
/.bundle/
/.idea/
/.vagrant/
/bin/
/convert_report.txt
/coverage/
/doc/
/Gemfile.local
/Gemfile.lock
/junit/
/log/
/pkg/
/spec/fixtures/manifests/
/spec/fixtures/modules/
/tmp/
/update_report.txt
/vendor/
<% if ! @configs['paths'].nil? -%>
<% @configs['paths'].each do |path| -%>
<%= path %>
<% end -%>
<% end -%>
2 changes: 1 addition & 1 deletion moduleroot/.rspec.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--format documentation
--color
--format documentation
1 change: 0 additions & 1 deletion moduleroot/.yardopts.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--markup markdown
--output-dir docs/
164 changes: 114 additions & 50 deletions moduleroot/Gemfile.erb
Original file line number Diff line number Diff line change
@@ -1,66 +1,130 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

def location_for(place, fake_version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
elsif place =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
<%
def gem_length(gem)
if gem['from_env']
version_len = " *location_for(ENV['#{gem['from_env']}'])".length + ((" || '#{gem['version']}'".length if gem['version']) || 0)
else
[place, { :require => false }]
version_len = (", '#{gem['version']}'".length if gem['version']) || 0
end

gem['gem'].length + version_len
end

<% groups = {} -%>
<% (@configs['required'].keys + ((@configs['optional'] || {}).keys)).uniq.each do |key| -%>
<% groups[key] = (@configs['required'][key] || []) + ((@configs['optional'] || {})[key] || []) -%>
<% end -%>
<% -%>
<% groups.each do |group, gems| -%>
group <%= group %> do
<% maxlen = gems.map! do |gem| -%>
<% gem['platforms'].map!{|a| a.to_sym} unless gem['platforms'].nil? -%>
<% { -%>
<% 'gem' => gem['gem'], -%>
<% 'version' => gem['version'], -%>
<% 'platforms' => gem['platforms'], -%>
<% 'require' => gem['require'], -%>
<% 'git' => gem['git'], -%>
<% 'branch' => gem['branch'], -%>
<% 'ruby-version' => gem['ruby-version'], -%>
<% 'ruby-operator' => gem['ruby-operator'], -%>
<% 'length' => gem['gem'].length + (("', '".length if gem['version']) || 0) + gem['version'].to_s.length -%>
<% } -%>
<% end.map do |gem| -%>
<% gem['length'] -%>
<% end.max -%>
<% gems.each do |gem| -%>
<% if gem['gem'] == 'beaker-rspec' -%>
if beaker_version = ENV['BEAKER_VERSION']
gem 'beaker', *location_for(beaker_version)
else
gem 'beaker', '>= 4.2.0', :require => false
def gem_spec(gem, max_len)
output = "\"#{gem['gem']}\""

if gem['version']
if gem['from_env']
output += ", *location_for(ENV['#{gem['from_env']}'] || '#{gem['version']}')"
else
output += ", '#{gem['version']}'"
end
end

options = []
options << "require: false" if gem['from_env'].nil?
options << "git: '#{gem['git']}'" unless gem['git'].nil?
options << "branch: '#{gem['branch']}'" unless gem['branch'].nil?
options << "ref: '#{gem['ref']}'" unless gem['ref'].nil?
options << "platforms: #{gem['platforms'].inspect}" unless gem['platforms'].nil?

unless options.empty?
output += ', '
output += ' ' * (max_len - gem['length'])

output += options.join(', ')
end
if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
gem 'beaker-rspec', *location_for(beaker_rspec_version)

output += " if #{gem['condition']}" unless gem['condition'].nil?

output
end
-%>
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

def location_for(place_or_version, fake_version = nil)
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
file_url_regex = %r{\Afile:\/\/(?<path>.*)}

if place_or_version && (git_url = place_or_version.match(git_url_regex))
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
else
gem 'beaker-rspec', :require => false
[place_or_version, { require: false }]
end
<% else -%>
gem '<%= gem['gem'] %>'<%= ", '#{gem['version']}'" if gem['version'] %>, <%= ' ' * (maxlen - gem['length']) %> :require => false<%= ", :git => '#{gem['git']}'" if gem['git'] %><%= ", :branch => '#{gem['branch']}'" if gem['branch'] %><%= ", :platforms => #{gem['platforms']}" if gem['platforms'] %><%= " if RUBY_VERSION #{gem['ruby-operator']} '#{gem['ruby-version']}'" if (gem['ruby-operator'] && gem['ruby-version']) %>
<% end -%>
<% end -%>
end

ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
minor_version = ruby_version_segments[0..1].join('.')

<%
groups = {}
(@configs['required'].keys + ((@configs['optional'] || {}).keys)).uniq.each do |key|
groups[key] = (@configs['required'][key] || []) + ((@configs['optional'] || {})[key] || [])
end
-%>
<% groups.each do |group, gems| -%>
group <%= group %> do
<%
gems.map! do |gem|
{
'gem' => gem['gem'],
'version' => gem['version'],
'platforms' => gem['platforms'].nil? ? nil : Array[*gem['platforms']].map(&:to_sym),
'git' => gem['git'],
'branch' => gem['branch'],
'ref' => gem['ref'],
'length' => gem_length(gem),
'from_env' => gem['from_env'],
'condition' => gem['condition'],
}
end

maxlen = gems.map { |r| r['length'] }.max
-%>
<% gems.each do |gem| -%>
gem <%= gem_spec(gem, maxlen) %>
<% end -%>
end
<% end -%>

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion.to_s, :require => false, :groups => [:test]
else
gem 'facter', :require => false, :groups => [:test]
gems = {}

gems['puppet'] = location_for(puppet_version)

# If facter or hiera versions have been specified via the environment
# variables

gems['facter'] = location_for(facter_version) if facter_version
gems['hiera'] = location_for(hiera_version) if hiera_version

if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)}
# If we're using a Puppet gem on Windows which handles its own win32-xxx gem
# dependencies (>= 3.5.0), set the maximum versions (see PUP-6445).
gems['win32-dir'] = ['<= 0.4.9', require: false]
gems['win32-eventlog'] = ['<= 0.6.5', require: false]
gems['win32-process'] = ['<= 0.7.5', require: false]
gems['win32-security'] = ['<= 0.2.5', require: false]
gems['win32-service'] = ['0.8.8', require: false]
end

ENV['PUPPET_VERSION'].nil? ? puppetversion = '<%= @configs['puppet_version'] || '~> 6.0' %>' : puppetversion = ENV['PUPPET_VERSION'].to_s
gem 'puppet', puppetversion, :require => false, :groups => [:test]
gems.each do |gem_name, gem_params|
gem gem_name, *gem_params
end

# Evaluate Gemfile.local and ~/.gemfile if they exist
extra_gemfiles = [
"#{__FILE__}.local",
File.join(Dir.home, '.gemfile'),
]

extra_gemfiles.each do |gemfile|
if File.file?(gemfile) && File.readable?(gemfile)
eval(File.read(gemfile), binding)
end
end
# vim: syntax=ruby
11 changes: 8 additions & 3 deletions moduleroot/Rakefile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ task :reference, [:debug, :backtrace] do |t, args|
Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace])
end

begin
require 'github_changelog_generator/task'
if Bundler.rubygems.find_name('github_changelog_generator').any?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if defined? GitHubChangelogGenerator so you don't rely on bundler?

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
version = (Blacksmith::Modulefile.new).version
config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/
Expand All @@ -83,6 +82,12 @@ begin
metadata = JSON.load(File.read(metadata_json))
config.project = metadata['name']
end
rescue LoadError
else
desc 'Generate a Changelog from GitHub'
task :changelog do
raise <<EOM
The changelog tasks depends on the github_changelog_generator gem.
EOM
end
end
# vim: syntax=ruby
Loading