summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/build.rb16
-rw-r--r--app/models/ci/job_artifact.rb26
-rw-r--r--app/models/concerns/artifact_migratable.rb2
-rw-r--r--app/presenters/ci/build_presenter.rb45
4 files changed, 60 insertions, 29 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 0078ae052d2..1b749dd67d0 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -391,6 +391,10 @@ module Ci
trace.exist?
end
+ def has_test_reports?
+ job_artifacts.test_reports.any?
+ end
+
def has_old_trace?
old_trace.present?
end
@@ -453,22 +457,26 @@ module Ci
end
def erase_artifacts!
- remove_legacy_artifacts_file! if legacy_artifacts_file
- remove_legacy_artifacts_metadata! if legacy_artifacts_metadata
- job_artifacts.destroy_all
+ remove_artifacts_file!
+ remove_artifacts_metadata!
save
end
+ def erase_test_reports!
+ job_artifacts.test_reports.destroy_all
+ end
+
def erase(opts = {})
return false unless erasable?
erase_artifacts!
+ erase_test_reports!
erase_trace!
update_erased!(opts[:erased_by])
end
def erasable?
- complete? && (artifacts? || has_trace?)
+ complete? && (artifacts? || has_test_reports? || has_trace?)
end
def erased?
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb
index 414b6c4be89..c76895c8d7d 100644
--- a/app/models/ci/job_artifact.rb
+++ b/app/models/ci/job_artifact.rb
@@ -9,7 +9,8 @@ module Ci
mount_uploader :file, JobArtifactUploader
- validates :file_format, presence: true, on: :create
+ validates :file_format, presence: true, unless: :ignore_schema, on: :create
+ validate :valid_file_format?, unless: :ignore_schema, on: :create
before_save :set_size, if: :file_changed?
after_save :update_project_statistics_after_save, if: :size_changed?
after_destroy :update_project_statistics_after_destroy, unless: :project_destroyed?
@@ -18,15 +19,26 @@ module Ci
scope :with_files_stored_locally, -> { where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]) }
+ scope :test_reports, -> do
+ types = self.file_types.select { |k, _| TEST_REPORT_FILE_TYPES.include?(k) }.values
+
+ where(file_type: types)
+ end
+
delegate :exists?, :open, to: :file
enum file_type: {
archive: 1,
- archive_metadata: 2,
+ metadata: 2,
trace: 3,
junit: 4
}
+ GENERAL_ARCHIVE_FILE_TYPE = 'archive'.freeze
+ TEST_REPORT_FILE_TYPES = %w[junit].freeze
+ DEFAULT_FILE_NAMES = { junit: 'junit.xml' }.freeze
+ TYPE_AND_FORMAT_PAIRS = { archive: :zip, metadata: :gzip, trace: :raw, junit: :gzip }.freeze
+
enum file_format: {
raw: 1,
zip: 2,
@@ -37,6 +49,16 @@ module Ci
gzip: Gitlab::Ci::Build::Artifacts::GzipFileAdapter
}
+ def valid_file_format?
+ unless TYPE_AND_FORMAT_PAIRS[self.file_type&.to_sym] == self.file_format&.to_sym
+ errors.add(:file_format, 'Invalid file format with specified file type')
+ end
+ end
+
+ def ignore_schema
+ ActiveRecord::Migrator.current_version <= ::Gitlab::Ci::Trace::ARCHIVE_LEGACY_TRACES_MIGRATION_VERSION
+ end
+
def update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
diff --git a/app/models/concerns/artifact_migratable.rb b/app/models/concerns/artifact_migratable.rb
index ca9aba5ac3a..ff52ca64459 100644
--- a/app/models/concerns/artifact_migratable.rb
+++ b/app/models/concerns/artifact_migratable.rb
@@ -7,7 +7,7 @@ module ArtifactMigratable
end
def artifacts_metadata
- job_artifacts_archive_metadata&.file || legacy_artifacts_metadata
+ job_artifacts_metadata&.file || legacy_artifacts_metadata
end
def artifacts?
diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb
index 6b52c91749f..5e3829693d1 100644
--- a/app/presenters/ci/build_presenter.rb
+++ b/app/presenters/ci/build_presenter.rb
@@ -34,14 +34,31 @@ module Ci
end
def config_artifacts
- list = []
+ [].tap do |list|
+ next unless options[:artifacts]
- options.dig(:artifacts).try do |artifacts|
- list << config_artifacts_reports(artifacts.delete(:reports)) if artifacts.dig(:reports)
- list << config_artifacts_archive(artifacts) if artifacts.dig(:paths)
- end
+ options[:artifacts].except(:reports).try do |archive|
+ ::Gitlab::Ci::Config::Entry::Artifacts.new(archive).present_for_runner.tap do |runner_config|
+ unless ::Gitlab::Ci::Config::Entry::ArtifactsForRunner.new(runner_config).valid?
+ raise ArgumentError, 'General artifact config for runner is not valid'
+ end
+
+ list << runner_config
+ end
+ end
+
+ options[:artifacts].dig(:reports).try do |reports|
+ ::Gitlab::Ci::Config::Entry::Reports.new(reports).present_for_runner.tap do |runner_configs|
+ list << runner_configs.map do |runner_config|
+ unless ::Gitlab::Ci::Config::Entry::ArtifactsForRunner.new(runner_config).valid?
+ raise ArgumentError, 'Report-type artifact config for runner is not valid'
+ end
- list.flatten
+ runner_config
+ end
+ end
+ end
+ end.flatten
end
private
@@ -53,21 +70,5 @@ module Ci
def detailed_status
@detailed_status ||= subject.detailed_status(user)
end
-
- def config_artifacts_archive(artifacts)
- artifacts.merge(type: :archive, format: :zip)
- end
-
- def config_artifacts_reports(reports)
- list = []
-
- list << config_artifacts_reports_junit(reports.dig(:junit)) if reports.dig(:junit)
-
- list
- end
-
- def config_artifacts_reports_junit(junit)
- { name: 'junit.xml', paths: junit, type: :junit, format: :gzip, when: :always }
- end
end
end