diff --git a/config_defaults.yml b/config_defaults.yml index afcb7b85..cd189b7a 100644 --- a/config_defaults.yml +++ b/config_defaults.yml @@ -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: @@ -46,17 +62,23 @@ 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 @@ -64,17 +86,15 @@ Gemfile: - 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 @@ -82,7 +102,6 @@ Gemfile: ':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 @@ -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 diff --git a/moduleroot/.gitattributes.erb b/moduleroot/.gitattributes.erb new file mode 100644 index 00000000..9032a014 --- /dev/null +++ b/moduleroot/.gitattributes.erb @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/moduleroot/.gitignore.erb b/moduleroot/.gitignore.erb index 07a30766..b2c4a757 100644 --- a/moduleroot/.gitignore.erb +++ b/moduleroot/.gitignore.erb @@ -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 %> diff --git a/moduleroot/.pdkignore.erb b/moduleroot/.pdkignore.erb new file mode 100644 index 00000000..b2c4a757 --- /dev/null +++ b/moduleroot/.pdkignore.erb @@ -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 -%> diff --git a/moduleroot/.rspec.erb b/moduleroot/.rspec.erb index 8c18f1ab..16f9cdb0 100644 --- a/moduleroot/.rspec.erb +++ b/moduleroot/.rspec.erb @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/moduleroot/.yardopts.erb b/moduleroot/.yardopts.erb index 3687f518..29c933bc 100644 --- a/moduleroot/.yardopts.erb +++ b/moduleroot/.yardopts.erb @@ -1,2 +1 @@ --markup markdown ---output-dir docs/ diff --git a/moduleroot/Gemfile.erb b/moduleroot/Gemfile.erb index bc0978f0..bba7f441 100644 --- a/moduleroot/Gemfile.erb +++ b/moduleroot/Gemfile.erb @@ -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(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + 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 diff --git a/moduleroot/Rakefile.erb b/moduleroot/Rakefile.erb index 297a3872..8cb1091b 100644 --- a/moduleroot/Rakefile.erb +++ b/moduleroot/Rakefile.erb @@ -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? GitHubChangelogGenerator::RakeTask.new :changelog do |config| version = (Blacksmith::Modulefile.new).version config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ @@ -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 < -if Dir.exist?(File.expand_path('../../lib', __FILE__)) - require 'coveralls' - require 'simplecov' - require 'simplecov-console' - SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ] - SimpleCov.start do - track_files 'lib/**/*.rb' - add_filter '/spec' - add_filter '/vendor' - add_filter '/.vendor' - end -end - RSpec.configure do |c| <%- if @configs['hiera_config'] -%> c.hiera_config = <%= @configs['hiera_config'] %> - <%- end -%> - # Coverage generation + <%- if @configs['strict_level'] -%> + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = <%= @configs['strict_level'] %> + end + <%- end -%> + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do RSpec::Puppet::Coverage.report! end end -<%- [@configs['spec_overrides']].flatten.compact.each do |line| -%> +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +<%- [@configs['spec_overrides']].flatten.compact.each do |line| -%> <%= line %> <%- end -%>