From 6f97b8dc15743848cab9e7150a9b9b04fa6dbd5b Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 23 Jul 2014 02:43:50 +0400 Subject: [PATCH] #416: Handle ExcludeArch and ExclusiveArch tags --- app/models/build_list.rb | 40 ++++++++++++++++++++++++- app/models/concerns/git.rb | 8 +++++ app/models/project.rb | 3 +- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 2 +- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8c397cbc8..69b3acc62 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,7 +105,8 @@ class BuildList < ActiveRecord::Base %w(TESTS_FAILED 11000), %w(BUILD_PUBLISHED_INTO_TESTING 12000), %w(BUILD_PUBLISH_INTO_TESTING 13000), - %w(FAILED_PUBLISH_INTO_TESTING 14000) + %w(FAILED_PUBLISH_INTO_TESTING 14000), + %w(UNPERMITTED_ARCH 15000) ].each do |kind, value| value = value.to_i const_set kind, value @@ -189,6 +190,10 @@ class BuildList < ActiveRecord::Base transition waiting_for_response: :build_pending end + event :unpermitted_arch do + transition build_pending: :unpermitted_arch + end + event :rerun_tests do transition %i(success tests_failed) => :rerun_tests end @@ -622,8 +627,41 @@ class BuildList < ActiveRecord::Base end end + def add_job_to_abf_worker_queue + if permitted_arch? + super + else + unpermitted_arch + end + end + protected + def permitted_arch? + blob, raw = project.find_blob_and_raw_of_spec_file(commit_hash) + return true unless blob + + permitted = true + file = Tempfile.new(blob.name, File.join(Rails.root, 'tmp')) + filename = file.path + begin + file.puts raw.content + file.rewind + exclusivearch = `rpm -q --qf="[%{EXCLUSIVEARCH}\n]" --specfile #{file.path}` + exitstatus = $?.exitstatus + permitted = false if exitstatus == 0 && exclusivearch.present? && exclusivearch !~ /^#{arch.name}$/ + + excludearch = `rpm -q --qf="[%{EXCLUDEARCH}\n]" --specfile #{file.path}` + exitstatus = $?.exitstatus + permitted = false if exitstatus == 0 && excludearch.present? && excludearch =~ /^#{arch.name}$/ + ensure + file.close + file.unlink # deletes the temp file + end + + permitted + end + def create_container Resque.enqueue(BuildLists::CreateContainerJob, id) end diff --git a/app/models/concerns/git.rb b/app/models/concerns/git.rb index 3565ea25e..9a40a24fa 100644 --- a/app/models/concerns/git.rb +++ b/app/models/concerns/git.rb @@ -32,6 +32,14 @@ module Git repo.tags.map(&:name) + repo.branches.map(&:name) end + def find_blob_and_raw_of_spec_file(project_version) + blob = repo.tree(project_version).contents.find{ |n| n.is_a?(Grit::Blob) && n.name =~ /.spec$/ } + return unless blob + + raw = Grit::GitRuby::Repository.new(repo.path).get_raw_object_by_sha1(blob.id) + [blob, raw] + end + def create_branch(new_ref, from_ref, user) return false if new_ref.blank? || from_ref.blank? || !(from_commit = repo.commit(from_ref)) status, out, err = repo.git.native(:branch, {process_info: true}, new_ref, from_commit.id) diff --git a/app/models/project.rb b/app/models/project.rb index b134f34cc..73e3e94b3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -337,10 +337,9 @@ class Project < ActiveRecord::Base end def increase_release_tag(project_version, user, message) - blob = repo.tree(project_version).contents.find{ |n| n.is_a?(Grit::Blob) && n.name =~ /.spec$/ } + blob, raw = find_blob_and_raw_of_spec_file(project_version) return unless blob - raw = Grit::GitRuby::Repository.new(repo.path).get_raw_object_by_sha1(blob.id) content = self.class.replace_release_tag raw.content return if content == raw.content diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 978c94c89..ff68935ee 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -173,6 +173,7 @@ en: build_published_into_testing: '[testing] Build has been published' build_publish_into_testing: '[testing] Build is being published' failed_publish_into_testing: '[testing] Publishing error' + unpermitted_arch: Unpermitted architecture log: build_log: Build Log diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 48a74d3b1..0238cab39 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -172,7 +172,7 @@ ru: build_published_into_testing: '[testing] опубликован' build_publish_into_testing: '[testing] публикуется' failed_publish_into_testing: '[testing] ошибка публикации' - + unpermitted_arch: Недопустимая архитектура log: build_log: Лог сборки