Merge pull request #317 from abf/rosa-build:316-add-testing-repository

#316: Add "testing" repositories
This commit is contained in:
avm 2013-11-06 11:18:59 +04:00
commit 9f2d259742
15 changed files with 147 additions and 80 deletions

View File

@ -45,9 +45,11 @@ var BuildList = function(atts, dictionary) {
switch (self.status) { // See: app/helpers/build_lists_helper.rb
case <%=BuildList::BUILD_PUBLISHED%>:
case <%=BuildList::BUILD_PUBLISHED_INTO_TESTING%>:
case <%=BuildList::SUCCESS%>: self.status_color = 'success'; break
case <%=BuildList::BUILD_ERROR%>:
case <%=BuildList::FAILED_PUBLISH%>:
case <%=BuildList::FAILED_PUBLISH_INTO_TESTING%>:
case <%=BuildList::REJECTED_PUBLISH%>: self.status_color = 'error'; break
case <%=BuildList::TESTS_FAILED%>: self.status_color = 'warning'; break
default: self.status_color = 'nocolor';

View File

@ -123,6 +123,12 @@ class Projects::BuildListsController < Projects::BaseController
redirect_to :back, :notice => t("layout.build_lists.publish_#{message}")
end
def publish_into_testing
@build_list.publisher = current_user
message = @build_list.publish_into_testing ? 'success' : 'fail'
redirect_to :back, :notice => t("layout.build_lists.publish_#{message}")
end
def reject_publish
@build_list.publisher = current_user
message = @build_list.reject_publish ? 'success' : 'fail'

View File

@ -4,9 +4,9 @@ module BuildListsHelper
# See: app/assets/javascripts/angularjs/models/build_list.js.erb
def build_list_status_color(status)
case status
when BuildList::BUILD_PUBLISHED, BuildList::SUCCESS
when BuildList::BUILD_PUBLISHED, BuildList::SUCCESS, BuildList::BUILD_PUBLISHED_INTO_TESTING
'success'
when BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH
when BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH, BuildList::FAILED_PUBLISH_INTO_TESTING
'error'
when BuildList::TESTS_FAILED
'warning'
@ -60,7 +60,7 @@ module BuildListsHelper
case status
when BuildList::SUCCESS
'success'
when BuildList::DEPENDENCIES_ERROR, BuildList::BUILD_ERROR, BuildList::Item::GIT_ERROR
when BuildList::BUILD_ERROR, BuildList::Item::GIT_ERROR #, BuildList::DEPENDENCIES_ERROR
'error'
else
''

View File

@ -82,6 +82,7 @@ class Ability
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :log, :everything, :list], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can(:publish_into_testing, BuildList) { |build_list| can?(:write, build_list.project) && can?(:show, build_list.build_for_platform) }
can(:create, BuildList) {|build_list|
build_list.project.is_package &&
can?(:write, build_list.project) &&
@ -175,9 +176,10 @@ class Ability
cannot [:create, :update, :destroy, :clone], Product, :platform => {:platform_type => 'personal'}
cannot [:clone], Platform, :platform_type => 'personal'
cannot :publish, BuildList, :new_core => false
cannot [:publish, :publish_into_testing], BuildList, :new_core => false
cannot :create_container, BuildList, :new_core => false
cannot(:publish, BuildList) {|build_list| !build_list.can_publish? }
cannot(:publish_into_testing, BuildList) {|build_list| !build_list.can_publish_into_testing? }
cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build}

View File

@ -15,9 +15,9 @@ class BuildList < ActiveRecord::Base
belongs_to :publisher, :class_name => 'User'
belongs_to :advisory
belongs_to :mass_build, :counter_cache => true
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
has_many :source_packages, :class_name => "BuildList::Package", :conditions => {:package_type => 'source'}
has_many :items, :class_name => '::BuildList::Item', :dependent => :destroy
has_many :packages, :class_name => '::BuildList::Package', :dependent => :destroy
has_many :source_packages, :class_name => '::BuildList::Package', :conditions => {:package_type => 'source'}
UPDATE_TYPES = %w[bugfix security enhancement recommended newpackage]
RELEASE_UPDATE_TYPES = %w[bugfix security]
@ -57,53 +57,37 @@ class BuildList < ActiveRecord::Base
:arch_id, :project_id, :save_to_repository_id, :update_type,
:save_to_platform_id, :project_version, :auto_create_container,
:extra_repositories, :extra_build_lists, :extra_params, :external_nodes
LIVE_TIME = 4.week # for unpublished
LIVE_TIME = 4.week # for unpublished
MAX_LIVE_TIME = 3.month # for published
SUCCESS = 0
ERROR = 1
PROJECT_SOURCE_ERROR = 6
DEPENDENCIES_ERROR = 555
BUILD_ERROR = 666
BUILD_STARTED = 3000
BUILD_CANCELED = 5000
WAITING_FOR_RESPONSE = 4000
BUILD_PENDING = 2000
BUILD_PUBLISHED = 6000
BUILD_PUBLISH = 7000
FAILED_PUBLISH = 8000
REJECTED_PUBLISH = 9000
BUILD_CANCELING = 10000
TESTS_FAILED = 11000
STATUSES = [ WAITING_FOR_RESPONSE,
BUILD_CANCELED,
BUILD_PENDING,
BUILD_PUBLISHED,
BUILD_CANCELING,
BUILD_PUBLISH,
FAILED_PUBLISH,
REJECTED_PUBLISH,
SUCCESS,
BUILD_STARTED,
BUILD_ERROR,
TESTS_FAILED
].freeze
HUMAN_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_response,
BUILD_CANCELED => :build_canceled,
BUILD_CANCELING => :build_canceling,
BUILD_PENDING => :build_pending,
BUILD_PUBLISHED => :build_published,
BUILD_PUBLISH => :build_publish,
FAILED_PUBLISH => :failed_publish,
REJECTED_PUBLISH => :rejected_publish,
BUILD_ERROR => :build_error,
BUILD_STARTED => :build_started,
SUCCESS => :success,
TESTS_FAILED => :tests_failed
}.freeze
STATUSES, HUMAN_STATUSES = [], {}
[
%w(SUCCESS 0),
# %w(ERROR 1),
# %w(PROJECT_SOURCE_ERROR 6),
# %w(DEPENDENCIES_ERROR 555),
%w(BUILD_ERROR 666),
%w(BUILD_STARTED 3000),
%w(BUILD_CANCELED 5000),
%w(WAITING_FOR_RESPONSE 4000),
%w(BUILD_PENDING 2000),
%w(BUILD_PUBLISHED 6000),
%w(BUILD_PUBLISH 7000),
%w(FAILED_PUBLISH 8000),
%w(REJECTED_PUBLISH 9000),
%w(BUILD_CANCELING 10000),
%w(TESTS_FAILED 11000),
%w(BUILD_PUBLISHED_INTO_TESTING 12000),
%w(BUILD_PUBLISH_INTO_TESTING 13000),
%w(FAILED_PUBLISH_INTO_TESTING 14000)
].each do |kind, value|
value = value.to_i
const_set kind, value
STATUSES << value
HUMAN_STATUSES[value] = kind.downcase.to_sym
end
STATUSES.freeze
HUMAN_STATUSES.freeze
scope :recent, order("#{table_name}.updated_at DESC")
scope :for_extra_build_lists, lambda {|ids, current_ability, save_to_platform|
@ -205,14 +189,50 @@ class BuildList < ActiveRecord::Base
end
event :publish do
transition [:success, :failed_publish, :build_published, :tests_failed] => :build_publish
transition [:success, :failed_publish] => :failed_publish
transition [
:success,
:failed_publish,
:build_published,
:tests_failed,
:failed_publish_into_testing,
:build_published_into_testing
] => :build_publish
transition [:success, :failed_publish, :failed_publish_into_testing] => :failed_publish
end
event :reject_publish do
transition [:success, :failed_publish, :tests_failed] => :rejected_publish
transition [
:success,
:failed_publish,
:tests_failed,
:failed_publish_into_testing,
:build_published_into_testing
] => :rejected_publish
end
# ===== into testing - start
event :published_into_testing do
transition [:build_publish_into_testing, :rejected_publish] => :build_published_into_testing
end
event :fail_publish_into_testing do
transition [:build_publish_into_testing, :rejected_publish] => :failed_publish_into_testing
end
event :publish_into_testing do
transition [
:success,
:failed_publish,
:tests_failed,
:failed_publish_into_testing,
:build_published_into_testing
] => :build_publish_into_testing
transition [:success, :failed_publish, :failed_publish_into_testing] => :failed_publish_into_testing
end
# ===== into testing - end
event :build_success do
transition [:build_started, :build_canceled] => :success
end
@ -283,7 +303,7 @@ class BuildList < ActiveRecord::Base
end
def can_create_container?
[SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
[SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
end
#TODO: Share this checking on product owner.
@ -316,7 +336,7 @@ class BuildList < ActiveRecord::Base
end
def can_publish?
[SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(:id => project_id)
[SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(:id => project_id)
end
def extra_build_lists_published?

View File

@ -7,11 +7,11 @@ class BuildList::Item < ActiveRecord::Base
GIT_ERROR = 5
STATUSES = [BuildList::SUCCESS, BuildList::DEPENDENCIES_ERROR, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED]
STATUSES = [BuildList::SUCCESS, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED] # BuildList::DEPENDENCIES_ERROR
HUMAN_STATUSES = {
nil => :unknown,
GIT_ERROR => :git_error,
BuildList::DEPENDENCIES_ERROR => :dependencies_error,
# BuildList::DEPENDENCIES_ERROR => :dependencies_error,
BuildList::SUCCESS => :success,
BuildList::BUILD_STARTED => :build_started,
BuildList::BUILD_ERROR => :build_error,

View File

@ -172,6 +172,10 @@
= submit_tag t("layout.publish"),
:confirm => t('layout.confirm'), :name => 'publish',
'ng-show' => "build_list.can_publish && build_list.can_publish_in_future && build_list.extra_build_lists_published && build_list.status != #{BuildList::TESTS_FAILED} && build_list.status != #{BuildList::BUILD_PUBLISHED}"
= link_to t('layout.publish_into_testing'), publish_into_testing_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"),
:class => 'button',
'ng-show' => 'build_list.can_publish_into_testing'
- if can?(:reject_publish, @build_list)
= link_to t('layout.reject_publish'), reject_publish_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"),

View File

@ -11,6 +11,7 @@ json.build_list do
end
json.can_publish can?(:publish, @build_list)
json.can_publish_into_testing can?(:can_publish_into_testing, @build_list) && @build_list.can_publish_into_testing?
json.can_cancel @build_list.can_cancel?
json.can_create_container @build_list.can_create_container?
json.can_reject_publish @build_list.can_reject_publish?

View File

@ -40,6 +40,7 @@ en:
publish: Publish
publish_again: Publish again
publish_again_warning: Secondary publication will be able to break relationships in the repository. Be careful!
publish_into_testing: '[testing] Publish'
reject_publish: Reject
add: Add
upload: Upload

View File

@ -146,6 +146,9 @@ en:
success: Build complete
build_started: Build started
platform_pending: Platform pending
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'
log:
build_log: Build Log

View File

@ -145,6 +145,10 @@ ru:
success: собран
build_started: собирается
platform_pending: платформа в процессе создания
build_published_into_testing: '[testing] опубликован'
build_publish_into_testing: '[testing] публикуется'
failed_publish_into_testing: '[testing] ошибка публикации'
log:
build_log: Лог сборки

View File

@ -40,6 +40,7 @@ ru:
publish: Опубликовать
publish_again: Опубликовать снова
publish_again_warning: Повторная публикация может привести к нарушению зависимостей в репозитории. Будьте осторожны!
publish_into_testing: '[testing] Опубликовать'
reject_publish: Отклонить
add: Добавить
upload: Загрузить

View File

@ -277,6 +277,7 @@ Rosa::Application.routes.draw do
get :log
put :publish
put :reject_publish
put :publish_into_testing
end
end

View File

@ -20,18 +20,27 @@ module AbfWorker
create_tasks_for_resign_repositories
create_tasks_for_repository_regenerate_metadata
create_tasks_for_build_rpms
create_tasks_for_build_rpms true
end
class << self
def destroy_project_from_repository(project, repository)
if repository.platform.personal?
Platform.main.each do |main_platform|
redis.lpush PROJECTS_FOR_CLEANUP, "#{project.id}-#{repository.id}-#{main_platform.id}"
key = "#{project.id}-#{repository.id}-#{main_platform.id}"
redis.lpush PROJECTS_FOR_CLEANUP, key
gather_old_packages project.id, repository.id, main_platform.id
redis.lpush PROJECTS_FOR_CLEANUP, ('testing-' << key)
gather_old_packages project.id, repository.id, main_platform.id, true
end
else
redis.lpush PROJECTS_FOR_CLEANUP, "#{project.id}-#{repository.id}-#{repository.platform.id}"
key = "#{project.id}-#{repository.id}-#{repository.platform.id}"
redis.lpush PROJECTS_FOR_CLEANUP, key
gather_old_packages project.id, repository.id, repository.platform.id
redis.lpush PROJECTS_FOR_CLEANUP, ('testing-' << key)
gather_old_packages project.id, repository.id, repository.platform.id, true
end
end
@ -108,11 +117,12 @@ module AbfWorker
)
end
def gather_old_packages(project_id, repository_id, platform_id)
def gather_old_packages(project_id, repository_id, platform_id, testing = false)
build_lists_for_cleanup = []
status = testing ? BuildList::BUILD_PUBLISHED : BuildList::BUILD_PUBLISHED_INTO_TESTING
Arch.pluck(:id).each do |arch_id|
bl = BuildList.where(:project_id => project_id).
where(:new_core => true, :status => BuildList::BUILD_PUBLISHED).
where(:new_core => true, :status => status).
where(:save_to_repository_id => repository_id).
where(:build_for_platform_id => platform_id).
where(:arch_id => arch_id).
@ -126,8 +136,8 @@ module AbfWorker
fill_packages(old_bl, old_packages, :fullname)
}
end
redis.hset PACKAGES_FOR_CLEANUP, "#{project_id}-#{repository_id}-#{platform_id}", old_packages.to_json
key = (testing ? 'testing-' : '') << "#{project_id}-#{repository_id}-#{platform_id}"
redis.hset PACKAGES_FOR_CLEANUP, key, old_packages.to_json
end
def fill_packages(bl, results_map, field = :sha1)
@ -185,10 +195,10 @@ module AbfWorker
end
end
def create_tasks_for_build_rpms
def create_tasks_for_build_rpms(testing = false)
available_repos = BuildList.
select('MIN(updated_at) as min_updated_at, save_to_repository_id, build_for_platform_id').
where(:new_core => true, :status => BuildList::BUILD_PUBLISH).
where(:new_core => true, :status => (testing ? BuildList::BUILD_PUBLISH_INTO_TESTING : BuildList::BUILD_PUBLISH)).
group(:save_to_repository_id, :build_for_platform_id).
order(:min_updated_at).
limit(@workers_count * 2) # because some repos may be locked
@ -198,7 +208,8 @@ module AbfWorker
available_repos = available_repos.where('save_to_repository_id NOT IN (?)', locked_rep) unless locked_rep.empty?
for_cleanup = @redis.lrange(PROJECTS_FOR_CLEANUP, 0, -1).map do |key|
pr, rep, pl = *key.split('-')
next if testing && key !~ /^testing-/
rep, pl = *key.split('-').last(2)
locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i]
end.compact
@ -207,24 +218,26 @@ module AbfWorker
available_repos.each do |save_to_repository_id, build_for_platform_id|
next if RepositoryStatus.not_ready.where(:repository_id => save_to_repository_id, :platform_id => build_for_platform_id).exists?
break if counter > @workers_count
counter += 1 if create_rpm_build_task(save_to_repository_id, build_for_platform_id)
counter += 1 if create_rpm_build_task(save_to_repository_id, build_for_platform_id, testing)
end
end
def create_rpm_build_task(save_to_repository_id, build_for_platform_id)
projects_for_cleanup = @redis.lrange(PROJECTS_FOR_CLEANUP, 0, -1).
select{ |k| k =~ /#{save_to_repository_id}\-#{build_for_platform_id}$/ }
def create_rpm_build_task(save_to_repository_id, build_for_platform_id, testing)
key = "#{save_to_repository_id}-#{build_for_platform_id}"
projects_for_cleanup = @redis.lrange(PROJECTS_FOR_CLEANUP, 0, -1).select do |k|
(testing && k =~ /^testing-#{key}$/) || (!testing && k =~ /^[\d]+-#{key}$/)
end
# We should not to publish new builds into repository
# if project of builds has been removed from repository.
BuildList.where(
:project_id => projects_for_cleanup.map{ |k| k.split('-')[0] }.uniq,
:project_id => projects_for_cleanup.map{ |k| k.split('-')[testing ? 1 : 0] }.uniq,
:save_to_repository_id => save_to_repository_id,
:status => BuildList::BUILD_PUBLISH
:status => [BuildList::BUILD_PUBLISH, BuildList::BUILD_PUBLISH_INTO_TESTING]
).update_all(:status => BuildList::FAILED_PUBLISH)
build_lists = BuildList.
where(:new_core => true, :status => BuildList::BUILD_PUBLISH).
where(:new_core => true, :status => (testing ? BuildList::BUILD_PUBLISH_INTO_TESTING : BuildList::BUILD_PUBLISH)).
where(:save_to_repository_id => save_to_repository_id).
where(:build_for_platform_id => build_for_platform_id).
order(:updated_at)
@ -271,7 +284,8 @@ module AbfWorker
'REPOSITORY_NAME' => save_to_repository.name,
'TYPE' => distrib_type,
'SAVE_TO_PLATFORM' => save_to_platform.name,
'BUILD_FOR_PLATFORM' => build_for_platform.name
'BUILD_FOR_PLATFORM' => build_for_platform.name,
'TESTING' => testing
}.map{ |k, v| "#{k}=#{v}" }.join(' ')
options = {

View File

@ -52,10 +52,18 @@ module AbfWorker
update_results build_list
case status
when COMPLETED
# 'update_column' - when project of build_list has been removed from repository
build_list.published || build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
if build_list.build_publish?
# 'update_column' - when project of build_list has been removed from repository
build_list.published || build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
elsif build_list.build_publish_into_testing?
build_list.published_into_testing || build_list.update_column(:status, BuildList::BUILD_PUBLISHED_INTO_TESTING)
end
when FAILED, CANCELED
build_list.fail_publish || build_list.update_column(:status, BuildList::FAILED_PUBLISH)
if build_list.build_publish?
build_list.fail_publish || build_list.update_column(:status, BuildList::FAILED_PUBLISH)
elsif build_list.build_publish_into_testing?
build_list.fail_publish_into_testing || build_list.update_column(:status, BuildList::FAILED_PUBLISH_INTO_TESTING)
end
end
AbfWorker::BuildListsPublishTaskManager.unlock_build_list build_list
end