Merge pull request #359 from abf/rosa-build:358-add-switch-to-allow-automated-publishing-to-the-testing-repository
#358: Add switch to allow automated publishing to the testing repository
This commit is contained in:
commit
c755ec6acb
|
@ -34,11 +34,11 @@ $(document).ready(function() {
|
|||
}
|
||||
setBranchSelected(selected_option);
|
||||
}
|
||||
var build_list_auto_publish = $('#build_list_auto_publish');
|
||||
var build_list_auto_publish_status = $('#build_list_auto_publish_status');
|
||||
if (selected_option.attr('publish_without_qa') == '1') {
|
||||
build_list_auto_publish.removeAttr('disabled').attr('checked', 'checked');
|
||||
build_list_auto_publish_status.removeAttr('disabled').val('default');
|
||||
} else {
|
||||
build_list_auto_publish.removeAttr('checked').attr('disabled', 'disabled');
|
||||
build_list_auto_publish_status.val('none').attr('disabled', 'disabled');
|
||||
auto_create_container.attr('checked', 'checked');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -16,10 +16,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController
|
|||
bl_params = params[:build_list] || {}
|
||||
save_to_repository = Repository.where(id: bl_params[:save_to_repository_id]).first
|
||||
|
||||
if save_to_repository
|
||||
bl_params[:save_to_platform_id] = save_to_repository.platform_id
|
||||
bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa?
|
||||
end
|
||||
bl_params[:save_to_platform_id] = save_to_repository.platform_id if save_to_repository
|
||||
|
||||
@build_list = current_user.build_lists.new(bl_params)
|
||||
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
|
||||
|
|
|
@ -56,7 +56,6 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
@platform = @repository.platform
|
||||
|
||||
params[:build_list][:save_to_platform_id] = @platform.id
|
||||
params[:build_list][:auto_publish] = false unless @repository.publish_without_qa?
|
||||
|
||||
build_for_platforms = Repository.select(:platform_id).
|
||||
where(id: params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id)
|
||||
|
@ -192,7 +191,7 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
build_list = BuildList.find(params[:build_list_id])
|
||||
|
||||
params[:build_list] ||= {}
|
||||
keys = [:save_to_repository_id, :auto_publish, :include_repos, :extra_params,
|
||||
keys = [:save_to_repository_id, :auto_publish_status, :include_repos, :extra_params,
|
||||
:project_version, :update_type, :auto_create_container,
|
||||
:extra_repositories, :extra_build_lists, :build_for_platform_id]
|
||||
keys.each { |key| params[:build_list][key] = build_list.send(key) }
|
||||
|
|
|
@ -38,6 +38,12 @@ module BuildListsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def auto_publish_statuses
|
||||
BuildList::AUTO_PUBLISH_STATUSES.map do |status|
|
||||
[I18n.t("layout.build_lists.auto_publish_status.#{status}"), status]
|
||||
end
|
||||
end
|
||||
|
||||
def mass_build_options
|
||||
options_from_collection_for_select(
|
||||
MassBuild.recent.limit(15),
|
||||
|
|
|
@ -23,10 +23,16 @@ class BuildList < ActiveRecord::Base
|
|||
EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm]
|
||||
EXTERNAL_NODES = %w[owned everything]
|
||||
|
||||
AUTO_PUBLISH_STATUS_NONE = 'none'
|
||||
AUTO_PUBLISH_STATUS_DEFAULT = 'default'
|
||||
AUTO_PUBLISH_STATUS_TESTING = 'testing'
|
||||
AUTO_PUBLISH_STATUSES = [AUTO_PUBLISH_STATUS_NONE, AUTO_PUBLISH_STATUS_DEFAULT, AUTO_PUBLISH_STATUS_TESTING]
|
||||
|
||||
validates :project_id, :project_version, :arch, :include_repos,
|
||||
:build_for_platform_id, :save_to_platform_id, :save_to_repository_id, presence: true
|
||||
validates_numericality_of :priority, greater_than_or_equal_to: 0
|
||||
validates :external_nodes, inclusion: {in: EXTERNAL_NODES}, allow_blank: true
|
||||
validates :auto_publish_status, inclusion: {in: AUTO_PUBLISH_STATUSES}
|
||||
validates :update_type, inclusion: UPDATE_TYPES,
|
||||
unless: Proc.new { |b| b.advisory.present? }
|
||||
validates :update_type, inclusion: {in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform')},
|
||||
|
@ -50,14 +56,13 @@ class BuildList < ActiveRecord::Base
|
|||
before_validation :prepare_extra_repositories, on: :create
|
||||
before_validation :prepare_extra_build_lists, on: :create
|
||||
before_validation :prepare_extra_params, on: :create
|
||||
before_validation lambda { self.auto_publish = false if external_nodes.present?; true }, on: :create
|
||||
before_validation lambda { self.auto_create_container = false if auto_publish?; true }, on: :create
|
||||
before_validation :prepare_auto_publish_status, on: :create
|
||||
|
||||
attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash,
|
||||
: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,
|
||||
:include_testing_subrepository
|
||||
:include_testing_subrepository, :auto_publish_status
|
||||
|
||||
LIVE_TIME = 4.week # for unpublished
|
||||
MAX_LIVE_TIME = 3.month # for published
|
||||
|
@ -167,7 +172,7 @@ class BuildList < ActiveRecord::Base
|
|||
|
||||
after_transition on: [:published, :fail_publish, :build_error, :tests_failed], do: :notify_users
|
||||
after_transition on: :build_success, do: :notify_users,
|
||||
unless: lambda { |build_list| build_list.auto_publish? }
|
||||
unless: lambda { |build_list| build_list.auto_publish? || build_list.auto_publish_into_testing? }
|
||||
|
||||
event :place_build do
|
||||
transition waiting_for_response: :build_pending
|
||||
|
@ -359,6 +364,19 @@ class BuildList < ActiveRecord::Base
|
|||
return false # no new packages
|
||||
end
|
||||
|
||||
def auto_publish?
|
||||
auto_publish_status == AUTO_PUBLISH_STATUS_DEFAULT
|
||||
end
|
||||
|
||||
def auto_publish_into_testing?
|
||||
auto_publish_status == AUTO_PUBLISH_STATUS_TESTING
|
||||
end
|
||||
|
||||
# TODO: remove later
|
||||
def auto_publish=(value)
|
||||
self.auto_publish_status = value.present? ? AUTO_PUBLISH_STATUS_DEFAULT : AUTO_PUBLISH_STATUS_NONE
|
||||
end
|
||||
|
||||
def can_auto_publish?
|
||||
auto_publish? && can_publish? && has_new_packages? && can_publish_into_repository?
|
||||
end
|
||||
|
@ -609,6 +627,19 @@ class BuildList < ActiveRecord::Base
|
|||
self.extra_build_lists = bls.pluck('build_lists.id')
|
||||
end
|
||||
|
||||
def prepare_auto_publish_status
|
||||
if external_nodes.present?
|
||||
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
|
||||
end
|
||||
if auto_publish? && !save_to_repository.publish_without_qa?
|
||||
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
|
||||
end
|
||||
if auto_publish? || auto_publish_into_testing?
|
||||
self.auto_create_container = false
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def prepare_extra_params
|
||||
if extra_params.present?
|
||||
params = extra_params.slice(*BuildList::EXTRA_PARAMS)
|
||||
|
|
|
@ -185,7 +185,7 @@ class Project < ActiveRecord::Base
|
|||
bl.arch = arch
|
||||
bl.project_version = project_version
|
||||
bl.user = user
|
||||
bl.auto_publish = mass_build.auto_publish?
|
||||
bl.auto_publish_status = mass_build.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE
|
||||
bl.include_repos = include_repos
|
||||
bl.extra_repositories = mass_build.extra_repositories
|
||||
bl.extra_build_lists = mass_build.extra_build_lists
|
||||
|
@ -324,7 +324,7 @@ class Project < ActiveRecord::Base
|
|||
bl.arch_id = arch_id
|
||||
bl.project_version = p.project_version_for(platform, platform)
|
||||
bl.user = user
|
||||
bl.auto_publish = p_to_r.auto_publish?
|
||||
bl.auto_publish_status = p_to_r.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE
|
||||
bl.save_to_repository = repository
|
||||
bl.include_repos = [repository.id, platform.repositories.main.first.try(:id)].uniq.compact
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ json.build_list do
|
|||
json.(@build_list, :id, :container_status, :status, :duration)
|
||||
json.(@build_list, :update_type, :priority, :new_core)
|
||||
json.(@build_list, :advisory, :mass_build)
|
||||
json.(@build_list, :auto_publish, :package_version, :commit_hash, :last_published_commit_hash, :auto_create_container)
|
||||
json.(@build_list, :auto_publish_status, :package_version, :commit_hash, :last_published_commit_hash, :auto_create_container)
|
||||
json.build_log_url log_build_list_path(@build_list)
|
||||
|
||||
if @build_list.container_published?
|
||||
|
|
|
@ -43,7 +43,11 @@
|
|||
.both
|
||||
|
||||
%h3= t("activerecord.attributes.build_list.preferences")
|
||||
- [:auto_publish, :auto_create_container, :include_testing_subrepository].each do |kind|
|
||||
- selected = params[:build_list].try(:[], :auto_publish_status) ? {selected: params[:build_list][:auto_publish_status]} : {}
|
||||
= f.select :auto_publish_status, auto_publish_statuses, selected
|
||||
= f.label :auto_publish_status
|
||||
.both
|
||||
- %i(auto_create_container include_testing_subrepository).each do |kind|
|
||||
.both
|
||||
- checked, field = params[:build_list].try(:[], kind), "build_list[#{kind}]"
|
||||
= hidden_field_tag field, false, id: nil
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
{{ update_type_errors }}
|
||||
.both
|
||||
.both
|
||||
.leftlist= t("activerecord.attributes.build_list.auto_publish")
|
||||
.rightlist= t("layout.#{@build_list.auto_publish}_")
|
||||
.leftlist= t("activerecord.attributes.build_list.auto_publish_status")
|
||||
.rightlist= t("layout.build_lists.auto_publish_status.#{@build_list.auto_publish_status}")
|
||||
.both
|
||||
.leftlist= t("activerecord.attributes.build_list.auto_create_container")
|
||||
.rightlist= t("layout.#{@build_list.auto_create_container?}_")
|
||||
|
|
|
@ -27,7 +27,7 @@ en:
|
|||
save_to_repository: Save to repository
|
||||
build_for_platform: Build for platform
|
||||
update_type: Update type
|
||||
auto_publish: Automated publishing
|
||||
auto_publish_status: Automated publishing
|
||||
project_version: Version
|
||||
user: User
|
||||
publisher: Publisher
|
||||
|
@ -135,6 +135,11 @@ en:
|
|||
git_error: Git error
|
||||
build_canceled: Build canceled
|
||||
|
||||
auto_publish_status:
|
||||
none: None
|
||||
default: Default
|
||||
testing: Into 'testing'
|
||||
|
||||
statuses:
|
||||
build_lists: All
|
||||
build_error: Build error
|
||||
|
|
|
@ -27,7 +27,7 @@ ru:
|
|||
save_to_repository: Сохранить в репозиторий
|
||||
build_for_platform: Собрано для платформы
|
||||
update_type: Критичность обновления
|
||||
auto_publish: Автоматическая публикация
|
||||
auto_publish_status: Автоматическая публикация
|
||||
project_version: Версия
|
||||
user: Пользователь
|
||||
publisher: Публикатор
|
||||
|
@ -134,6 +134,11 @@ ru:
|
|||
git_error: проблема с гит
|
||||
build_canceled: сборка отменена
|
||||
|
||||
auto_publish_status:
|
||||
none: Нет
|
||||
default: По умолчанию
|
||||
testing: В 'testing'
|
||||
|
||||
statuses:
|
||||
build_lists: Всего
|
||||
build_error: ошибка сборки
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
class AddAutoPublishStatusToBuildList < ActiveRecord::Migration
|
||||
|
||||
class BuildList < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
# Make existing build_lists 'none', but default to 'default' in the future.
|
||||
add_column :build_lists, :auto_publish_status, :string, default: 'none', null: false
|
||||
BuildList.where(auto_publish: true).update_all(auto_publish_status: :default)
|
||||
change_column :build_lists, :auto_publish_status, :string, default: 'default', null: false
|
||||
remove_column :build_lists, :auto_publish
|
||||
end
|
||||
|
||||
def down
|
||||
# Make existing build_lists false, but default to true in the future.
|
||||
add_column :build_lists, :auto_publish, :boolean, default: false
|
||||
BuildList.where(auto_publish_status: :default).update_all(auto_publish: true)
|
||||
change_column :build_lists, :auto_publish, :boolean, default: true
|
||||
remove_column :build_lists, :auto_publish_status
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20140217192640) do
|
||||
ActiveRecord::Schema.define(:version => 20140219191644) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -122,10 +122,9 @@ ActiveRecord::Schema.define(:version => 20140217192640) do
|
|||
t.integer "save_to_platform_id"
|
||||
t.text "include_repos"
|
||||
t.integer "user_id"
|
||||
t.boolean "auto_publish", :default => true
|
||||
t.string "package_version"
|
||||
t.string "commit_hash"
|
||||
t.integer "priority", :default => 0, :null => false
|
||||
t.integer "priority", :default => 0, :null => false
|
||||
t.datetime "started_at"
|
||||
t.integer "duration"
|
||||
t.integer "advisory_id"
|
||||
|
@ -144,6 +143,7 @@ ActiveRecord::Schema.define(:version => 20140217192640) do
|
|||
t.string "external_nodes"
|
||||
t.integer "builder_id"
|
||||
t.boolean "include_testing_subrepository"
|
||||
t.string "auto_publish_status", :default => "default", :null => false
|
||||
end
|
||||
|
||||
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"
|
||||
|
|
|
@ -21,7 +21,11 @@ module AbfWorker
|
|||
case status
|
||||
when COMPLETED
|
||||
subject.build_success
|
||||
subject.now_publish if subject.can_auto_publish?
|
||||
if subject.can_auto_publish?
|
||||
subject.now_publish
|
||||
elsif subject.auto_publish_into_testing?
|
||||
subject.now_publish_into_testing
|
||||
end
|
||||
when FAILED
|
||||
subject.build_error
|
||||
item.update_attributes({status: BuildList::BUILD_ERROR})
|
||||
|
|
|
@ -19,7 +19,7 @@ describe BuildList do
|
|||
let!(:user) { FactoryGirl.create(:user) }
|
||||
let!(:build_list) { FactoryGirl.create(:build_list,
|
||||
user: user,
|
||||
auto_publish: false) }
|
||||
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_NONE) }
|
||||
let!(:build_list_package) { FactoryGirl.create(:build_list_package,
|
||||
build_list: build_list,
|
||||
project: build_list.project) }
|
||||
|
@ -44,7 +44,7 @@ describe BuildList do
|
|||
end
|
||||
|
||||
it "gets notification by email when auto_publish and status - Build error" do
|
||||
build_list.update_attributes(auto_publish: true)
|
||||
build_list.update_attributes(auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT)
|
||||
build_list.build_error
|
||||
should have(1).item
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ describe BuildList do
|
|||
end
|
||||
|
||||
it "gets notification by email when auto_publish and status - Failed publish" do
|
||||
build_list.update_attributes({auto_publish: true, status: BuildList::BUILD_PUBLISH}, without_protection: true)
|
||||
build_list.update_attributes({auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT, status: BuildList::BUILD_PUBLISH}, without_protection: true)
|
||||
build_list.fail_publish
|
||||
should have(1).item
|
||||
end
|
||||
|
@ -68,13 +68,19 @@ describe BuildList do
|
|||
end
|
||||
|
||||
it "gets notification by email when auto_publish and status - Build published" do
|
||||
build_list.update_attributes({auto_publish: true, status: BuildList::BUILD_PUBLISH}, without_protection: true)
|
||||
build_list.update_attributes({auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT, status: BuildList::BUILD_PUBLISH}, without_protection: true)
|
||||
build_list.published
|
||||
should have(1).item
|
||||
end
|
||||
|
||||
it "doesn't get notification by email when auto_publish and status - Build complete" do
|
||||
build_list.update_attributes(auto_publish: true)
|
||||
build_list.update_attributes(auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT)
|
||||
build_list.build_success
|
||||
should have(:no).items
|
||||
end
|
||||
|
||||
it "doesn't get notification by email when auto_publish_into_testing and status - Build complete" do
|
||||
build_list.update_attributes(auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_TESTING)
|
||||
build_list.build_success
|
||||
should have(:no).items
|
||||
end
|
||||
|
@ -141,9 +147,9 @@ describe BuildList do
|
|||
it "doesn't get 2 notification by email when user associated to project and created task" do
|
||||
project = FactoryGirl.create(:project_with_commit, owner: user)
|
||||
bl = FactoryGirl.create(:build_list_with_attaching_project,
|
||||
user: user,
|
||||
auto_publish: true,
|
||||
project: project
|
||||
user: user,
|
||||
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT,
|
||||
project: project
|
||||
)
|
||||
FactoryGirl.create(:build_list_package, build_list: bl, project: bl.project)
|
||||
bl.update_attributes({commit_hash: bl.project.repo.commits('master').last.id,
|
||||
|
@ -156,8 +162,8 @@ describe BuildList do
|
|||
|
||||
context '#has_new_packages?' do
|
||||
let!(:build_list) { FactoryGirl.create( :build_list,
|
||||
status: BuildList::SUCCESS,
|
||||
auto_publish: true) }
|
||||
status: BuildList::SUCCESS,
|
||||
auto_publish_status: BuildList::AUTO_PUBLISH_STATUS_DEFAULT) }
|
||||
let!(:build_list_package) { FactoryGirl.create( :build_list_package,
|
||||
build_list: build_list,
|
||||
version: '3.1.12',
|
||||
|
|
Loading…
Reference in New Issue