diff --git a/.travis.yml b/.travis.yml index 927ea8d..dc78f26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,46 +1,71 @@ --- +sudo: false +dist: trusty language: ruby -bundler_args: --without system_tests -install: ["travis_retry ./.travis.sh"] -script: ["bundle exec rake validate", "bundle exec rake lint", "AUGEAS_LENS_LIB=files/lenses bundle exec rake spec SPEC_OPTS='--format documentation'", "bundle exec rake metadata"] +cache: bundler +addons: + apt: + packages: + - libaugeas-dev +before_install: + - rm -f Gemfile.lock +script: + - 'bundle exec rake $CHECK' matrix: fast_finish: true include: - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.0" - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5.0" + bundler_args: --without system_tests development release + env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=12 + - rvm: 2.4.4 + bundler_args: --without system_tests development release + env: PUPPET_VERSION="~> 5.0" CHECK=test + - rvm: 2.5.1 + bundler_args: --without system_tests development release + env: PUPPET_VERSION="~> 5.0" CHECK=test_with_coveralls + - rvm: 2.4.4 + bundler_args: --without system_tests development release + env: PUPPET_VERSION="~> 5.0" CHECK=rubocop + - rvm: 2.5.1 + bundler_args: --without system_tests development release + env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - rvm: 2.4.0 - sudo: required - services: docker - env: BEAKER_set="docker/debian-7" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no bundler_args: + env: BEAKER_set="docker/debian-7" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no script: bundle exec rspec spec/acceptance/*_spec.rb - - rvm: 2.4.0 - sudo: required services: docker - env: BEAKER_set="docker/centos-6" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no + sudo: required + - rvm: 2.4.0 bundler_args: + env: BEAKER_set="docker/centos-6" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no script: bundle exec rspec spec/acceptance/*_spec.rb - - rvm: 2.4.0 - sudo: required services: docker - env: BEAKER_set="docker/centos-7" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no + sudo: required + - rvm: 2.4.0 bundler_args: + env: BEAKER_set="docker/centos-7" PUPPET_INSTALL_TYPE="agent" CHECK="beaker" BEAKER_IS_PE=no script: bundle exec rspec spec/acceptance/*_spec.rb - - rvm: default - sudo: required - dist: trusty services: docker - env: BEAKER_set="centos-6" - bundler_args: - script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb - - rvm: default sudo: required - dist: trusty - services: docker - env: BEAKER_set="centos-7" - bundler_args: - script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb +branches: + only: + - master + - /^v\d/ notifications: email: false + irc: + on_success: always + on_failure: always + channels: + - "chat.freenode.org#voxpupuli-notifications" +deploy: + provider: puppetforge + user: puppet + password: + secure: "etCGQI0hjcKLcm7WcdUONSCh3TWM+SSoqCVMdMsulcVKeAR2CWPSi2nga7TKsDAlKQ2XxXPVYcBpFf+p0gxbAvV4jCFNU96KTtHAMkJbIASYhtHr9Ixk/ToG6hhdywvjAZRS7xvAOwUgWEoA6gA0jJy5nNu+hUZRpvdPreM/DgE=" + on: + tags: true + # all_branches is required to use tags + all_branches: true + # Only publish the build marked with "DEPLOY_TO_FORGE" + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index ac2eff2..1191b70 100644 --- a/Gemfile +++ b/Gemfile @@ -1,51 +1,84 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" -group :development, :unit_tests do - gem 'rake', :require => false - gem 'rspec', :require => false - gem 'rspec-puppet', :require => false - gem 'puppetlabs_spec_helper', :require => false - gem 'metadata-json-lint', :require => false - gem 'puppet-lint', :require => false - gem 'puppet-lint-unquoted_string-check', :require => false - gem 'puppet-lint-empty_string-check', :require => false - gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false - gem 'puppet-lint-absolute_classname-check', :require => false - gem 'puppet-lint-undef_in_function-check', :require => false - gem 'puppet-lint-leading_zero-check', :require => false - gem 'puppet-lint-trailing_comma-check', :require => false - gem 'puppet-lint-file_ensure-check', :require => false - gem 'puppet-lint-version_comparison-check', :require => false - gem 'puppet-lint-file_source_rights-check', :require => false - gem 'puppet-lint-alias-check', :require => false - gem 'rspec-puppet-facts', :require => false - gem 'ruby-augeas', :require => false - gem 'puppet-blacksmith', :require => false if RUBY_VERSION !~ /^1\./ - gem 'json_pure', '< 2.0.2', :require => false +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 }] + else + [place, { :require => false }] + end +end + +group :test do + gem 'puppetlabs_spec_helper', '~> 2.6', :require => false + gem 'rspec-puppet', '~> 2.5', :require => false + gem 'rspec-puppet-facts', :require => false + gem 'rspec-puppet-utils', :require => false + gem 'puppet-lint-leading_zero-check', :require => false + gem 'puppet-lint-trailing_comma-check', :require => false + gem 'puppet-lint-version_comparison-check', :require => false + gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false + gem 'puppet-lint-unquoted_string-check', :require => false + gem 'puppet-lint-variable_contains_upcase', :require => false + gem 'metadata-json-lint', :require => false + gem 'redcarpet', :require => false + gem 'rubocop', '~> 0.49.1', :require => false if RUBY_VERSION >= '2.3.0' + gem 'rubocop-rspec', '~> 1.15.0', :require => false if RUBY_VERSION >= '2.3.0' + gem 'mocha', '~> 1.4.0', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2' + gem 'parallel_tests', :require => false + gem 'ruby-augeas', :require => false +end + +group :development do + gem 'travis', :require => false + gem 'travis-lint', :require => false + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do - gem 'beaker', '~>3.13', :require => false - gem 'beaker-rspec', '> 5', :require => false - gem 'beaker_spec_helper', :require => false - gem 'serverspec', :require => false - gem 'specinfra', :require => false + gem 'winrm', :require => false + if beaker_version = ENV['BEAKER_VERSION'] + gem 'beaker', *location_for(beaker_version) + else + gem 'beaker', '>= 3.9.0', :require => false + end + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false + gem 'beaker-hostgenerator', '>= 1.1.10', :require => false + gem 'beaker-docker', :require => false + gem 'beaker-puppet', :require => false + gem 'beaker-puppet_install_helper', :require => false + gem 'beaker-module_install_helper', :require => false + gem 'rbnacl', '>= 4', :require => false if RUBY_VERSION >= '2.2.6' + gem 'rbnacl-libsodium', :require => false if RUBY_VERSION >= '2.2.6' + gem 'bcrypt_pbkdf', :require => false end -group :test do - gem 'ruby-augeas', :require => false +group :release do + gem 'github_changelog_generator', :require => false, :git => 'https://github.com/skywinder/github-changelog-generator' if RUBY_VERSION >= '2.2.2' + gem 'puppet-blacksmith', :require => false + gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem' + gem 'puppet-strings', '>= 1.0', :require => false end + + if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion, :require => false + gem 'facter', facterversion.to_s, :require => false, :groups => [:test] else - gem 'facter', :require => false + gem 'facter', :require => false, :groups => [:test] end -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false -else - gem 'puppet', :require => false -end +ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 5.0' : puppetversion = ENV['PUPPET_VERSION'].to_s +gem 'puppet', puppetversion, :require => false, :groups => [:test] -# vim:ft=ruby +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index aa7b8a1..279580a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,17 +1,92 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' -Rake::Task[:lint].clear -PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] - config.disable_checks = ['140chars'] - config.fail_on_warnings = true +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'puppet_blacksmith/rake_tasks' + require 'voxpupuli/release/rake_tasks' + require 'puppet-strings/tasks' +rescue LoadError end -PuppetSyntax.exclude_paths = ["spec/fixtures/**/*.pp", "vendor/**/*"] +PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('relative') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') -# Publishing tasks -unless RUBY_VERSION =~ /^1\./ - require 'puppet_blacksmith' - require 'puppet_blacksmith/rake_tasks' +exclude_paths = %w( + pkg/**/* + vendor/**/* + .vendor/**/* + spec/**/* +) +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +desc 'Auto-correct puppet-lint offenses' +task 'lint:auto_correct' do + PuppetLint.configuration.fix = true + Rake::Task[:lint].invoke +end + +desc 'Run acceptance tests' +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' +end + +desc 'Run tests metadata_lint, release_checks' +task test: [ + :metadata_lint, + :release_checks, +] + +desc "Run main 'test' task and report merged results to coveralls" +task test_with_coveralls: [:test] do + if Dir.exist?(File.expand_path('../lib', __FILE__)) + require 'coveralls/rake/task' + Coveralls::RakeTask.new + Rake::Task['coveralls:push'].invoke + else + puts 'Skipping reporting to coveralls. Module has no lib dir' + end +end + +desc "Print supported beaker sets" +task 'beaker_sets', [:directory] do |t, args| + directory = args[:directory] + + metadata = JSON.load(File.read('metadata.json')) + + (metadata['operatingsystem_support'] || []).each do |os| + (os['operatingsystemrelease'] || []).each do |release| + if directory + beaker_set = "#{directory}/#{os['operatingsystem'].downcase}-#{release}" + else + beaker_set = "#{os['operatingsystem'].downcase}-#{release}-x64" + end + + filename = "spec/acceptance/nodesets/#{beaker_set}.yml" + + puts beaker_set if File.exists? filename + end + end +end + +begin + require 'github_changelog_generator/task' + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + version = (Blacksmith::Modulefile.new).version + config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ + config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} + config.user = 'voxpupuli' + metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') + metadata = JSON.load(File.read(metadata_json)) + config.project = metadata['name'] + end +rescue LoadError end +# vim: syntax=ruby diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3a7471..58590eb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,46 +2,46 @@ require 'rspec-puppet-facts' include RspecPuppetFacts +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config + # Setup augeasproviders require 'pathname' dir = Pathname.new(__FILE__).parent $LOAD_PATH.unshift(dir, File.join(dir, 'fixtures/modules/augeasproviders_core/spec/lib'), File.join(dir, '..', 'lib')) require 'augeas_spec' - -RSpec.configure do |c| - c.include PuppetlabsSpec::Files - - c.before :each do - # Store any environment variables away to be restored later - @old_env = {} - ENV.each_key {|k| @old_env[k] = ENV[k]} - - c.strict_variables = Gem::Version.new(Puppet.version) >= Gem::Version.new('3.5') - Puppet.features.stubs(:root?).returns(true) - end - - c.after :each do - PuppetlabsSpec::Files.cleanup - end -end - require 'pathname' dir = Pathname.new(__FILE__).parent Puppet[:modulepath] = File.join(dir, 'fixtures', 'modules') +puts 'augeasproviders: setting Puppet[:libdir] to work around broken type autoloading' +# libdir is only a single dir, so it can only workaround loading of one external module +Puppet[:libdir] = "#{Puppet[:modulepath]}/augeasproviders_core/lib" -# There's no real need to make this version dependent, but it helps find -# regressions in Puppet -# -# 1. Workaround for issue #16277 where default settings aren't initialised from -# a spec and so the libdir is never initialised (3.0.x) -# 2. Workaround for 2.7.20 that now only loads types for the current node -# environment (#13858) so Puppet[:modulepath] seems to get ignored -# 3. Workaround for 3.5 where context hasn't been configured yet, -# ticket https://tickets.puppetlabs.com/browse/MODULES-823 -# -ver = Gem::Version.new(Puppet.version.split('-').first) -if Gem::Requirement.new("~> 2.7.20") =~ ver || Gem::Requirement.new("~> 3.0.0") =~ ver || Gem::Requirement.new("~> 3.5") =~ ver || Gem::Requirement.new("~> 4.0") - puts "augeasproviders: setting Puppet[:libdir] to work around broken type autoloading" - # libdir is only a single dir, so it can only workaround loading of one external module - Puppet[:libdir] = "#{Puppet[:modulepath]}/augeasproviders_core/lib" +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| + default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version + } + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__)) + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__)) + c.default_facts = default_facts +end + +# vim: syntax=ruby