diff --git a/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml b/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml index b31bf18..bf07dc5 100644 --- a/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml +++ b/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml @@ -1,58 +1,58 @@ --- name: '[Daily] Unit Tests with nightly Puppet gem' on: schedule: - cron: '0 5 * * 1-5' jobs: daily_unit_tests_with_nightly_puppet_gem: name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} strategy: matrix: - os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2016' ] puppet_version: [ 5, 6, 7 ] include: - puppet_version: 5 ruby: 2.4 - puppet_version: 6 ruby: 2.5 - puppet_version: 7 ruby: 2.7 - os: 'ubuntu-18.04' os_type: 'Linux' env_set_cmd: 'export ' gem_file: 'puppet-latest.gem' - os: 'macos-10.15' os_type: 'macOS' env_set_cmd: 'export ' gem_file: 'puppet-latest-universal-darwin.gem' - - os: 'windows-2019' + - os: 'windows-2016' os_type: 'Windows' env_set_cmd: '$env:' gem_file: 'puppet-latest-x64-mingw32.gem' runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - name: Install ruby version ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Install the latest nightly build of puppet${{ matrix.puppet_version }} gem run: | curl http://nightlies.puppet.com/downloads/gems/puppet${{ matrix.puppet_version }}-nightly/${{ matrix.gem_file }} --output puppet.gem gem install puppet.gem -N - name: Prepare testing environment with bundler run: | bundle config set system 'true' ${{ matrix.env_set_cmd }}PUPPET_GEM_VERSION=$(ruby -e 'puts /puppet\s+\((.+)\)/.match(`gem list -eld puppet`)[1]') bundle update --jobs 4 --retry 3 - name: Run unit tests run: bundle exec rake parallel_spec diff --git a/.github/workflows/static_code_analysis.yaml b/.github/workflows/static_code_analysis.yaml index ed4a232..9b94bf8 100644 --- a/.github/workflows/static_code_analysis.yaml +++ b/.github/workflows/static_code_analysis.yaml @@ -1,41 +1,46 @@ --- name: Static Code Analysis on: push: branches: [ main ] pull_request: branches: [ main ] jobs: static_code_analysis: name: Run checks env: ruby_version: 2.5 extra_checks: check:symlinks check:git_ignore check:dot_underscore check:test_file runs-on: 'ubuntu-18.04' steps: - name: Checkout current PR code uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Install ruby version ${{ env.ruby_version }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ env.ruby_version }} - name: Prepare testing environment with bundler run: bundle update --jobs 4 --retry 3 + - name: Run commits check + run: bundle exec rake commits + - name: Run rubocop check run: bundle exec rake ${{ env.extra_checks }} rubocop - name: Run syntax check run: bundle exec rake ${{ env.extra_checks }} syntax syntax:hiera syntax:manifests syntax:templates - name: Run lint check run: bundle exec rake ${{ env.extra_checks }} lint - name: Run metadata_lint check run: bundle exec rake ${{ env.extra_checks }} metadata_lint diff --git a/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml index 8c5d909..b408ee8 100644 --- a/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml +++ b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml @@ -1,60 +1,60 @@ --- name: Unit Tests with nightly Puppet gem on: push: branches: [ main ] pull_request: branches: [ main ] jobs: unit_tests_with_nightly_puppet_gem: name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} strategy: matrix: - os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2016' ] puppet_version: [ 5, 6, 7 ] include: - puppet_version: 5 ruby: 2.4 - puppet_version: 6 ruby: 2.5 - puppet_version: 7 ruby: 2.7 - os: 'ubuntu-18.04' os_type: 'Linux' env_set_cmd: 'export ' gem_file: 'puppet-latest.gem' - os: 'macos-10.15' os_type: 'macOS' env_set_cmd: 'export ' gem_file: 'puppet-latest-universal-darwin.gem' - - os: 'windows-2019' + - os: 'windows-2016' os_type: 'Windows' env_set_cmd: '$env:' gem_file: 'puppet-latest-x64-mingw32.gem' runs-on: ${{ matrix.os }} steps: - name: Checkout current PR code uses: actions/checkout@v2 - name: Install ruby version ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Install the latest nightly build of puppet${{ matrix.puppet_version }} gem run: | curl http://nightlies.puppet.com/downloads/gems/puppet${{ matrix.puppet_version }}-nightly/${{ matrix.gem_file }} --output puppet.gem gem install puppet.gem -N - name: Prepare testing environment with bundler run: | bundle config set system 'true' ${{ matrix.env_set_cmd }}PUPPET_GEM_VERSION=$(ruby -e 'puts /puppet\s+\((.+)\)/.match(`gem list -eld puppet`)[1]') bundle update --jobs 4 --retry 3 - name: Run unit tests run: bundle exec rake parallel_spec diff --git a/.github/workflows/unit_tests_with_released_puppet_gem.yaml b/.github/workflows/unit_tests_with_released_puppet_gem.yaml index 065e2b9..47385ac 100644 --- a/.github/workflows/unit_tests_with_released_puppet_gem.yaml +++ b/.github/workflows/unit_tests_with_released_puppet_gem.yaml @@ -1,48 +1,48 @@ --- name: Unit Tests with released Puppet gem on: push: branches: [ main ] pull_request: branches: [ main ] jobs: unit_tests_with_released_puppet_gem: name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} strategy: matrix: - os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2016' ] puppet_version: [ 5, 6 ] include: - puppet_version: 5 ruby: 2.4 - puppet_version: 6 ruby: 2.5 - os: 'ubuntu-18.04' os_type: 'Linux' - os: 'macos-10.15' os_type: 'macOS' - - os: 'windows-2019' + - os: 'windows-2016' os_type: 'Windows' runs-on: ${{ matrix.os }} env: PUPPET_GEM_VERSION: ~> ${{ matrix.puppet_version }}.0 steps: - name: Checkout current PR code uses: actions/checkout@v2 - name: Install ruby version ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Prepare testing environment with bundler run: | bundle config set system 'true' bundle update --jobs 4 --retry 3 - name: Run unit tests run: bundle exec rake parallel_spec diff --git a/Gemfile b/Gemfile index 3444d32..dd48fcc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,90 +1,92 @@ 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 "parallel_tests", '>= 2.14.1', '< 2.14.3', require: false gem "metadata-json-lint", '>= 2.0.2', '< 3.0.0', require: false gem "rspec-puppet-facts", '~> 1.10.0', require: false gem "rspec_junit_formatter", '~> 0.2', require: false gem "rubocop", '~> 0.49.0', require: false gem "rubocop-rspec", '~> 1.16.0', require: false gem "rubocop-i18n", '~> 1.2.0', require: false gem "puppetlabs_spec_helper", '>= 2.9.0', '< 3.0.0', require: false 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 "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "puppet-module-posix-default-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-strings", require: false gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end group :system_tests do gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 4') gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.5') gem "beaker-pe", require: false gem "beaker-hostgenerator" gem "beaker-rspec" gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 1.0') + gem "pdk", '~> 1.18', platforms: [:ruby] + gem "puppet-blacksmith", '~> 3.4', require: false end 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 e1d5f7b..7f91a3f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,86 +1,111 @@ require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' 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? 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 def changelog_project return unless Rake.application.top_level_tasks.include? "changelog" returnVal = nil returnVal ||= begin metadata_source = JSON.load(File.read('metadata.json'))['source'] metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) metadata_source_match && metadata_source_match[1] end raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? puts "GitHubChangelogGenerator project:#{returnVal}" returnVal end def changelog_future_release return unless Rake.application.top_level_tasks.include? "changelog" returnVal = "%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 PuppetLint.configuration.send('disable_relative') 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 "verify that commit messages match CONTRIBUTING.md requirements" +task(:commits) do + # This rake task looks at the summary from every commit from this branch not + # in the branch targeted for a PR. + commit_range = 'HEAD^..HEAD' + puts "Checking commits #{commit_range}" + %x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary| + # This regex tests for the currently supported commit summary tokens. + # The exception tries to explain it in more full. + if /^\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil? + raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \ + "\n\t\t#{commit_summary}\n" \ + "\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \ + "\t\t(MODULES-) # this is most common and should be a ticket at tickets.puppet.com\n" \ + "\t\t(docs)\n" \ + "\t\t(docs)(DOCUMENT-)\n" \ + "\t\t(packaging)\n" + "\t\t(maint)\n" \ + "\n\tThis test for the commit summary is case-insensitive.\n\n\n" + else + puts "#{commit_summary}" + end + puts "...passed" + end +end