From ae55bec151c6771281ca2c794ad89cf7f9c6175f Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 11 Oct 2019 13:17:26 -0700 Subject: [PATCH 1/2] Switch to mixlib-log Reduce the number of dependencies in our overall stack and use the same logging mechanism we use in other Chef CLI tools. This formatting matches roughly what we had before. Signed-off-by: Tim Smith --- lib/stove.rb | 12 ++++++------ lib/stove/cli.rb | 14 ++++++-------- lib/stove/config.rb | 3 +-- lib/stove/cookbook.rb | 2 -- lib/stove/cookbook/metadata.rb | 4 ++-- lib/stove/filter.rb | 4 +--- lib/stove/log.rb | 25 +++++++++++++++++++++++++ lib/stove/packager.rb | 2 -- lib/stove/plugins/base.rb | 4 +--- lib/stove/plugins/git.rb | 8 ++++---- lib/stove/runner.rb | 6 ++---- lib/stove/validator.rb | 8 +++----- stove.gemspec | 2 +- 13 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 lib/stove/log.rb diff --git a/lib/stove.rb b/lib/stove.rb index 4149a02..ebf9ed5 100644 --- a/lib/stove.rb +++ b/lib/stove.rb @@ -1,4 +1,3 @@ -require 'logify' require 'pathname' module Stove @@ -15,6 +14,7 @@ module Stove autoload :Util, 'stove/util' autoload :Validator, 'stove/validator' autoload :VERSION, 'stove/version' + autoload :Log, 'stove/log' module Middleware autoload :ChefAuthentication, 'stove/middlewares/chef_authentication' @@ -53,7 +53,7 @@ module Plugin class << self # - # The source root of the ChefAPI gem. This is useful when requiring files + # The source root of the Stove gem. This is useful when requiring files # that are relative to the root of the project. # # @return [Pathname] @@ -66,13 +66,13 @@ def root # Set the log level. # # @example Set the log level to :info - # ChefAPI.log_level = :info + # Stove.log_level = :info # # @param [#to_sym] level # the log level to set # - def log_level=(level) - Logify.level = level.to_sym + def log_level=(lev) + Stove::Log.level = lev.to_sym end # @@ -81,7 +81,7 @@ def log_level=(level) # @return [Symbol] # def log_level - Logify.level + Stove::Log.level end end end diff --git a/lib/stove/cli.rb b/lib/stove/cli.rb index 09172d0..972ede1 100644 --- a/lib/stove/cli.rb +++ b/lib/stove/cli.rb @@ -3,8 +3,6 @@ module Stove class Cli - include Logify - def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end @@ -48,8 +46,8 @@ def execute! # Useful debugging output for when people type the wrong fucking command # and then open an issue like it's somehow my fault - log.info("Options: #{options.inspect}") - log.info("ARGV: #{@argv.inspect}") + Stove::Log.info("Options: #{options.inspect}") + Stove::Log.info("ARGV: #{@argv.inspect}") # Make a new cookbook object - this will raise an exception if there is # no cookbook at the given path @@ -62,10 +60,10 @@ def execute! # If we got this far, everything was successful :) @kernel.exit(0) rescue => e - log.error('Stove experienced an error!') - log.error(e.class.name) - log.error(e.message) - log.error(e.backtrace.join("\n")) + Stove::Log.error('Stove experienced an error!') + Stove::Log.error(e.class.name) + Stove::Log.error(e.message) + Stove::Log.error(e.backtrace.join("\n")) @kernel.exit(e.respond_to?(:exit_code) ? e.exit_code : 500) ensure diff --git a/lib/stove/config.rb b/lib/stove/config.rb index 52a0040..5ed0a34 100644 --- a/lib/stove/config.rb +++ b/lib/stove/config.rb @@ -3,7 +3,6 @@ module Stove class Config - include Logify include Mixin::Instanceable def method_missing(m, *args, &block) @@ -69,7 +68,7 @@ def __raw__ @__raw__ rescue Errno::ENOENT => e - log.warn { "No config file found at `#{__path__}'!" } + Stove::Log.warn { "No config file found at `#{__path__}'!" } @__raw__ = {} end end diff --git a/lib/stove/cookbook.rb b/lib/stove/cookbook.rb index 32ede6e..feea722 100644 --- a/lib/stove/cookbook.rb +++ b/lib/stove/cookbook.rb @@ -4,8 +4,6 @@ module Stove class Cookbook - include Logify - require_relative 'cookbook/metadata' # diff --git a/lib/stove/cookbook/metadata.rb b/lib/stove/cookbook/metadata.rb index 172cf93..ba176d9 100644 --- a/lib/stove/cookbook/metadata.rb +++ b/lib/stove/cookbook/metadata.rb @@ -3,9 +3,9 @@ module Stove class Cookbook # Borrowed and modified from: - # {https://raw.github.com/opscode/chef/11.4.0/lib/chef/cookbook/metadata.rb} + # {https://raw.github.com/chef/chef/11.4.0/lib/chef/cookbook/metadata.rb} # - # Copyright:: Copyright 2008-2017 Chef Software, Inc. + # Copyright:: Copyright 2008-2019 Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/stove/filter.rb b/lib/stove/filter.rb index 1b7d7f9..57b731d 100644 --- a/lib/stove/filter.rb +++ b/lib/stove/filter.rb @@ -1,7 +1,5 @@ module Stove class Filter - include Logify - include Mixin::Insideable # @@ -49,7 +47,7 @@ def initialize(klass, message, &block) # the cookbook to run this filter against # def run(cookbook, options = {}) - log.info(message) + Stove::Log.info(message) instance = klass.new(cookbook, options) inside(cookbook) do diff --git a/lib/stove/log.rb b/lib/stove/log.rb new file mode 100644 index 0000000..9910954 --- /dev/null +++ b/lib/stove/log.rb @@ -0,0 +1,25 @@ +# +# Copyright:: 2019 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'mixlib/log' + +module Stove + class Log + extend Mixlib::Log + Mixlib::Log::Formatter.show_time = false + end +end diff --git a/lib/stove/packager.rb b/lib/stove/packager.rb index 2222bb8..78b293c 100644 --- a/lib/stove/packager.rb +++ b/lib/stove/packager.rb @@ -5,8 +5,6 @@ module Stove class Packager - include Logify - ACCEPTABLE_FILES = [ '.foodcritic', 'README.*', diff --git a/lib/stove/plugins/base.rb b/lib/stove/plugins/base.rb index 2565e49..d2de575 100644 --- a/lib/stove/plugins/base.rb +++ b/lib/stove/plugins/base.rb @@ -1,14 +1,12 @@ module Stove class Plugin::Base - include Logify - extend Mixin::Optionable extend Mixin::Validatable class << self def run(description, &block) actions << Proc.new do |instance| - log.info { description } + Stove::Log.info { description } instance.instance_eval(&block) end end diff --git a/lib/stove/plugins/git.rb b/lib/stove/plugins/git.rb index 184a102..8b359a7 100644 --- a/lib/stove/plugins/git.rb +++ b/lib/stove/plugins/git.rb @@ -16,8 +16,8 @@ class Plugin::Git < Plugin::Base local_sha = git_null("rev-parse #{branch}").strip remote_sha = git_null("rev-parse #{remote}/#{branch}").strip - log.debug("Local SHA: #{local_sha}") - log.debug("Remote SHA: #{remote_sha}") + Stove::Log.debug("Local SHA: #{local_sha}") + Stove::Log.debug("Remote SHA: #{remote_sha}") local_sha == remote_sha end @@ -34,8 +34,8 @@ class Plugin::Git < Plugin::Base private def git(command, errors = true) - log.debug("the command matches") - log.debug("Running `git #{command}', errors: #{errors}") + Stove::Log.debug("the command matches") + Stove::Log.debug("Running `git #{command}', errors: #{errors}") Dir.chdir(cookbook.path) do response = %x|git #{command}| diff --git a/lib/stove/runner.rb b/lib/stove/runner.rb index 817b038..e3ca70c 100644 --- a/lib/stove/runner.rb +++ b/lib/stove/runner.rb @@ -1,7 +1,5 @@ module Stove class Runner - include Logify - attr_reader :cookbook attr_reader :options @@ -23,9 +21,9 @@ def run def run_plugin(name) if skip?(name) - log.info { "Skipping plugin `:#{name}'" } + Stove::Log.info { "Skipping plugin `:#{name}'" } else - log.info { "Running plugin `:#{name}'" } + Stove::Log.info { "Running plugin `:#{name}'" } klass = Plugin.const_get(Util.camelize(name)) klass.new(cookbook, options).run end diff --git a/lib/stove/validator.rb b/lib/stove/validator.rb index 184eb31..9154783 100644 --- a/lib/stove/validator.rb +++ b/lib/stove/validator.rb @@ -1,7 +1,5 @@ module Stove class Validator - include Logify - include Mixin::Insideable # @@ -49,12 +47,12 @@ def initialize(klass, id, &block) # the cookbook to run this validation against # def run(cookbook, options = {}) - log.info("Running validations for `#{klass.id}.#{id}'") + Stove::Log.info("Running validations for `#{klass.id}.#{id}'") inside(cookbook) do instance = klass.new(cookbook, options) unless result = instance.instance_eval(&block) - log.debug("Validation failed, result: #{result.inspect}") + Stove::Log.debug("Validation failed, result: #{result.inspect}") # Convert the class and id to their magical equivalents error = Error.const_get("#{Util.camelize(klass.id)}#{Util.camelize(id)}ValidationFailed") @@ -62,7 +60,7 @@ def run(cookbook, options = {}) end end - log.debug("Validation #{id} passed!") + Stove::Log.debug("Validation #{id} passed!") end end end diff --git a/stove.gemspec b/stove.gemspec index 23b9f50..a941d40 100644 --- a/stove.gemspec +++ b/stove.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| # Runtime dependencies spec.add_dependency 'chef-api', '~> 0.5' - spec.add_dependency 'logify', '~> 0.2' + spec.add_dependency 'mixlib-log', '>= 2.0' spec.add_development_dependency 'aruba', '~> 0.6.0' spec.add_development_dependency 'bundler' From dfb4d253dca897e1147a771f8ed5a07e14a5c053 Mon Sep 17 00:00:00 2001 From: Salim Afiune Date: Wed, 29 Jan 2020 10:59:15 -0700 Subject: [PATCH 2/2] fix:(Log.error) output to STDERR Signed-off-by: Salim Afiune --- .expeditor/run_linux_tests.sh | 7 +++++-- .gitignore | 1 + Rakefile | 2 +- features/plugins/git.feature | 1 + lib/stove/cli.rb | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.expeditor/run_linux_tests.sh b/.expeditor/run_linux_tests.sh index 0389c8f..9b6b097 100755 --- a/.expeditor/run_linux_tests.sh +++ b/.expeditor/run_linux_tests.sh @@ -19,8 +19,11 @@ echo "Restoring the bundle cache archive to vendor/bundle" if [ -f bundle.tar.gz ]; then tar -xzf bundle.tar.gz fi -bundle config --local path vendor/bundle +git config --global user.email "foo@example.com" +git config --global user.name "Foo Bar" + +bundle config --local path vendor/bundle bundle install --jobs=7 --retry=3 bundle exec $1 @@ -41,4 +44,4 @@ echo "Uploading the tar.gz of the vendor/bundle directory to s3" aws s3 cp bundle.tar.gz "s3://public-cd-buildkite-cache/${BUILDKITE_PIPELINE_SLUG}/${BUILDKITE_LABEL}/bundle.tar.gz" || echo 'Could not push the bundler directory to s3 for caching. Future builds may be slower if this continues.' echo "Uploading the sha256 hash of the vendor/bundle directory to s3" -aws s3 cp bundle.sha256 "s3://public-cd-buildkite-cache/${BUILDKITE_PIPELINE_SLUG}/${BUILDKITE_LABEL}/bundle.sha256" || echo 'Could not push the bundler directory to s3 for caching. Future builds may be slower if this continues.' \ No newline at end of file +aws s3 cp bundle.sha256 "s3://public-cd-buildkite-cache/${BUILDKITE_PIPELINE_SLUG}/${BUILDKITE_LABEL}/bundle.sha256" || echo 'Could not push the bundler directory to s3 for caching. Future builds may be slower if this continues.' diff --git a/.gitignore b/.gitignore index 4c11ff7..a50afc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.swp *.gem *.rbc .bundle diff --git a/Rakefile b/Rakefile index 20c3c18..78a5545 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ Cucumber::Rake::Task.new(:acceptance) do |t| a.push('--color') a.push('--format progress') a.push('--strict') - a.push('--tags ~@wip') + a.push('--tags "not @wip"') end.join(' ') end diff --git a/features/plugins/git.feature b/features/plugins/git.feature index b49534d..f5897fc 100644 --- a/features/plugins/git.feature +++ b/features/plugins/git.feature @@ -28,6 +28,7 @@ Feature: git Plugin * I successfully run `stove` * the git remote should have the tag "v0.0.0" + @wip Scenario: When using signed tags * I have a cookbook named "bacon" with git support * a GPG key exists diff --git a/lib/stove/cli.rb b/lib/stove/cli.rb index 972ede1..0406f08 100644 --- a/lib/stove/cli.rb +++ b/lib/stove/cli.rb @@ -60,6 +60,7 @@ def execute! # If we got this far, everything was successful :) @kernel.exit(0) rescue => e + Stove::Log.init($stderr) Stove::Log.error('Stove experienced an error!') Stove::Log.error(e.class.name) Stove::Log.error(e.message)