From 10c3599d227d4510f77da06bf1dff0e6d37e1c63 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Tue, 12 Jul 2016 12:16:09 -0500 Subject: [PATCH] Add dir_path_task_root * Specify the root directory of a task Change-Id: Ib064af9f851d7f657b12e6824220f4bc10e305f5 --- doc/usage.rst | 3 +++ lib/noop/config/base.rb | 18 ++++++++++++++++++ lib/noop/manager/report.rb | 1 + lib/noop/task/run.rb | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/usage.rst b/doc/usage.rst index 958eac6..3055d25 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -330,6 +330,9 @@ Paths related: - **SPEC_TASK_DIR** Set the path to the task manifests folder. - **SPEC_DEPLOYMENT_DIR** Set the path to the *deployment* directory. It's actually use only to find the scripts to update and reset modules. +- **SPEC_TASK_ROOT_DIR** Set the root path of the RSpec execution. + RSpec command will be run from this directory. + Usually it's the same dir as the **SPEC_ROOT_DIR**. - **WORKSPACE** This variable is passed by the Jenkins jobs or will default to the *workspece* folder. Currently used only to store the Ruby gems installed by the *bundler* if *RVM* is not used. diff --git a/lib/noop/config/base.rb b/lib/noop/config/base.rb index aa43e91..cf493e3 100644 --- a/lib/noop/config/base.rb +++ b/lib/noop/config/base.rb @@ -2,12 +2,16 @@ require 'pathname' module Noop module Config + # The root directory of the config sub-module. + # It's being used as the root for the relative paths + # to the other directories. # @return [Pathname] def self.dir_path_config return @dirname if @dirname @dirname = Pathname.new(__FILE__).dirname.realpath end + # The root directory of the fixtures module. # @return [Pathname] def self.dir_path_root return @dir_path_root if @dir_path_root @@ -20,6 +24,20 @@ module Noop end end + # The directory where the task will chdir before being run. + # Equals to the root dir unless specified. + # @return [Pathname] + def self.dir_path_task_root + return @dir_path_task_root if @dir_path_task_root + @dir_path_task_root = Noop::Utils.path_from_env 'SPEC_TASK_ROOT_DIR' + @dir_path_task_root = dir_path_root unless @dir_path_task_root + begin + @dir_path_task_root = @dir_path_task_root.realpath + rescue + @dir_path_task_root + end + end + # @return [Pathname] def self.dir_path_task_spec return @dir_path_task_spec if @dir_path_task_spec diff --git a/lib/noop/manager/report.rb b/lib/noop/manager/report.rb index 8e09746..7978f42 100644 --- a/lib/noop/manager/report.rb +++ b/lib/noop/manager/report.rb @@ -205,6 +205,7 @@ Total tasks to run: <%= task_list.count.to_s.colorize :yellow %> paths = [ :dir_path_config, :dir_path_root, + :dir_path_task_root, :dir_path_task_spec, :dir_path_modules_local, :dir_path_tasks_local, diff --git a/lib/noop/task/run.rb b/lib/noop/task/run.rb index 56ab03c..7acea0e 100644 --- a/lib/noop/task/run.rb +++ b/lib/noop/task/run.rb @@ -61,6 +61,7 @@ module Noop 'GEM_HOME' => Noop::Config.dir_path_gem_home.to_s, 'SPEC_ROOT_DIR' => Noop::Config.dir_path_root.to_s, + 'SPEC_TASK_ROOT_DIR' => Noop::Config.dir_path_task_root.to_s, 'SPEC_DEPLOYMENT_DIR' => Noop::Config.dir_path_deployment.to_s, 'SPEC_HIERA_DIR' => Noop::Config.dir_path_hiera.to_s, 'SPEC_FACTS_DIR' => Noop::Config.dir_path_facts.to_s, @@ -71,7 +72,7 @@ module Noop } command = "rspec #{file_path_spec.to_s} #{rspec_options} --format json --out #{file_path_report_json.to_s}" command = "bundle exec #{command}" if ENV['SPEC_BUNDLE_EXEC'] - Dir.chdir Noop::Config.dir_path_root + Dir.chdir Noop::Config.dir_path_task_root success = Noop::Utils.run environment, command if success.nil? debug 'RSpec command is not found!'