diff --git a/.fixtures.yml b/.fixtures.yml index 564391d..058852f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,3 +3,6 @@ fixtures: stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" symlinks: pe_backup: "#{source_dir}" + forge_modules: + cron: 'puppetlabs-cron_core' + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index 4644eed..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,27 @@ -.*.sw? -/pkg -/spec/fixtures/manifests -/spec/fixtures/modules -/.rspec_system -/.vagrant -/.bundle -/vendor -/Gemfile.lock -/junit -/log +.git/ +.*.sw[op] +.metadata .yardoc -coverage -.rake_tasks~ +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..81e6d76 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,41 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.3-Puppet ~> 6: + stage: syntax + image: ruby:2.5.3 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.5.3-Puppet ~> 6: + stage: unit + image: ruby:2.5.3 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.4.5-Puppet ~> 5: + stage: unit + image: ruby:2.4.5 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..e6215cd --- /dev/null +++ b/.pdkignore @@ -0,0 +1,42 @@ +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/rakelib/ +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ +/.vscode/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..cc96ece --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.rspec b/.rspec index 8c18f1a..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml index 81e97cd..3cd2b0e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,486 +1,126 @@ +--- +require: +- rubocop-rspec +- rubocop-i18n AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" Exclude: - # Ignore HTML related things - - '**/*.erb' - # Ignore vendored gems - - 'vendor/**/*' - # Ignore code from test fixtures - - 'spec/fixtures/**/*' - -Lint/ConditionPosition: - Enabled: true - -Lint/ElseLayout: - Enabled: true - -Lint/UnreachableCode: - Enabled: true - -Lint/UselessComparison: - Enabled: true - -Lint/EnsureReturn: - Enabled: true - -Lint/HandleExceptions: - Enabled: true - -Lint/LiteralInCondition: - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Enabled: true - -Lint/LiteralInInterpolation: - Enabled: true - -Style/RedundantReturn: - Enabled: true - -Lint/AmbiguousOperator: - Enabled: true - -Lint/AssignmentInCondition: - Enabled: true - -Style/SpaceBeforeComment: - Enabled: true - -# DISABLED - not useful -Style/HashSyntax: - Enabled: false - -# USES: as shortcut for non nil&valid checking a = x() and a.empty? -# DISABLED - not useful -Style/AndOr: - Enabled: false - -# DISABLED - not useful -Style/RedundantSelf: - Enabled: false - -# DISABLED - not useful -Metrics/MethodLength: - Enabled: false - -# DISABLED - not useful -Style/WhileUntilModifier: - Enabled: false - -# DISABLED - the offender is just haskell envy -Lint/AmbiguousRegexpLiteral: - Enabled: false - -# DISABLED -Security/Eval: - Enabled: false - -# DISABLED -Lint/BlockAlignment: - Enabled: false - -# DISABLED -Lint/DefEndAlignment: - Enabled: false - -# DISABLED -Lint/EndAlignment: - Enabled: false - -# DISABLED -Lint/DeprecatedClassMethods: - Enabled: false - -# DISABLED -Lint/Loop: - Enabled: false - -# DISABLED -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -Lint/RescueException: - Enabled: false - -Lint/StringConversionInInterpolation: - Enabled: false - -Lint/UnusedBlockArgument: - Enabled: false - -Lint/UnusedMethodArgument: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +GetText: Enabled: false - -Lint/UselessAccessModifier: +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/**/* +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: Enabled: true - -Lint/UselessAssignment: +Style/MethodCalledOnDoEndBlock: Enabled: true - -Lint/Void: +Style/StringMethods: Enabled: true - -Style/AccessModifierIndentation: - Enabled: false - -Style/AccessorMethodName: - Enabled: false - -Style/Alias: - Enabled: false - -Style/AlignArray: - Enabled: false - -Style/AlignHash: - Enabled: false - -Style/AlignParameters: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Style/AsciiComments: - Enabled: false - -Style/Attr: - Enabled: false - -Style/BracesAroundHashParameters: - Enabled: false - -Style/CaseEquality: - Enabled: false - -Style/CaseIndentation: +Layout/EndOfLine: Enabled: false - -Style/CharacterLiteral: +Layout/IndentHeredoc: Enabled: false - -Style/ClassAndModuleCamelCase: +Metrics/AbcSize: Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/ClassCheck: +Metrics/BlockLength: Enabled: false - Metrics/ClassLength: Enabled: false - -Style/ClassMethods: - Enabled: false - -Style/ClassVars: - Enabled: false - -Style/WhenThen: - Enabled: false - -# DISABLED - not useful -Style/WordArray: - Enabled: false - -Style/UnneededPercentQ: - Enabled: false - -Style/Tab: - Enabled: false - -Style/SpaceBeforeSemicolon: - Enabled: false - -Style/TrailingBlankLines: - Enabled: false - -Style/SpaceInsideBlockBraces: - Enabled: false - -Style/SpaceInsideBrackets: - Enabled: false - -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -Style/SpaceInsideParens: - Enabled: false - -Style/LeadingCommentSpace: - Enabled: false - -Style/SpaceBeforeFirstArg: - Enabled: false - -Style/SpaceAfterColon: - Enabled: false - -Style/SpaceAfterComma: - Enabled: false - -Style/SpaceAroundKeyword: - Enabled: false - -Style/SpaceAfterMethodName: - Enabled: false - -Style/SpaceAfterNot: - Enabled: false - -Style/SpaceAfterSemicolon: - Enabled: false - -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - -Style/SpaceAroundOperators: - Enabled: false - -Style/SpaceBeforeBlockBraces: - Enabled: false - -Style/SpaceBeforeComma: - Enabled: false - -Style/CollectionMethods: - Enabled: false - -Style/CommentIndentation: - Enabled: false - -Style/ColonMethodCall: - Enabled: false - -Style/CommentAnnotation: - Enabled: false - Metrics/CyclomaticComplexity: Enabled: false - -Style/ConstantName: - Enabled: false - -Style/Documentation: - Enabled: false - -Style/DefWithParentheses: - Enabled: false - -Style/DotPosition: - Enabled: false - -# DISABLED - used for converting to bool -Style/DoubleNegation: - Enabled: false - -Style/EachWithObject: - Enabled: false - -Style/EmptyLineBetweenDefs: - Enabled: false - -Style/IndentArray: - Enabled: false - -Style/IndentHash: - Enabled: false - -Style/IndentationConsistency: - Enabled: false - -Style/IndentationWidth: - Enabled: false - -Style/EmptyLines: - Enabled: false - -Style/EmptyLinesAroundAccessModifier: - Enabled: false - -Style/EmptyLiteral: - Enabled: false - -Metrics/LineLength: +Metrics/MethodLength: Enabled: false - -Style/MethodCallWithoutArgsParentheses: +Metrics/ModuleLength: Enabled: false - -Style/MethodDefParentheses: +Metrics/ParameterLists: Enabled: false - -Style/LineEndConcatenation: +Metrics/PerceivedComplexity: Enabled: false - -Style/TrailingWhitespace: +RSpec/DescribeClass: Enabled: false - -Style/StringLiterals: +RSpec/ExampleLength: Enabled: false - -Style/TrailingCommaInLiteral: +RSpec/MessageExpectation: Enabled: false - -Style/TrailingCommaInArguments: +RSpec/MultipleExpectations: Enabled: false - -Style/GlobalVars: +RSpec/NestedGroups: Enabled: false - -Style/GuardClause: +Style/AsciiComments: Enabled: false - Style/IfUnlessModifier: Enabled: false - -Style/MultilineIfThen: - Enabled: false - -Style/NegatedIf: - Enabled: false - -Style/NegatedWhile: - Enabled: false - -Style/Next: - Enabled: false - -Style/SingleLineBlockParams: - Enabled: false - -Style/SingleLineMethods: - Enabled: false - -Style/SpecialGlobalVars: - Enabled: false - -Style/TrivialAccessors: - Enabled: false - -Style/UnlessElse: - Enabled: false - -Style/VariableInterpolation: - Enabled: false - -Style/VariableName: - Enabled: false - -Style/WhileUntilDo: - Enabled: false - -Style/EvenOdd: - Enabled: false - -Style/FileName: - Enabled: false - -Style/For: - Enabled: false - -Style/Lambda: - Enabled: false - -Style/MethodName: - Enabled: false - -Style/MultilineTernaryOperator: - Enabled: false - -Style/NestedTernaryOperator: - Enabled: false - -Style/NilComparison: - Enabled: false - -Style/FormatString: - Enabled: false - -Style/MultilineBlockChain: - Enabled: false - -Style/Semicolon: - Enabled: false - -Style/SignalException: - Enabled: false - -Style/NonNilCheck: - Enabled: false - -Style/Not: - Enabled: false - -Style/NumericLiterals: - Enabled: false - -Style/OneLineConditional: - Enabled: false - -Style/OpMethod: - Enabled: false - -Style/ParenthesesAroundCondition: - Enabled: false - -Style/PercentLiteralDelimiters: - Enabled: false - -Style/PerlBackrefs: - Enabled: false - -Style/PredicateName: - Enabled: false - -Style/RedundantException: - Enabled: false - -Style/SelfAssignment: - Enabled: false - -Style/Proc: - Enabled: false - -Style/RaiseArgs: - Enabled: false - -Style/RedundantBegin: - Enabled: false - -Style/RescueModifier: - Enabled: false - -Style/RegexpLiteral: - Enabled: false - -Lint/UnderscorePrefixedVariableName: - Enabled: false - -Metrics/ParameterLists: - Enabled: false - -Lint/RequireParentheses: - Enabled: false - -Style/SpaceBeforeFirstArg: - Enabled: false - -Style/ModuleFunction: - Enabled: false - -Lint/Debugger: - Enabled: false - -Style/IfWithSemicolon: - Enabled: false - -Style/Encoding: - Enabled: false - -Style/SymbolArray: +Style/SymbolProc: Enabled: false - -Style/ExtraSpacing: - Enabled: false diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..d5a70de --- /dev/null +++ b/.sync.yml @@ -0,0 +1,3 @@ +--- +spec/spec_helper.rb: + coverage_report: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index cbacae5..ed27d4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,41 +1,45 @@ --- -sudo: false -cache: bundler +dist: xenial language: ruby -bundler_args: --without development system_tests -before_install: rm Gemfile.lock || true +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests rvm: - - 2.1 -# - 2.2 -# - 2.3 -script: bundle exec rake test -env: - - PUPPET_GEM_VERSION="~> 4.4.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" - - PUPPET_GEM_VERSION="~> 4.5.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" - - PUPPET_GEM_VERSION="~> 4.6.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" - - PUPPET_GEM_VERSION="~> 4.7.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" - - PUPPET_GEM_VERSION="~> 4.8.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" - - PUPPET_GEM_VERSION="~> 4.9.0" STRICT_VARIABLES=yes FACTER_GEM_VERSION="~> 2.4.0" -#matrix: -# exclude: -# Ruby 1.9.3 -# - rvm: 1.9.3 -# env: PUPPET_GEM_VERSION="~> 2.7.0" -# -# # Ruby 2.0.0 -# - rvm: 2.0.0 -# env: PUPPET_GEM_VERSION="~> 2.7.0" -# -# # Ruby 2.1 -# - rvm: 2.1 -# env: PUPPET_GEM_VERSION="~> 2.7.0" -# - rvm: 2.1 -# env: PUPPET_GEM_VERSION="~> 3.2.0" -# - rvm: 2.1 -# env: PUPPET_GEM_VERSION="~> 3.3.0" -# - rvm: 2.1 -# env: PUPPET_GEM_VERSION="~> 3.4.0" -addons: - code_climate: - repo_token: - secure: c3pOGEDtUztGKBXzbbm/j8Jox6bAzWAZ0dSLlQ76KyFapa3ME3rawx+WASH65l/LrwYVvkvl2sMA1fj+yvK4FHQY22bsU709/lG0g9RQ2G96cFfVE+KtyPVfSvWtI9wUZPA+VKp3D1XXtOnoJoyuU/4vvndeiPHcvHSOoPwKFCaUGZEATQ6O6pGbwjBSgyG9ZG84B1NG/G6fRWszm5P4RykGuPas8jgdM1la/c3ZoZbmgxgWqjlQ0AbHuN0HVWQmfqhPsO2Kv7L6wP/AznYYXX2N55uLxzvBbfnvLkWznbV79JghgKSUykRAl9y3H25BW2Ya+K77Mor5sEKTU5yN4zD0odPuPhoKyfTCneX7PoM1emU+WtpCsxS/lXwMKaZzP3AlmyyhWazBqa8bKyqFA4CoBATf5/NFRMa8nI/BH4yYVi3yx53vGvv71j3nAs+XmI/lLGmiR2vXt0FJg8XyZ/73EcjwkxZAkuNh+22q1PkeO9fDKcSE3JFSHoJ5Isu+UrwEzfA0RDTCaUsGLgRWKWxj7GHeVUhpPmFHhCgRfYy9CWgWMBq7E7PRo/dXEUIrJcqhCtkM8hXM3+bxbokfc+HAPFWEFfekSy+lATRL59KcYDDgsMNUmMygnkAkMqYdD4SxH/GDXPw6WX8rYNo/OF+Wyaoc4gpeNtVvQ5viWJM= + - 2.5.3 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy +matrix: + fast_finish: true + include: + - + env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + stage: static + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.5 + stage: spec + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.3 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy +branches: + only: + - master + - /^v\d/ +notifications: + email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..6177782 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "jpogran.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/Gemfile b/Gemfile index 6102f4e..0e6b530 100644 --- a/Gemfile +++ b/Gemfile @@ -1,36 +1,71 @@ -source ENV['GEM_SOURCE'] || "https://rubygems.org" - -group :test do - gem 'facter', '~> 2.4.0' - gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0' - gem "metadata-json-lint" - gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 4.9.0' - gem "puppet-lint-absolute_classname-check" - gem "puppet-lint-classes_and_types_beginning_with_digits-check" - gem "puppet-lint-leading_zero-check" - gem 'puppet-lint-resource_reference_syntax' - gem "puppet-lint-trailing_comma-check" - gem "puppet-lint-unquoted_string-check" - gem "puppet-lint-version_comparison-check" - gem "puppetlabs_spec_helper" - gem "rake", '< 11.0' - gem "rspec", '< 3.2.0' - gem "rspec-puppet" - gem "rspec-puppet-facts" - gem 'rubocop', '0.48.1' - gem 'simplecov', '>= 0.11.0' - gem 'simplecov-console' +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 + [place_or_version, { require: false }] + end end +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + group :development do - gem "guard-rake" if RUBY_VERSION >= '2.2.5' # per dependency https://rubygems.org/gems/ruby_dep - gem "puppet-blacksmith" - gem "travis" if RUBY_VERSION >= '2.1.0' - gem "travis-lint" if RUBY_VERSION >= '2.1.0' + gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') + gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem "beaker" - gem "beaker-puppet_install_helper" - gem "beaker-rspec" +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +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 + +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/Rakefile b/Rakefile index 3a881bf..d9b223c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,64 +1,77 @@ -require 'rubygems' -require 'bundler/setup' - +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet/version' -require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' -require 'metadata-json-lint/rake_task' -require 'rubocop/rake_task' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -if Puppet.version.to_f >= 4.9 - require 'semantic_puppet' -elsif Puppet.version.to_f >= 3.6 && Puppet.version.to_f < 4.9 - require 'puppet/vendor/semantic/lib/semantic' +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator user:#{returnVal}" + returnVal end -# These gems aren't always present, for instance -# on Travis with --without development -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError # rubocop:disable Lint/HandleExceptions +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['source'].match(%r{.*/([^/]*)})[1] + raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal end -RuboCop::RakeTask.new - -exclude_paths = [ - "bundle/**/*", - "pkg/**/*", - "vendor/**/*", - "spec/**/*", -] - -Rake::Task[:lint].clear - -PuppetLint.configuration.relative = true -PuppetLint.configuration.disable_80chars -PuppetLint.configuration.disable_class_inherits_from_params_class -PuppetLint.configuration.disable_class_parameter_defaults -PuppetLint.configuration.fail_on_warnings = true - -PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = exclude_paths +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal end -PuppetSyntax.exclude_paths = exclude_paths - -desc "Run acceptance tests" -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' -end +PuppetLint.configuration.send('disable_relative') -desc "Populate CONTRIBUTORS file" -task :contributors do - system("git log --format='%aN' | sort -u > CONTRIBUTORS") +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? + config.user = "#{changelog_user}" + config.project = "#{changelog_project}" + config.future_release = "#{changelog_future_release}" + config.exclude_labels = ['maintenance'] + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." + config.add_pr_wo_labels = true + config.issues = false + config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end end -desc "Run syntax, lint, and spec tests." -task :test => [ - :metadata_lint, - :syntax, - :lint, - :rubocop, - :spec, -] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ec38949 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,56 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master + - release +skip_commits: + message: /^\(?doc\)?.*/ +clone_depth: 10 +init: + - SET + - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' +environment: + matrix: + - + RUBY_VERSION: 24-x64 + CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24-x64 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25-x64 + CHECK: parallel_spec +matrix: + fast_finish: true +install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 --without system_tests + - type Gemfile.lock +build: off +test_script: + - bundle exec puppet -V + - ruby -v + - gem -v + - bundle -v + - bundle exec rake %CHECK% +notifications: + - provider: Email + to: + - nobody@nowhere.com + on_build_success: false + on_build_failure: false + on_build_status_changed: false diff --git a/manifests/init.pp b/manifests/init.pp index bc1b3c4..0b19008 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,43 +12,24 @@ # class pe_backup ( Stdlib::Absolutepath $destination, - String $user = $::pe_backup::params::user, - String $group = $::pe_backup::params::group, - String $umask = $::pe_backup::params::umask, - String $prefix = $::pe_backup::params::prefix, - Stdlib::Absolutepath $script = $::pe_backup::params::script, - String $hour = $::pe_backup::params::hour, - String $minute = $::pe_backup::params::minute, - String $weekday = $::pe_backup::params::weekday, - Array $dirs_common = $::pe_backup::params::dirs_common, - Array $dirs_master = $::pe_backup::params::dirs_master, - Array $dirs_db = $::pe_backup::params::dirs_db, - Array $dirs_console = $::pe_backup::params::dirs_console, - Array $dirs_extra = $::pe_backup::params::dirs_extra, - Enum['monolithic','master','db','console'] $nodetype = $::pe_backup::params::nodetype, -) inherits ::pe_backup::params { + String $user = $::pe_backup::params::user, + String $group = $::pe_backup::params::group, + String $umask = $::pe_backup::params::umask, + String $prefix = $::pe_backup::params::prefix, + Stdlib::Absolutepath $script = $::pe_backup::params::script, + String $hour = $::pe_backup::params::hour, + String $minute = $::pe_backup::params::minute, + String $weekday = $::pe_backup::params::weekday, + Array $dirs_common = $::pe_backup::params::dirs_common, + Array $dirs_master = $::pe_backup::params::dirs_master, + Array $dirs_db = $::pe_backup::params::dirs_db, + Array $dirs_console = $::pe_backup::params::dirs_console, + Array $dirs_extra = $::pe_backup::params::dirs_extra, + Enum['monolithic','master','db','console'] $nodetype = $::pe_backup::params::nodetype, +) inherits pe_backup::params { - case $nodetype { - 'monolithic': { - $dir_list = $dirs_common + $dirs_master + $dirs_db + $dirs_console + $dirs_extra - } - 'master': { - $dir_list = $dirs_common + $dirs_master + $dirs_extra - } - 'db': { - $dir_list = $dirs_common + $dirs_db + $dirs_extra - } - 'console': { - $dir_list = $dirs_common + $dirs_console + $dirs_extra - } - default: { - # We should never reach this point, but... - fail("Invalid node type: ${nodetype}") - } - } + contain pe_backup::install + contain pe_backup::service - contain ::pe_backup::install - contain ::pe_backup::service - - Class['::pe_backup::install'] -> Class['::pe_backup::service'] + Class['pe_backup::install'] -> Class['pe_backup::service'] } diff --git a/manifests/install.pp b/manifests/install.pp index d1dba09..0c00288 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -3,13 +3,41 @@ # This class is called from pe_backup for install. # class pe_backup::install { - $script = $::pe_backup::script + $destination = $::pe_backup::destination + $dirs_common = $::pe_backup::dirs_common + $dirs_console = $::pe_backup::dirs_console + $dirs_db = $::pe_backup::dirs_db + $dirs_extra = $::pe_backup::dirs_extra + $dirs_master = $::pe_backup::dirs_master + $nodetype = $::pe_backup::nodetype + $prefix = $::pe_backup::prefix + $script = $::pe_backup::script + $umask = $::pe_backup::umask + + case $nodetype { + 'monolithic': { + $dir_list = $dirs_common + $dirs_master + $dirs_db + $dirs_console + $dirs_extra + } + 'master': { + $dir_list = $dirs_common + $dirs_master + $dirs_extra + } + 'db': { + $dir_list = $dirs_common + $dirs_db + $dirs_extra + } + 'console': { + $dir_list = $dirs_common + $dirs_console + $dirs_extra + } + default: { + # We should never reach this point, but... + fail("Invalid node type: ${nodetype}") + } + } $template_params = { - 'destination' => $::pe_backup::destination, - 'dir_list' => $::pe_backup::dir_list, - 'prefix' => $::pe_backup::prefix, - 'umask' => $::pe_backup::umask, + 'destination' => $destination, + 'dir_list' => $dir_list, + 'prefix' => $prefix, + 'umask' => $umask, } file { $script: @@ -19,5 +47,4 @@ mode => '0750', content => epp("${module_name}/pe_backup.sh.epp", $template_params), } - } diff --git a/metadata.json b/metadata.json index 4e1c2ad..2d89126 100644 --- a/metadata.json +++ b/metadata.json @@ -7,12 +7,6 @@ "source": "https://github.com/fvoges/puppet-pe_backup.git", "project_page": "https://github.com/fvoges/puppet-pe_backup", "issues_url": "https://github.com/fvoges/puppet-pe_backup/issues", - "requirements": [ - { - "name": "puppet", - "version_requirement": ">= 4.4.0 < 5.0.0" - } - ], "dependencies": [ { "name": "puppetlabs-stdlib", @@ -49,5 +43,14 @@ "12" ] } - ] + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.4.0 < 5.0.0" + } + ], + "pdk-version": "1.11.1", + "template-url": "pdk-default#1.11.1", + "template-ref": "1.11.1-0-g2ff8c24" } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 937bcde..1985c46 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -3,14 +3,14 @@ describe 'pe_backup class' do context 'default parameters' do # Using puppet_apply as a helper - it 'should work idempotently with no errors' do + it 'work idempotently with no errors' do pp = <<-EOS class { 'pe_backup': } EOS # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end describe package('pe_backup') do diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb deleted file mode 100644 index 12513b8..0000000 --- a/spec/classes/coverage_spec.rb +++ /dev/null @@ -1 +0,0 @@ -at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/classes/pe_backup_spec.rb b/spec/classes/pe_backup_spec.rb index 1e0b504..0259835 100644 --- a/spec/classes/pe_backup_spec.rb +++ b/spec/classes/pe_backup_spec.rb @@ -8,10 +8,10 @@ facts end - context "pe_backup class with destination => /tmp" do + context 'pe_backup class with destination => /tmp' do let(:params) do { - :destination => '/tmp', + destination: '/tmp', } end @@ -26,17 +26,4 @@ end end end - -# context 'unsupported operating system' do -# describe 'pe_backup class without any parameters on Solaris/Nexenta' do -# let(:facts) do -# { -# :osfamily => 'Solaris', -# :operatingsystem => 'Nexenta', -# } -# end -# -# it { expect { is_expected.to contain_cron('pe_backup') }.to raise_error(Puppet::Error, /Nexenta not supported/) } -# end -# end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..ea1e480 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,7 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2e5985..d650528 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,20 +1,50 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + include RspecPuppetFacts -require 'simplecov' -require 'simplecov-console' +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) -SimpleCov.start do - add_filter '/spec' - add_filter '/vendor' - formatter SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ]) + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end end RSpec.configure do |c| - c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml')) + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) + end end + +# Ensures that a module is defined +# @param module_name Name of the module +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 + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 18fd098..d1c8049 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -14,9 +14,9 @@ # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'pe_backup') + puppet_module_install(source: proj_root, module_name: 'pe_backup') hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] end end end