Last active
June 11, 2021 12:51
-
-
Save ViliusLuneckas/c32bf2d7de05ac3b385bf6a565cc2d6d to your computer and use it in GitHub Desktop.
Distribute tests between pipelines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number_of_pipelines = ENV['NUMBER_OF_PIPELINES'].to_i || 2 | |
groups = [ | |
'spec/acceptance/**/*.feature', | |
'spec/mailers/**/*_spec.rb', | |
'spec/decorators/**/*_spec.rb', | |
'spec/features/**/*_spec.rb', | |
'spec/models/**/*_spec.rb', | |
'spec/policies/**/*_spec.rb', | |
'spec/adapters/**/*_spec.rb', | |
'spec/graphql/**/*_spec.rb', | |
'spec/state_handlers/**/*_spec.rb', | |
'spec/requests/**/*_spec.rb', | |
'spec/lib/**/*_spec.rb', | |
'spec/db/**/*_spec.rb', | |
'spec/workers/**/*_spec.rb', | |
'spec/routing/**/*_spec.rb', | |
'spec/controllers/**/*_spec.rb', | |
'spec/helpers/**/*_spec.rb', | |
'spec/services/**/*_spec.rb' | |
] | |
Dir.glob("{#{groups.join(',')}}").uniq.shuffle.each.with_index do |path, index| | |
test_content = File.read(path) | |
pipeline = index % number_of_pipelines | |
if File.extname(path) == '.feature' | |
(test_content[0] == '#') ? | |
test_content = "# @pipeline#{pipeline}\n#{test_content}" : | |
test_content = "@pipeline#{pipeline}\n#{test_content}" | |
else | |
test_lines = test_content.lines | |
test_content = test_lines[0].gsub("do\n", ", pipeline#{pipeline}: true do\n") + test_lines[1..-1].join | |
end | |
File.open(path, 'w') { |f| f.write(test_content) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment