Class: Tes::Request::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Tes::Request::RakeTask
- Defined in:
- lib/tes/request/rake_task.rb
Constant Summary collapse
- SUPPORT_FILE_TYPES =
[:yaml, :yml, :json, :properties]
Instance Method Summary collapse
- #gen_job_ci_params(job) ⇒ Object
- #get_job_env_profile_str(job, split = ';') ⇒ Object
- #get_job_rspec_run_args_str(job, split = ' ') ⇒ Object
-
#initialize(name, type) ⇒ RakeTask
constructor
A new instance of RakeTask.
- #save_job_files(jobs, target_dir, file_type) ⇒ Object
- #save_job_properties(job_cfg, save_file) ⇒ Object
- #spec_tag_param_str(tags) ⇒ Object
Constructor Details
#initialize(name, type) ⇒ RakeTask
Returns a new instance of RakeTask.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tes/request/rake_task.rb', line 10 def initialize(name, type) desc "Generate RSpec distribute jobs #{type} file for CI" task name, [:project_dir, :type, :count, :version, :lang] do |_, task_args| rspec_distribute = ::Tes::Request::RSpec::Distribute.new(task_args[:project_dir]) jobs = rspec_distribute.distribute_jobs(task_args[:type], task_args[:count].to_i, task_args[:version], task_args[:lang]) target_dir = File.join(task_args[:project_dir], '.ci_jobs') save_job_files(jobs, target_dir, type) end end |
Instance Method Details
#gen_job_ci_params(job) ⇒ Object
87 88 89 |
# File 'lib/tes/request/rake_task.rb', line 87 def gen_job_ci_params(job) {'RSPEC_PARAM' => get_job_rspec_run_args_str(job), 'REQUEST_ASKS' => get_job_env_profile_str(job)} end |
#get_job_env_profile_str(job, split = ';') ⇒ Object
83 84 85 |
# File 'lib/tes/request/rake_task.rb', line 83 def get_job_env_profile_str(job, split=';') job[:profile].to_s(split) end |
#get_job_rspec_run_args_str(job, split = ' ') ⇒ Object
77 78 79 80 81 |
# File 'lib/tes/request/rake_task.rb', line 77 def get_job_rspec_run_args_str(job, split=' ') = spec_tag_param_str(job[:tag]) paths_str = job[:specs].join(split) ? ( + split + paths_str) : paths_str end |
#save_job_files(jobs, target_dir, file_type) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tes/request/rake_task.rb', line 36 def save_job_files(jobs, target_dir, file_type) unless SUPPORT_FILE_TYPES.include?(file_type) raise(ArgumentError, "Not supported file type:#{file_type}!") end job_configs_for_ci = jobs.map { |j| gen_job_ci_params(j) } FileUtils.rm_rf(target_dir) FileUtils.mkdir(target_dir) case file_type when :json save_file = File.join(target_dir, 'ci_tasks.json') File.open(save_file, 'w') { |f| f.write job_configs_for_ci.to_json } puts "Generated #{jobs.size} jobs, Stored in:#{save_file} ." when :yml, :yaml save_file = File.join(target_dir, 'ci_tasks.yml') File.open(save_file, 'w') { |f| f.write job_configs_for_ci.to_yaml } puts "Generated #{jobs.size} jobs, Stored in:#{save_file} ." when :properties job_configs_for_ci.each_with_index do |params, i| file = File.join(target_dir, "#{i}.properties") save_job_properties(params, file) end puts "Generated #{jobs.size} jobs, Stored in:#{target_dir}/*.properties ." end end |
#save_job_properties(job_cfg, save_file) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tes/request/rake_task.rb', line 62 def save_job_properties(job_cfg, save_file) # context = ["# gen at #{Time.now}"] JavaProperties.write(job_cfg, save_file) # # context = ["# gen at #{Time.now}"] # tag_opt_cli_args = spec_tag_param_str(job_cfg[:tag]) # rspec_param = if tag_opt_cli_args # "RSPEC_PARAM = #{tag_opt_cli_args} \\\n\t#{piece[:files].join(" \\\n\t")}" # else # "RSPEC_PARAM = #{piece[:files].join(" \\\n\t")}" # end # context << "REQUEST_ASKS = #{piece[:profile].to_s(";\\\n\t")}" # File.open(file, 'w') { |f| f.write context.join("\n") } end |
#spec_tag_param_str(tags) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tes/request/rake_task.rb', line 23 def spec_tag_param_str() case when Array .map { |t| "--tag #{t}" }.join(' ') when String "--tag #{}" when nil nil else raise("不支持的类型:#{.class}") end end |