8 NODE_TOTAL = Integer(ENV.fetch('CIRCLE_NODE_TOTAL', 1))
9 NODE_INDEX = Integer(ENV.fetch('CIRCLE_NODE_INDEX', 0))
11 ROOT = Pathname.pwd.freeze
12 VENDOR_BUNDLE = ROOT.join('vendor', 'bundle').freeze
13 ROOT_GEMFILE = ROOT.join('Gemfile').freeze
18 DEFAULT_MODE = 'test'.freeze
24 ALL = %w[api core emails].map(&method(:new)).freeze
25 CORE_GEMS = %w[api core].freeze
29 # @raise [RuntimeError]
36 bundle_check || bundle_install || raise('Cannot finish gem installation')
41 # Test subproject for passing its tests
44 # the success of the build
52 # Process CLI arguments
54 # @param [Array<String>] arguments
57 # the success of the CLI run
58 def self.run_cli(arguments)
59 raise ArgumentError if arguments.length > 1
61 mode = arguments.fetch(0, DEFAULT_MODE)
70 raise "Unknown mode: #{mode.inspect}"
76 # Check if current bundle is already usable
80 system("bundle check --path=#{VENDOR_BUNDLE}")
83 # Install the current bundle
86 # the success of the installation
88 system("bundle install --path=#{VENDOR_BUNDLE} --jobs=#{BUNDLER_JOBS} --retry=#{BUNDLER_RETRIES}")
95 gemfile_path = if CORE_GEMS.include?(self.name)
101 system("bundle exec --gemfile=#{gemfile_path} rake test_app ") || raise('Failed to setup the test app')
104 # Run tests for subproject
107 # the success of the tests
109 system("bundle exec rspec #{rspec_arguments.join(' ')}")
112 def rspec_arguments(custom_name = name)
114 args += %w[--order random --format documentation --profile 10]
115 if report_dir = ENV['CIRCLE_TEST_REPORTS']
116 args += %W[-r rspec_junit_formatter --format RspecJunitFormatter -o #{report_dir}/rspec/#{custom_name}.xml]
121 # Change to subproject directory and execute block
123 # @return [undefined]
125 Dir.chdir(ROOT.join(name), &block)
128 # Install subprojects
132 current_projects.each do |project|
133 log("Installing project: #{project.name}")
138 private_class_method :install
140 # Execute tests on subprojects
143 # the success of ALL subprojects
145 projects = current_projects
146 suffix = "#{projects.length} projects(s) on node #{NODE_INDEX.succ} / #{NODE_TOTAL}"
148 log("Running #{suffix}")
149 projects.each do |project|
150 log("- #{project.name}")
153 builds = projects.map do |project|
154 log("Building: #{project.name}")
157 log("Finished running #{suffix}")
159 projects.zip(builds).each do |project, build|
160 log("- #{project.name} #{build ? 'SUCCESS' : 'FAILURE'}")
165 private_class_method :test
167 # Return the projects active on current node
169 # @return [Array<Project>]
170 def self.current_projects
171 NODE_INDEX.step(ALL.length - 1, NODE_TOTAL).map(&ALL.method(:fetch))
173 private_class_method :current_projects
175 # Log a progress message to stderr
177 # @param [String] message
179 # @return [undefined]
180 def self.log(message)
183 private_class_method :log
186 exit Project.run_cli(ARGV)