diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-06-28 15:10:26 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-28 15:10:26 +0900 |
commit | 09440757ac4ee89a7ac7409556556c3736aaabfc (patch) | |
tree | 8a3334bbdc4542e7358e80e069ac22e31a46a0ab | |
parent | cf0b459b879d82a8dacda5ca737274d134c39214 (diff) | |
download | gitlab-ce-idea-how-to-present-junit-report.tar.gz |
Rough outline about how to present junit.xmlidea-how-to-present-junit-report
-rw-r--r-- | app/controllers/projects/jobs_controller.rb | 19 | ||||
-rw-r--r-- | app/models/ci/job_artifact.rb | 36 | ||||
-rw-r--r-- | app/workers/cache_raw_artifact_worker.rb | 30 |
3 files changed, 85 insertions, 0 deletions
diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index 63f0aea3195..85472629d94 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -63,6 +63,25 @@ class Projects::JobsController < Projects::ApplicationController end end + def junit + return respond_404 unless @build.job_artifacts_junit + + respond_to do |format| + format.json do + if @build.job_artifacts_junit.raw? + raw_path = @build.job_artifacts_junit.file.raw_path + else + @build.job_artifacts_junit.decompress! unless @build.job_artifacts_junit.decompressing? + end + + render json: { + id: @build.id, + path: raw_path + } + end + end + end + def trace build.trace.read do |stream| respond_to do |format| diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index 3b952391b7e..9228005393e 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -50,6 +50,42 @@ module Ci end end + def raw? + connection.get_object(bucket_name, raw_name) # This is inefficient + rescue Excon::File::NotFound + false + end + + def cache!(file) + connection.put_object(bucket_name, raw_name, file) + end + + def raw_path + connection.get_object_https_url(bucket_name, raw_name) + end + + def raw_name + "tmp/cache/builds/#{job_id}/artifacts/#{id}/#{file_type}/raw" + end + + def bucket_name + Gitlab.config.artifacts.object_store.remote_directory + end + + def connection + ::Fog::Storage.new(Gitlab.config.artifacts) + end + + def decompressing? + Gitlab::Redis::Cache.with do |redis| + redis.exist(raw_name) + end + end + + def decompress! + DecompressZipArtifactWorker.perform_async(id) + end + private def set_size diff --git a/app/workers/cache_raw_artifact_worker.rb b/app/workers/cache_raw_artifact_worker.rb new file mode 100644 index 00000000000..9bf611c5435 --- /dev/null +++ b/app/workers/cache_raw_artifact_worker.rb @@ -0,0 +1,30 @@ +class CacheRawArtifactWorker + include ApplicationWorker + include PipelineBackgroundQueue + + def perform(job_artifact_id) + state_flag do + Ci::JobArtifact.find_by(id: job_artifact_id).compressed.try do |job_artifact| + job_artifact.file.use_file do |artifact_path| + local_cache_path = "path/to/cache" # TODO: + extract_zip_archive!(from: artifact_path, to: local_cache_path) + job_artifact.cache!(local_cache_path) + end + end + end + end + + def state_flag(&block) + Gitlab::Redis::Cache.with do |redis| + return if redis.exist(job_artifact.raw_name) + + redis.set(job_artifact.raw_name, ttl: 1.week) + end + + yield + ensure + Gitlab::Redis::Cache.with do |redis| + redis.del(job_artifact.raw_name) + end + end +end |