From 3797b483b6e6123fc7eeeaa439714ff7c1fbb627 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 20:44:59 -0700 Subject: [PATCH 1/8] Add windows testing in Buildkite Also switch to the faster containers Signed-off-by: Tim Smith --- .expeditor/verify.pipeline.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index a3efc1c..7865325 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -1,28 +1,43 @@ +--- +expeditor: + defaults: + buildkite: + timeout_in_minutes: 30 + steps: - label: run-lint-and-specs-ruby-2.4 command: - - asdf local ruby 2.4.5 - - bundle install --jobs=7 --retry=3 + - bundle install --jobs=7 --retry=3 --without docs debug - bundle exec rake expeditor: executor: docker: + image: ruby:2.4-stretch - label: run-lint-and-specs-ruby-2.5 command: - - asdf local ruby 2.5.5 - - bundle install --jobs=7 --retry=3 + - bundle install --jobs=7 --retry=3 --without docs debug - bundle exec rake expeditor: executor: docker: + image: ruby:2.5-stretch - label: run-lint-and-specs-ruby-2.6 command: - - asdf local ruby 2.6.3 - - bundle install --jobs=7 --retry=3 + - bundle install --jobs=7 --retry=3 --without docs debug + - bundle exec rake + expeditor: + executor: + docker: + image: ruby:2.6-stretch + +- label: run-specs-windows + command: + - bundle install --jobs=7 --retry=3 --without docs debug - bundle exec rake expeditor: executor: docker: + host_os: windows From b7a37d62fca4252b0c80774adaa7f07a36d745fb Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 20:45:54 -0700 Subject: [PATCH 2/8] Remove appveyor config Also add the badge to the readme Signed-off-by: Tim Smith --- README.md | 1 + appveyor.yml | 43 ------------------------------------------- 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 appveyor.yml diff --git a/README.md b/README.md index 1641158..bf0a770 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Mixlib::Log [![Gem Version](https://badge.fury.io/rb/mixlib-log.svg)](https://badge.fury.io/rb/mixlib-log) +[![Build status](https://badge.buildkite.com/cb1e5b6f3cc77071f4b2315f6b605fe60d86e2862a490873d4.svg?branch=master)](https://buildkite.com/chef-oss/chef-mixlib-log-master-verify) **Umbrella Project**: [Chef Foundation](https://github.com/chef/chef-oss-practices/blob/master/projects/chef-foundation.md) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 023ea09..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: "master-{build}" - -os: Visual Studio 2017 -platform: - - x64 - -cache: - - vendor/bundle - -environment: - matrix: - - ruby_version: "24-x64" - - ruby_version: "25-x64" - - ruby_version: "26-x64" - -clone_depth: 1 -skip_tags: true -skip_branch_with_pr: true -branches: - only: - - master - -install: - - systeminfo - - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - - echo %PATH% - - appveyor DownloadFile http://curl.haxx.se/ca/cacert.pem -FileName C:\cacert.pem - - set SSL_CERT_FILE=C:\cacert.pem - - SET BUNDLE_WITHOUT=server:docgen:maintenance:pry:travis:integration:ci - - bundle config --local path vendor/bundle # use the cache we define above - - bundle install || bundle install || bundle install - -build: off - -before_test: - - ruby --version - - gem --version - - bundler --version - - bundle env - -test_script: - - SET SPEC_OPTS=--format progress - - bundle exec rake \ No newline at end of file From 1d60af72a9e1cfa7155bf42bcba6b0f25e863324 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 20:51:22 -0700 Subject: [PATCH 3/8] Chefstyle fixes Signed-off-by: Tim Smith --- Rakefile | 2 +- lib/mixlib/log.rb | 10 ++++++---- lib/mixlib/log/child.rb | 4 ++-- lib/mixlib/log/formatter.rb | 2 +- lib/mixlib/log/logger.rb | 6 ++++-- lib/mixlib/log/logging.rb | 2 +- spec/mixlib/log_spec.rb | 2 +- spec/spec_helper.rb | 4 +--- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Rakefile b/Rakefile index 1b9ec9a..adfd106 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" require "cucumber/rake/task" -task default: [:style, :spec, :features] +task default: %i{style spec features} Bundler::GemHelper.install_tasks diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb index e57ffcd..d15663c 100644 --- a/lib/mixlib/log.rb +++ b/lib/mixlib/log.rb @@ -61,7 +61,7 @@ def use_log_devices(other) if other.respond_to?(:loggers) && other.respond_to?(:logger) @loggers = other.loggers @logger = other.logger - elsif other.kind_of?(Array) + elsif other.is_a?(Array) @loggers = other @logger = other.first else @@ -82,7 +82,7 @@ def use_log_devices(other) def init(*opts) reset! @logger = logger_for(*opts) - @logger.formatter = Mixlib::Log::Formatter.new() if @logger.respond_to?(:formatter=) + @logger.formatter = Mixlib::Log::Formatter.new if @logger.respond_to?(:formatter=) @logger.level = Logger::WARN @configured = true @parent = nil @@ -110,6 +110,7 @@ def configured? def level=(new_level) level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level] raise ArgumentError, "Log level must be one of :trace, :debug, :info, :warn, :error, or :fatal" if level_int.nil? + loggers.each { |l| l.level = level_int } end @@ -125,7 +126,7 @@ def level(new_level = nil) # Note that we *only* query the default logger (@logger) and not any other # loggers that may have been added, even though it is possible to configure # two (or more) loggers at different log levels. - [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name| + %i{trace? debug? info? warn? error? fatal?}.each do |method_name| define_method(method_name) do logger.send(method_name) end @@ -137,7 +138,7 @@ def <<(msg) def add(severity, message = nil, progname = nil, data: {}, &block) message, progname, data = yield if block_given? - data = metadata.merge(data) if metadata.kind_of?(Hash) && data.kind_of?(Hash) + data = metadata.merge(data) if metadata.is_a?(Hash) && data.is_a?(Hash) loggers.each do |l| # if we don't have any metadata, let's not do the potentially expensive # merging and managing that this call requires @@ -193,6 +194,7 @@ def loggers_to_close # to get access to it. next unless logger.instance_variable_defined?(:"@logdev") next unless (logdev = logger.instance_variable_get(:"@logdev")) + loggers_to_close << logger if logdev.filename end loggers_to_close diff --git a/lib/mixlib/log/child.rb b/lib/mixlib/log/child.rb index 56376c5..2d7de00 100644 --- a/lib/mixlib/log/child.rb +++ b/lib/mixlib/log/child.rb @@ -36,14 +36,14 @@ def level # Note that we *only* query the default logger (@logger) and not any other # loggers that may have been added, even though it is possible to configure # two (or more) loggers at different log levels. - [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name| + %i{trace? debug? info? warn? error? fatal?}.each do |method_name| define_method(method_name) do parent.send(method_name) end end def add(severity, message = nil, progname = nil, data: {}, &block) - data = metadata.merge(data) if data.kind_of?(Hash) + data = metadata.merge(data) if data.is_a?(Hash) parent.send(:pass, severity, message, progname, data: data, &block) end diff --git a/lib/mixlib/log/formatter.rb b/lib/mixlib/log/formatter.rb index 1727452..680836f 100644 --- a/lib/mixlib/log/formatter.rb +++ b/lib/mixlib/log/formatter.rb @@ -31,7 +31,7 @@ def self.show_time=(show = false) # Otherwise, doesn't print the time. def call(severity, time, progname, msg) if @@show_time - sprintf("[%s] %s: %s\n", time.iso8601(), severity, msg2str(msg)) + sprintf("[%s] %s: %s\n", time.iso8601, severity, msg2str(msg)) else sprintf("%s: %s\n", severity, msg2str(msg)) end diff --git a/lib/mixlib/log/logger.rb b/lib/mixlib/log/logger.rb index f227f23..e1f8929 100644 --- a/lib/mixlib/log/logger.rb +++ b/lib/mixlib/log/logger.rb @@ -45,14 +45,16 @@ def initialize(logdev) def add_data(severity, message, progname, data: {}) return true if @logdev.nil? || severity < @level + data ||= {} - if message.kind_of?(::Exception) + if message.is_a?(::Exception) data[:err] = message else data[:msg] = message end @logdev.write( - format_message(to_label(severity), Time.now, progname, data)) + format_message(to_label(severity), Time.now, progname, data) + ) true end alias_method :add, :add_data diff --git a/lib/mixlib/log/logging.rb b/lib/mixlib/log/logging.rb index 524900b..5a7a076 100644 --- a/lib/mixlib/log/logging.rb +++ b/lib/mixlib/log/logging.rb @@ -41,7 +41,7 @@ def pass(severity, args, progname = nil, data: {}, &block) # Define the standard logger methods on this class programmatically. # No need to incur method_missing overhead on every log call. - [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name| + %i{trace debug info warn error fatal}.each do |method_name| level = LEVELS[method_name] define_method(method_name) do |msg = nil, data: {}, &block| pass(level, msg, data: data, &block) diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb index b58c4e2..5366dcd 100644 --- a/spec/mixlib/log_spec.rb +++ b/spec/mixlib/log_spec.rb @@ -38,7 +38,7 @@ def add(severity, message = nil, progname = nil, data: {}) @messages << message end - [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name| + %i{trace debug info warn error fatal}.each do |method_name| class_eval(<<-E) def #{method_name}(message) @messages << message diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2de3b9..e8a1bb1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,9 +24,7 @@ require "mixlib/log" require "mixlib/log/formatter" -RSpec.configure do |config| - config.disable_monkey_patching! -end +RSpec.configure(&:disable_monkey_patching!) class Logit extend Mixlib::Log From 01b46cf6efe0b0ba5fa0458e1c33a99945a6e5e7 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 21:02:16 -0700 Subject: [PATCH 4/8] Use standard gemfile groups This makes it easier diff Signed-off-by: Tim Smith --- Gemfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 432ee84..60cad82 100755 --- a/Gemfile +++ b/Gemfile @@ -3,19 +3,19 @@ source "https://rubygems.org" gemspec group :docs do - gem "yard" - gem "redcarpet" gem "github-markup" + gem "redcarpet" + gem "yard" end group :test do - gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master" - gem "rspec", "~> 3.7" + gem "chefstyle" gem "cucumber" gem "rake" + gem "rspec", "~> 3.7" end -group :development do +group :debug do gem "pry" gem "pry-byebug" gem "pry-stack_explorer" From cdb6b5c46072f782e241cddb318e0e9c71c7396b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 21:02:54 -0700 Subject: [PATCH 5/8] Add tagging config in expeditor Turns out we need this Signed-off-by: Tim Smith --- .expeditor/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 330b6a5..5283bc0 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -1,5 +1,6 @@ # Documentation available at https://expeditor.chef.io/docs/getting-started/ --- + # Slack channel in Chef Software slack to send notifications about build failures, etc slack: notify_channel: chef-found-notify @@ -11,6 +12,8 @@ rubygems: github: # This deletes the GitHub PR branch after successfully merged into the release branch delete_branch_on_merge: true + # The tag format to use (e.g. v1.0.0) + version_tag_format: "v{{version}}" # allow bumping the minor release via label minor_bump_labels: - "Expeditor: Bump Version Minor" From 2e93ea1fe20b3d5e0e96d81d8e300cdcb63eba3b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 6 Aug 2019 21:04:22 -0700 Subject: [PATCH 6/8] Use a standard rakefile This has more error handling and better named groups Signed-off-by: Tim Smith --- Rakefile | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index adfd106..15fa270 100644 --- a/Rakefile +++ b/Rakefile @@ -1,28 +1,40 @@ require "bundler/gem_tasks" -require "rspec/core/rake_task" -require "cucumber/rake/task" -task default: %i{style spec features} - -Bundler::GemHelper.install_tasks +begin + require "cucumber/rake/task" -desc "Run specs" -RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = "spec/**/*_spec.rb" + Cucumber::Rake::Task.new(:features) do |t| + t.cucumber_opts = "--format pretty" + end +rescue LoadError + desc "cucumber is not installed, this task is disabled" + task :spec do + abort "cucumber is not installed. bundle install first to make sure all dependencies are installed." + end end -Cucumber::Rake::Task.new(:features) do |t| - t.cucumber_opts = "--format pretty" +begin + require "rspec/core/rake_task" + + RSpec::Core::RakeTask.new do |t| + t.pattern = "spec/**/*_spec.rb" + end +rescue LoadError + desc "rspec is not installed, this task is disabled" + task :spec do + abort "rspec is not installed. bundle install first to make sure all dependencies are installed." + end end begin require "chefstyle" require "rubocop/rake_task" + desc "Run Chefstyle tests" RuboCop::RakeTask.new(:style) do |task| task.options += ["--display-cop-names", "--no-color"] end rescue LoadError - puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed." + puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed." end begin @@ -39,3 +51,5 @@ task :console do ARGV.clear IRB.start end + +task default: %i{style spec features} From b66dc9dbc9d58c977e289bd55e3484eecb8e057f Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 7 Aug 2019 09:13:11 -0700 Subject: [PATCH 7/8] Require full bundler in the rakefile Signed-off-by: Tim Smith --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 15fa270..5c9a752 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -require "bundler/gem_tasks" +require "bundler" begin require "cucumber/rake/task" From 76b305a788968538b5ce0c7223b8b0fe470f0c31 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 7 Aug 2019 09:29:22 -0700 Subject: [PATCH 8/8] Add bundle env to the windows job Let's see what's going on in here Signed-off-by: Tim Smith --- .expeditor/verify.pipeline.yml | 1 + Rakefile | 1 + 2 files changed, 2 insertions(+) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 7865325..81cc2b6 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -36,6 +36,7 @@ steps: - label: run-specs-windows command: - bundle install --jobs=7 --retry=3 --without docs debug + - bundle env - bundle exec rake expeditor: executor: diff --git a/Rakefile b/Rakefile index 5c9a752..5442c99 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,7 @@ begin Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = "--format pretty" + t.bundler = false end rescue LoadError desc "cucumber is not installed, this task is disabled"