Browse Source

Add dir_path_task_root

* Specify the root directory of a task

Change-Id: Ib064af9f851d7f657b12e6824220f4bc10e305f5
Dmitry Ilyin 2 years ago
parent
commit
10c3599d22
4 changed files with 24 additions and 1 deletions
  1. 3
    0
      doc/usage.rst
  2. 18
    0
      lib/noop/config/base.rb
  3. 1
    0
      lib/noop/manager/report.rb
  4. 2
    1
      lib/noop/task/run.rb

+ 3
- 0
doc/usage.rst View File

@@ -330,6 +330,9 @@ Paths related:
330 330
 - **SPEC_TASK_DIR** Set the path to the task manifests folder.
331 331
 - **SPEC_DEPLOYMENT_DIR** Set the path to the *deployment* directory. It's
332 332
   actually use only to find the scripts to update and reset modules.
333
+- **SPEC_TASK_ROOT_DIR** Set the root path of the RSpec execution.
334
+  RSpec command will be run from this directory.
335
+  Usually it's the same dir as the **SPEC_ROOT_DIR**.
333 336
 - **WORKSPACE** This variable is passed by the Jenkins jobs or will default to
334 337
   the *workspece* folder. Currently used only to store the Ruby gems installed
335 338
   by the *bundler* if *RVM* is not used.

+ 18
- 0
lib/noop/config/base.rb View File

@@ -2,12 +2,16 @@ require 'pathname'
2 2
 
3 3
 module Noop
4 4
   module Config
5
+    # The root directory of the config sub-module.
6
+    # It's being used as the root for the relative paths
7
+    # to the other directories.
5 8
     # @return [Pathname]
6 9
     def self.dir_path_config
7 10
       return @dirname if @dirname
8 11
       @dirname = Pathname.new(__FILE__).dirname.realpath
9 12
     end
10 13
 
14
+    # The root directory of the fixtures module.
11 15
     # @return [Pathname]
12 16
     def self.dir_path_root
13 17
       return @dir_path_root if @dir_path_root
@@ -20,6 +24,20 @@ module Noop
20 24
       end
21 25
     end
22 26
 
27
+    # The directory where the task will chdir before being run.
28
+    # Equals to the root dir unless specified.
29
+    # @return [Pathname]
30
+    def self.dir_path_task_root
31
+      return @dir_path_task_root if @dir_path_task_root
32
+      @dir_path_task_root = Noop::Utils.path_from_env 'SPEC_TASK_ROOT_DIR'
33
+      @dir_path_task_root = dir_path_root unless @dir_path_task_root
34
+      begin
35
+        @dir_path_task_root = @dir_path_task_root.realpath
36
+      rescue
37
+        @dir_path_task_root
38
+      end
39
+    end
40
+
23 41
     # @return [Pathname]
24 42
     def self.dir_path_task_spec
25 43
       return @dir_path_task_spec if @dir_path_task_spec

+ 1
- 0
lib/noop/manager/report.rb View File

@@ -205,6 +205,7 @@ Total tasks to run:       <%= task_list.count.to_s.colorize :yellow %>
205 205
       paths = [
206 206
           :dir_path_config,
207 207
           :dir_path_root,
208
+          :dir_path_task_root,
208 209
           :dir_path_task_spec,
209 210
           :dir_path_modules_local,
210 211
           :dir_path_tasks_local,

+ 2
- 1
lib/noop/task/run.rb View File

@@ -61,6 +61,7 @@ module Noop
61 61
           'GEM_HOME' => Noop::Config.dir_path_gem_home.to_s,
62 62
 
63 63
           'SPEC_ROOT_DIR' => Noop::Config.dir_path_root.to_s,
64
+          'SPEC_TASK_ROOT_DIR' => Noop::Config.dir_path_task_root.to_s,
64 65
           'SPEC_DEPLOYMENT_DIR' => Noop::Config.dir_path_deployment.to_s,
65 66
           'SPEC_HIERA_DIR' => Noop::Config.dir_path_hiera.to_s,
66 67
           'SPEC_FACTS_DIR' => Noop::Config.dir_path_facts.to_s,
@@ -71,7 +72,7 @@ module Noop
71 72
       }
72 73
       command = "rspec #{file_path_spec.to_s} #{rspec_options} --format json --out #{file_path_report_json.to_s}"
73 74
       command = "bundle exec #{command}" if ENV['SPEC_BUNDLE_EXEC']
74
-      Dir.chdir Noop::Config.dir_path_root
75
+      Dir.chdir Noop::Config.dir_path_task_root
75 76
       success = Noop::Utils.run environment, command
76 77
       if success.nil?
77 78
         debug 'RSpec command is not found!'

Loading…
Cancel
Save