#156: added MassBuild for personal platforms

This commit is contained in:
Vokhmin Alexey V 2013-06-03 19:20:23 +04:00
parent 01981803ee
commit ff04874278
12 changed files with 92 additions and 52 deletions

View File

@ -20,7 +20,7 @@ class Platforms::MassBuildsController < Platforms::BaseController
if mass_build.save if mass_build.save
redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success")) redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success"))
else else
@auto_publish_selected = params[:auto_publish].present? @auto_publish_selected, @use_save_to_repository = params[:auto_publish].present?, params[:use_save_to_repository].present?
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
flash[:warning] = mass_build.errors.full_messages.join('. ') flash[:warning] = mass_build.errors.full_messages.join('. ')
flash[:error] = t("flash.platform.build_all_error") flash[:error] = t("flash.platform.build_all_error")
@ -39,7 +39,7 @@ class Platforms::MassBuildsController < Platforms::BaseController
def index def index
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
@auto_publish_selected = true @auto_publish_selected = @use_save_to_repository = true
end end
def cancel def cancel

View File

@ -26,7 +26,7 @@ class Ability
# Platforms block # Platforms block
can [:show, :members, :advisories], Platform, :visibility => 'open' can [:show, :members, :advisories], Platform, :visibility => 'open'
can :platforms_for_build, Platform, :visibility => 'open', :platform_type => 'main' can :platforms_for_build, Platform, :visibility => 'open', :platform_type => 'main'
can(:get_list, MassBuild) {|mass_build| mass_build.platform.main? && can?(:show, mass_build.platform) } can(:get_list, MassBuild) {|mass_build| can?(:show, mass_build.save_to_platform) }
can [:read, :projects_list, :projects], Repository, :platform => {:visibility => 'open'} can [:read, :projects_list, :projects], Repository, :platform => {:visibility => 'open'}
can :read, Product, :platform => {:visibility => 'open'} can :read, Product, :platform => {:visibility => 'open'}
@ -105,8 +105,8 @@ class Ability
can([:update, :destroy], Platform) {|platform| owner?(platform) } can([:update, :destroy], Platform) {|platform| owner?(platform) }
can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) } can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
can([:create, :publish], MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && mass_build.platform.main?} can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)}
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build && mass_build.platform.main?} can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
@ -166,8 +166,7 @@ class Ability
cannot :create_container, BuildList, :new_core => false cannot :create_container, BuildList, :new_core => false
cannot(:publish, BuildList) {|build_list| !build_list.can_publish? } cannot(:publish, BuildList) {|build_list| !build_list.can_publish? }
cannot([:get_list, :create, :publish], MassBuild) {|mass_build| mass_build.platform.personal?} cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build}
cannot(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build}
cannot(:regenerate_metadata, Repository) {|repository| !repository.platform.main?} cannot(:regenerate_metadata, Repository) {|repository| !repository.platform.main?}

View File

@ -1,20 +1,22 @@
class MassBuild < ActiveRecord::Base class MassBuild < ActiveRecord::Base
belongs_to :platform belongs_to :build_for_platform, :class_name => 'Platform'
belongs_to :save_to_platform, :class_name => 'Platform'
belongs_to :user belongs_to :user
has_many :build_lists, :dependent => :destroy has_many :build_lists, :dependent => :destroy
scope :recent, order("#{table_name}.created_at DESC") scope :recent, order("#{table_name}.created_at DESC")
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } scope :by_platform, lambda { |platform| where(:save_to_platform_id => platform.id) }
scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME)
attr_accessor :arches attr_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list attr_accessible :arches, :auto_publish, :projects_list
validates :platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true
validates_inclusion_of :auto_publish, :in => [true, false] validates_inclusion_of :auto_publish, :in => [true, false]
after_create :build_all after_create :build_all
before_validation :set_data before_validation :set_data, :on => :create
before_validation :set_build_for_platform, :on => :create
COUNT_STATUSES = [ COUNT_STATUSES = [
:build_lists, :build_lists,
@ -36,12 +38,12 @@ class MassBuild < ActiveRecord::Base
next if name.blank? next if name.blank?
name.chomp!; name.strip! name.chomp!; name.strip!
if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name) if project = Project.joins(:repositories).where('repositories.id in (?)', save_to_platform.repository_ids).find_by_name(name)
begin begin
return if self.reload.stop_build return if self.reload.stop_build
arches_list.each do |arch| arches_list.each do |arch|
rep = (project.repositories & platform.repositories).first rep_id = (project.repository_ids & save_to_platform.repository_ids).first
project.build_for(platform, rep.id, user, arch, auto_publish, self.id, 0) project.build_for(build_for_platform, save_to_platform, rep_id, user, arch, auto_publish, self, 0)
end end
rescue RuntimeError, Exception rescue RuntimeError, Exception
end end
@ -98,10 +100,15 @@ class MassBuild < ActiveRecord::Base
end end
end end
def set_data def set_build_for_platform
if new_record? if save_to_platform && save_to_platform.main?
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" self.build_for_platform = save_to_platform
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") self.use_save_to_repository = true
end end
end end
def set_data
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}"
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
end
end end

View File

@ -16,7 +16,7 @@ class Platform < ActiveRecord::Base
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
has_many :mass_builds has_many :mass_builds, :foreign_key => :save_to_platform_id
validates :description, :presence => true validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}

View File

@ -146,27 +146,29 @@ class Project < ActiveRecord::Base
#path #share by NFS #path #share by NFS
end end
def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0) def build_for(build_for_platform, save_to_platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build = nil, priority = 0)
# Select main and project platform repository(contrib, non-free and etc) # Select main and project platform repository(contrib, non-free and etc)
# If main does not exist, will connect only project platform repository # If main does not exist, will connect only project platform repository
# If project platform repository is main, only main will be connect # If project platform repository is main, only main will be connect
main_rep_id = platform.repositories.find_by_name('main').try(:id) main_rep_id = build_for_platform.repositories.find_by_name('main').try(:id)
build_reps_ids = [main_rep_id, repository_id].compact.uniq include_repos = [main_rep_id] << (save_to_platform.main? ? repository_id : nil).compact.uniq
project_version = repo.commits("#{platform.name}").try(:first).try(:id) ? project_version = repo.commits("#{platform.name}").try(:first).try(:id) ?
platform.name : 'master' platform.name : 'master'
build_list = build_lists.build do |bl| build_list = build_lists.build do |bl|
bl.save_to_platform = platform bl.save_to_platform = platform
bl.build_for_platform = platform bl.build_for_platform = platform
bl.update_type = 'newpackage' bl.update_type = 'newpackage'
bl.arch = arch bl.arch = arch
bl.project_version = project_version bl.project_version = project_version
bl.user = user bl.user = user
bl.auto_publish = auto_publish bl.auto_publish = auto_publish
bl.include_repos = build_reps_ids bl.include_repos = include_repos
bl.priority = priority bl.extra_repositories = [repository_id] if save_to_platform.personal? && mass_build.use_save_to_repository?
bl.mass_build_id = mass_build_id bl.priority = priority
bl.save_to_repository_id = repository_id bl.mass_build_id = mass_build.try(:id)
bl.save_to_repository_id = repository_id
end end
build_list.save build_list.save
end end

View File

@ -13,7 +13,7 @@
- if can? :show, @platform - if can? :show, @platform
%li{:class => (act == :index && contr == :maintainers) ? 'active' : nil} %li{:class => (act == :index && contr == :maintainers) ? 'active' : nil}
= link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform) = link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform)
- if @platform.main? && can?(:show, @platform) - if can?(:show, @platform)
%li{:class => (contr == :mass_builds && [:index, :create].include?(act)) ? 'active' : ''} %li{:class => (contr == :mass_builds && [:index, :create].include?(act)) ? 'active' : ''}
= link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform) = link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform)
- if can? :read, @platform.products.build - if can? :read, @platform.products.build

View File

@ -10,8 +10,16 @@
= check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}"
= label_tag "arches_#{arch.id}", arch.name = label_tag "arches_#{arch.id}", arch.name
.both .both
- if @platform.personal?
%h3= t('activerecord.attributes.build_list.build_for_platform')
- platforms = Platform.main.select{ |p| p.repository_ids.size > 0 }
= select_tag 'build_for_platform', options_from_collection_for_select(platforms, :id, :name), :include_blank => false
.both
%h3= t("activerecord.attributes.build_list.preferences") %h3= t("activerecord.attributes.build_list.preferences")
.both.bottom_20 .both
= check_box_tag :auto_publish, true, @auto_publish_selected, :id => 'auto_publish' = check_box_tag :auto_publish, true, @auto_publish_selected, :id => 'auto_publish'
= label_tag :auto_publish, t('activerecord.attributes.build_list.auto_publish') = label_tag :auto_publish, t('activerecord.attributes.build_list.auto_publish')
- if @platform.personal?
= check_box_tag :use_save_to_repository, true, @use_save_to_repository, :id => 'auto_publish'
= label_tag :use_save_to_repository, t('activerecord.attributes.mass_build.use_save_to_repository')
.both .both

View File

@ -21,6 +21,7 @@ en:
created_at: Created created_at: Created
updated_at: Updated updated_at: Updated
arch_names: Architectures arch_names: Architectures
use_save_to_repository: Use personal repository for assembly
user: User user: User
auto_publish: Auto Publish auto_publish: Auto Publish
repositories: Repositories repositories: Repositories

View File

@ -21,6 +21,7 @@ ru:
created_at: Создан created_at: Создан
updated_at: Обновлен updated_at: Обновлен
arch_names: Архитектуры arch_names: Архитектуры
use_save_to_repository: Использовать персональный репозиторий для сборки
user: Пользователь user: Пользователь
auto_publish: Авто Публикация auto_publish: Авто Публикация
repositories: Репозитории repositories: Репозитории

View File

@ -0,0 +1,20 @@
class AddSaveToPlatformToMassBuild < ActiveRecord::Migration
class MassBuild < ActiveRecord::Base
end
def up
add_column :mass_builds, :save_to_platform_id, :integer
MassBuild.update_all('save_to_platform_id = platform_id')
change_column :mass_builds, :save_to_platform_id, :integer, :null => false
change_column :mass_builds, :platform_id, :integer, :null => false
rename_column :mass_builds, :platform_id, :build_for_platform_id
add_column :mass_builds, :use_save_to_repository, :boolean
end
def down
remove_column :mass_builds, :save_to_platform_id
remove_column :mass_builds, :use_save_to_repository
rename_column :mass_builds, :build_for_platform_id, :platform_id
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130527181351) do ActiveRecord::Schema.define(:version => 20130603124853) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -271,26 +271,28 @@ ActiveRecord::Schema.define(:version => 20130527181351) do
add_index "labels", ["project_id"], :name => "index_labels_on_project_id" add_index "labels", ["project_id"], :name => "index_labels_on_project_id"
create_table "mass_builds", :force => true do |t| create_table "mass_builds", :force => true do |t|
t.integer "platform_id" t.integer "build_for_platform_id", :null => false
t.string "name" t.string "name"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "arch_names" t.string "arch_names"
t.integer "user_id" t.integer "user_id"
t.boolean "auto_publish", :default => false, :null => false t.boolean "auto_publish", :default => false, :null => false
t.integer "build_lists_count", :default => 0, :null => false t.integer "build_lists_count", :default => 0, :null => false
t.integer "build_published_count", :default => 0, :null => false t.integer "build_published_count", :default => 0, :null => false
t.integer "build_pending_count", :default => 0, :null => false t.integer "build_pending_count", :default => 0, :null => false
t.integer "build_started_count", :default => 0, :null => false t.integer "build_started_count", :default => 0, :null => false
t.integer "build_publish_count", :default => 0, :null => false t.integer "build_publish_count", :default => 0, :null => false
t.integer "build_error_count", :default => 0, :null => false t.integer "build_error_count", :default => 0, :null => false
t.boolean "stop_build", :default => false, :null => false t.boolean "stop_build", :default => false, :null => false
t.text "projects_list" t.text "projects_list"
t.integer "missed_projects_count", :default => 0, :null => false t.integer "missed_projects_count", :default => 0, :null => false
t.text "missed_projects_list" t.text "missed_projects_list"
t.boolean "new_core", :default => true t.boolean "new_core", :default => true
t.integer "success_count", :default => 0, :null => false t.integer "success_count", :default => 0, :null => false
t.integer "build_canceled_count", :default => 0, :null => false t.integer "build_canceled_count", :default => 0, :null => false
t.integer "save_to_platform_id", :null => false
t.boolean "use_save_to_repository"
end end
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|

View File

@ -13,7 +13,7 @@ namespace :build do
open(source).readlines.each do |name| open(source).readlines.each do |name|
name.chomp!; name.strip! #; name.downcase! name.chomp!; name.strip! #; name.downcase!
if p = Project.joins(:repositories).where('repositories.id IN (?)', platform.repositories).find_by_name(name) if p = Project.joins(:repositories).where('repositories.id IN (?)', platform.repositories).find_by_name(name)
# Old code p.build_for(platform, owner, arch) # Old code p.build_for(platform, platform, owner, arch)
say "== Build #{p.name} ==" say "== Build #{p.name} =="
else else
say "== Not found #{name} ==" say "== Not found #{name} =="