diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-08-02 13:07:46 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-08-06 15:04:07 +0300 |
commit | 8441d8c6a5ab1efb57b02f9e4d4265100063926b (patch) | |
tree | 128b42a03344cd941ad993ae73ac0fac3606b465 | |
parent | 30c960d4eee9a4814e593abef8e13cd52914bd88 (diff) |
bring back debaggable fixturestest-reports-on-merge-request
17 files changed, 111 insertions, 29 deletions
diff --git a/db/fixtures/development/14_pipelines.rb b/db/fixtures/development/14_pipelines.rb index d3a63aa2a78..bdaa5e01ed9 100644 --- a/db/fixtures/development/14_pipelines.rb +++ b/db/fixtures/development/14_pipelines.rb @@ -30,6 +30,8 @@ class Gitlab::Seeder::Pipelines queued_at: 8.hour.ago, started_at: 8.hour.ago, finished_at: 7.hour.ago }, { name: 'spinach:osx', stage: 'test', status: :failed, allow_failure: true, queued_at: 8.hour.ago, started_at: 8.hour.ago, finished_at: 7.hour.ago }, + { name: 'java ant', stage: 'test', status: :failed, allow_failure: true, + queued_at: 8.hour.ago, started_at: 8.hour.ago, finished_at: 7.hour.ago }, # deploy stage { name: 'staging', stage: 'deploy', environment: 'staging', status_event: :success, @@ -41,7 +43,7 @@ class Gitlab::Seeder::Pipelines when: 'manual', status: :skipped }, # notify stage - { name: 'slack', stage: 'notify', when: 'manual', status: :created }, + { name: 'slack', stage: 'notify', when: 'manual', status: :success }, ] EXTERNAL_JOBS = [ { name: 'jenkins', stage: 'test', status: :success, @@ -54,17 +56,52 @@ class Gitlab::Seeder::Pipelines def seed! pipelines.each do |pipeline| - begin - BUILDS.each { |opts| build_create!(pipeline, opts) } - EXTERNAL_JOBS.each { |opts| commit_status_create!(pipeline, opts) } - print '.' - rescue ActiveRecord::RecordInvalid - print 'F' - ensure - pipeline.update_duration - pipeline.update_status + BUILDS.each { |opts| build_create!(pipeline, opts) } + EXTERNAL_JOBS.each { |opts| commit_status_create!(pipeline, opts) } + pipeline.update_duration + pipeline.update_status + end + end + + def create_running_pipeline_with_test_reports(ref, rspec_pattern:, ant_pattern:) + raise 'Unknown result_pattern' unless %w[pass failed-1 failed-2 failed-3].include?(rspec_pattern) + raise 'Unknown result_pattern' unless %w[pass failed-1 failed-2 failed-3].include?(ant_pattern) + + last_commit = @project.repository.commit(ref) + pipeline = create_pipeline!(@project, ref, last_commit) + + @project.merge_requests.find_by_source_branch(ref).update!(head_pipeline_id: pipeline.id) if ref != 'master' + + (0...3).each do |index| + Ci::Build.create!(name: "rspec:pg #{index} 3", stage: 'test', status: :running, project: @project, pipeline: pipeline, ref: ref).tap do |build| + path = Rails.root + "spec/fixtures/junit/#{rspec_pattern}-rspec-#{index}-3.xml.gz" + + artifacts_cache_file(path) do |file| + build.job_artifacts.create!(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end end end + + Ci::Build.create!(name: "java ant", stage: 'test', status: :running, project: @project, pipeline: pipeline, ref: ref).tap do |build| + path = Rails.root + "spec/fixtures/junit/#{ant_pattern}-ant-test.xml.gz" + + artifacts_cache_file(path) do |file| + build.job_artifacts.create!(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end + end + + pipeline.update_duration + pipeline.update_status + end + + def finish_last_pipeline(ref) + last_pipeline = @project.pipelines.where(ref: ref).last + last_pipeline.builds.update_all(status: :success) + last_pipeline.update_status + end + + def destroy_pipeline(ref) + @project.pipelines.where(ref: ref).destroy_all end private @@ -87,7 +124,9 @@ class Gitlab::Seeder::Pipelines branch = merge_request.source_branch merge_request.commits.last(4).map do |commit| - create_pipeline!(project, branch, commit) + create_pipeline!(project, branch, commit).tap do |pipeline| + merge_request.update!(head_pipeline_id: pipeline.id) + end end end @@ -98,7 +137,7 @@ class Gitlab::Seeder::Pipelines def create_pipeline!(project, ref, commit) - project.pipelines.create(sha: commit.id, ref: ref, source: :push) + project.pipelines.create!(sha: commit.id, ref: ref, source: :push) end def build_create!(pipeline, opts = {}) @@ -110,25 +149,50 @@ class Gitlab::Seeder::Pipelines # (id required), that is why we need `#tap` method instead of passing # block directly to `Ci::Build#create!`. - setup_artifacts(build) + setup_artifacts(build) if %w[build test].include?(build.stage) + setup_test_reports(build) if %w[test].include?(build.stage) setup_build_log(build) build.project.environments. find_or_create_by(name: build.expanded_environment_name) - build.save + build.save! end end def setup_artifacts(build) - return unless %w[build test].include?(build.stage) - artifacts_cache_file(artifacts_archive_path) do |file| - build.job_artifacts.build(project: build.project, file_type: :archive, file: file) + build.job_artifacts.build(project: build.project, file_type: :archive, file_format: :zip, file: file) end artifacts_cache_file(artifacts_metadata_path) do |file| - build.job_artifacts.build(project: build.project, file_type: :metadata, file: file) + build.job_artifacts.build(project: build.project, file_type: :metadata, file_format: :gzip, file: file) + end + end + + def setup_test_reports(build) + if build.ref == build.project.default_branch + if build.name.include?('rspec:linux') + artifacts_cache_file(artifacts_rspec_junit_master_path(build.name)) do |file| + build.job_artifacts.build(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end + elsif build.name.include?('java ant') + artifacts_cache_file(artifacts_ant_junit_master_path) do |file| + build.job_artifacts.build(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end + end + else + if build.name.include?('rspec:linux') + artifacts_rspec_junit_feature_path(build.name).try do |path| + artifacts_cache_file(path) do |file| + build.job_artifacts.build(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end + end + elsif build.name.include?('java ant') + artifacts_cache_file(artifacts_ant_junit_feature_path) do |file| + build.job_artifacts.build(project: build.project, file_type: :junit, file_format: :gzip, file: file) + end + end end end @@ -171,19 +235,37 @@ class Gitlab::Seeder::Pipelines Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz' end - def artifacts_cache_file(file_path) - cache_path = file_path.to_s.gsub('ci_', "p#{@project.id}_") + def artifacts_rspec_junit_master_path(build_name) + index, total = build_name.scan(/ (\d) (\d)/).first + Rails.root + "spec/fixtures/junit/junit_master_rspec_#{index}_#{total}.xml.gz" + end - FileUtils.copy(file_path, cache_path) - File.open(cache_path) do |file| - yield file - end + def artifacts_rspec_junit_feature_path(build_name) + index, total = build_name.scan(/ (\d) (\d)/).first + Rails.root + "spec/fixtures/junit/junit_feature_rspec_#{index}_#{total}.xml.gz" end -end -Gitlab::Seeder.quiet do - Project.all.sample(5).each do |project| - project_builds = Gitlab::Seeder::Pipelines.new(project) - project_builds.seed! + def artifacts_ant_junit_master_path + Rails.root + "spec/fixtures/junit/junit_master_ant.xml.gz" + end + + def artifacts_ant_junit_feature_path + Rails.root + "spec/fixtures/junit/junit_feature_ant.xml.gz" + end + + def artifacts_cache_file(file_path) + file = Tempfile.new("artifacts") + file.close + + FileUtils.copy(file_path, file.path) + + yield(UploadedFile.new(file.path, filename: File.basename(file_path))) end end + +# Gitlab::Seeder.quiet do +# Project.all.sample(5).each do |project| +# project_builds = Gitlab::Seeder::Pipelines.new(project) +# project_builds.seed! +# end +# end diff --git a/spec/fixtures/junit/failed-1-ant-test.xml.gz b/spec/fixtures/junit/failed-1-ant-test.xml.gz Binary files differnew file mode 100644 index 00000000000..401025ec1e0 --- /dev/null +++ b/spec/fixtures/junit/failed-1-ant-test.xml.gz diff --git a/spec/fixtures/junit/failed-1-rspec-0-3.xml.gz b/spec/fixtures/junit/failed-1-rspec-0-3.xml.gz Binary files differnew file mode 100644 index 00000000000..6367a42f02b --- /dev/null +++ b/spec/fixtures/junit/failed-1-rspec-0-3.xml.gz diff --git a/spec/fixtures/junit/failed-1-rspec-1-3.xml.gz b/spec/fixtures/junit/failed-1-rspec-1-3.xml.gz Binary files differnew file mode 100644 index 00000000000..0a8603d5ce5 --- /dev/null +++ b/spec/fixtures/junit/failed-1-rspec-1-3.xml.gz diff --git a/spec/fixtures/junit/failed-1-rspec-2-3.xml.gz b/spec/fixtures/junit/failed-1-rspec-2-3.xml.gz Binary files differnew file mode 100644 index 00000000000..0736228ed20 --- /dev/null +++ b/spec/fixtures/junit/failed-1-rspec-2-3.xml.gz diff --git a/spec/fixtures/junit/failed-2-ant-test.xml.gz b/spec/fixtures/junit/failed-2-ant-test.xml.gz Binary files differnew file mode 100644 index 00000000000..5861683033e --- /dev/null +++ b/spec/fixtures/junit/failed-2-ant-test.xml.gz diff --git a/spec/fixtures/junit/failed-2-rspec-0-3.xml.gz b/spec/fixtures/junit/failed-2-rspec-0-3.xml.gz Binary files differnew file mode 100644 index 00000000000..b5c84df2240 --- /dev/null +++ b/spec/fixtures/junit/failed-2-rspec-0-3.xml.gz diff --git a/spec/fixtures/junit/failed-2-rspec-1-3.xml.gz b/spec/fixtures/junit/failed-2-rspec-1-3.xml.gz Binary files differnew file mode 100644 index 00000000000..11192d76eeb --- /dev/null +++ b/spec/fixtures/junit/failed-2-rspec-1-3.xml.gz diff --git a/spec/fixtures/junit/failed-2-rspec-2-3.xml.gz b/spec/fixtures/junit/failed-2-rspec-2-3.xml.gz Binary files differnew file mode 100644 index 00000000000..02dedf30ede --- /dev/null +++ b/spec/fixtures/junit/failed-2-rspec-2-3.xml.gz diff --git a/spec/fixtures/junit/failed-3-ant-test.xml.gz b/spec/fixtures/junit/failed-3-ant-test.xml.gz Binary files differnew file mode 100644 index 00000000000..79359ae8916 --- /dev/null +++ b/spec/fixtures/junit/failed-3-ant-test.xml.gz diff --git a/spec/fixtures/junit/failed-3-rspec-0-3.xml.gz b/spec/fixtures/junit/failed-3-rspec-0-3.xml.gz Binary files differnew file mode 100644 index 00000000000..9ed62382322 --- /dev/null +++ b/spec/fixtures/junit/failed-3-rspec-0-3.xml.gz diff --git a/spec/fixtures/junit/failed-3-rspec-1-3.xml.gz b/spec/fixtures/junit/failed-3-rspec-1-3.xml.gz Binary files differnew file mode 100644 index 00000000000..baaa7945d48 --- /dev/null +++ b/spec/fixtures/junit/failed-3-rspec-1-3.xml.gz diff --git a/spec/fixtures/junit/failed-3-rspec-2-3.xml.gz b/spec/fixtures/junit/failed-3-rspec-2-3.xml.gz Binary files differnew file mode 100644 index 00000000000..03e774b1aeb --- /dev/null +++ b/spec/fixtures/junit/failed-3-rspec-2-3.xml.gz diff --git a/spec/fixtures/junit/pass-ant-test.xml.gz b/spec/fixtures/junit/pass-ant-test.xml.gz Binary files differnew file mode 100644 index 00000000000..e9cca1b0c73 --- /dev/null +++ b/spec/fixtures/junit/pass-ant-test.xml.gz diff --git a/spec/fixtures/junit/pass-rspec-0-3.xml.gz b/spec/fixtures/junit/pass-rspec-0-3.xml.gz Binary files differnew file mode 100644 index 00000000000..0ba21f43156 --- /dev/null +++ b/spec/fixtures/junit/pass-rspec-0-3.xml.gz diff --git a/spec/fixtures/junit/pass-rspec-1-3.xml.gz b/spec/fixtures/junit/pass-rspec-1-3.xml.gz Binary files differnew file mode 100644 index 00000000000..05478409dca --- /dev/null +++ b/spec/fixtures/junit/pass-rspec-1-3.xml.gz diff --git a/spec/fixtures/junit/pass-rspec-2-3.xml.gz b/spec/fixtures/junit/pass-rspec-2-3.xml.gz Binary files differnew file mode 100644 index 00000000000..54f4b1e7326 --- /dev/null +++ b/spec/fixtures/junit/pass-rspec-2-3.xml.gz |