Merge pull request #491 from warpc/442-mass_build
[Refs #442] support customize mass rebuild (first version)
This commit is contained in:
commit
bc5cf86115
|
@ -947,3 +947,9 @@ div#git_help_data p {
|
|||
.atom_icon {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
/* Mass build forms */
|
||||
form.mass_build input[type="checkbox"] {
|
||||
width: 10px;
|
||||
height: 11px;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,19 @@ class Platforms::PlatformsController < Platforms::BaseController
|
|||
autocomplete :user, :uname
|
||||
|
||||
def build_all
|
||||
@platform.delay.build_all(current_user)
|
||||
@build_lists = BuildList.for_platform(@platform)
|
||||
@build_lists = @build_lists.by_mass_build(MassBuild.find(params[:mass_build_id])) unless params[:mass_build_id].blank?
|
||||
|
||||
redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success"))
|
||||
if request.post?
|
||||
mass_build = MassBuild.create(:platform => @platform)
|
||||
mass_build.delay.build_all(
|
||||
:user => current_user,
|
||||
:repositories => params[:repositories],
|
||||
:arches => params[:arches],
|
||||
:auto_publish => params[:auto_publish]
|
||||
)
|
||||
redirect_to(build_all_platform_path(@platform), :notice => t("flash.platform.build_all_success"))
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
|
|
@ -6,6 +6,7 @@ class BuildList < ActiveRecord::Base
|
|||
belongs_to :build_for_platform, :class_name => 'Platform'
|
||||
belongs_to :user
|
||||
belongs_to :advisory
|
||||
belongs_to :mass_build
|
||||
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
|
||||
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
|
||||
|
||||
|
@ -72,6 +73,8 @@ class BuildList < ActiveRecord::Base
|
|||
scope :recent, order("#{table_name}.updated_at DESC")
|
||||
scope :for_status, lambda {|status| where(:status => status) }
|
||||
scope :for_user, lambda { |user| where(:user_id => user.id) }
|
||||
scope :for_platform, lambda { |platform| where(:build_for_platform_id => platform.id) }
|
||||
scope :by_mass_build, lambda { |mass_build| where(:mass_build_id => mass_build.id) }
|
||||
scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) }
|
||||
scope :scoped_to_project_version, lambda {|project_version| where(:project_version => project_version) }
|
||||
scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) }
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
class MassBuild < ActiveRecord::Base
|
||||
belongs_to :platform
|
||||
|
||||
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
||||
|
||||
def build_all(opts={})
|
||||
set_name opts[:repositories]
|
||||
platform.build_all opts.merge({:mass_build_id => self.id})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_name(repositories_ids)
|
||||
rep_names = Repository.where(:id => repositories_ids).map(&:name).join(", ")
|
||||
self.name = "#{Date.today.strftime("%d.%b")}-#{platform.name}(#{rep_names})"
|
||||
self.save!
|
||||
end
|
||||
end
|
|
@ -17,6 +17,8 @@ class Platform < ActiveRecord::Base
|
|||
|
||||
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy
|
||||
|
||||
has_many :mass_builds
|
||||
|
||||
validates :description, :presence => true
|
||||
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
||||
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
|
||||
|
@ -155,16 +157,23 @@ class Platform < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def build_all(user)
|
||||
def build_all(opts={})
|
||||
# Set options to build all need
|
||||
repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories
|
||||
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
|
||||
auto_publish = opts[:auto_publish] || true
|
||||
user = opts[:user]
|
||||
mass_build_id = opts[:mass_build_id]
|
||||
|
||||
repositories.each do |rep|
|
||||
rep.projects.find_in_batches(:batch_size => 2) do |group|
|
||||
sleep 1
|
||||
group.each do |p|
|
||||
Arch.all.map(&:name).each do |arch|
|
||||
arches.map(&:name).each do |arch|
|
||||
begin
|
||||
p.build_for(self, user, arch)
|
||||
p.build_for(self, user, arch, auto_publish, mass_build_id)
|
||||
rescue RuntimeError, Exception
|
||||
p.delay.build_for(self, user, arch)
|
||||
p.delay.build_for(self, user, arch, auto_publish, mass_build_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,7 +70,7 @@ class Project < ActiveRecord::Base
|
|||
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
def build_for(platform, user, arch = 'i586', priority = 0)
|
||||
def build_for(platform, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0)
|
||||
# Select main and project platform repository(contrib, non-free and etc)
|
||||
# If main does not exist, will connect only project platform repository
|
||||
# If project platform repository is main, only main will be connect
|
||||
|
@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
|
|||
arch = Arch.find_by_name(arch) if arch.acts_like?(:string)
|
||||
build_lists.create do |bl|
|
||||
bl.save_to_platform = platform
|
||||
bl.build_to_platform = platform
|
||||
bl.build_for_platform = platform
|
||||
bl.update_type = 'newpackage'
|
||||
bl.arch = arch
|
||||
bl.project_version = "latest_#{platform.name}"
|
||||
|
@ -89,6 +89,7 @@ class Project < ActiveRecord::Base
|
|||
bl.auto_publish = true # already set as db default
|
||||
bl.include_repos = build_ids
|
||||
bl.priority = priority
|
||||
bl.mass_build_id = mass_build_id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
- content_for(:sidebar) do
|
||||
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
|
||||
.bordered.nopadding
|
||||
.table
|
||||
%h3= t("activerecord.attributes.build_list.build_for_platform")
|
||||
- @platform.repositories.each do |rep|
|
||||
.lefter
|
||||
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
|
||||
= label_tag "repositories_#{rep.id}", rep.name
|
||||
.both
|
||||
.both
|
||||
.table
|
||||
%h3= t("activerecord.attributes.build_list.arch")
|
||||
- Arch.recent.each do |arch|
|
||||
.lefter
|
||||
= check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}"
|
||||
= label_tag "arches_#{arch.id}", arch.name
|
||||
.both
|
||||
.both
|
||||
.table
|
||||
%h3= t("activerecord.attributes.build_list.preferences")
|
||||
.lefter
|
||||
= check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : true, :id => 'auto_publish'
|
||||
= label_tag :auto_publish
|
||||
.both
|
||||
.both
|
||||
%br
|
||||
= f.submit t("layout.projects.build_button")
|
||||
|
||||
%br
|
||||
%br
|
||||
.bordered.nopadding
|
||||
.table
|
||||
- ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state|
|
||||
.lefter
|
||||
= t("layout.build_lists.statuses.#{state.demodulize.downcase}")
|
||||
.righter
|
||||
= BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count
|
||||
.both
|
||||
%br
|
||||
= link_to t("layout.activity_feed.all_my_builds"), build_lists_path
|
||||
|
||||
%h3.fix= t("layout.platforms.mass_build")
|
||||
|
||||
- if MassBuild.exists? :platform_id => @platform.id
|
||||
%br
|
||||
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => :form, :method => :get } do |f|
|
||||
= select_tag "mass_build_id", options_from_collection_for_select( MassBuild.by_platform(@platform), :id, :name ), :include_blank => true
|
||||
= f.submit t("layout.platforms.refresh_button")
|
||||
|
||||
%table.tablesorter.unbordered
|
||||
%thead
|
||||
%tr
|
||||
%th.lpadding16= t('layout.platforms.mass_build')
|
||||
%th.lpadding16= t('layout.platforms.project')
|
||||
%th.lpadding16= t('layout.platforms.arch')
|
||||
%th.lpadding16= t('layout.platforms.build_task')
|
||||
- @build_lists.each do |build_list|
|
||||
%tr{:class => "#{build_list_status_color(build_list.status)}"}
|
||||
%td= build_list.mass_build_id ? build_list.mass_build.name : ""
|
||||
%td= link_to build_list.project.name, project_path(build_list.project)
|
||||
%td= build_list.arch.name
|
||||
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), build_list
|
|
@ -40,7 +40,11 @@ en:
|
|||
target_platform: Target platform
|
||||
target_architecture: Target architecture
|
||||
members: Members
|
||||
|
||||
project: Project
|
||||
arch: Architecture
|
||||
mass_build: Mass Build
|
||||
build_task: Build Task
|
||||
refresh_button: Refresh
|
||||
|
||||
flash:
|
||||
platform:
|
||||
|
|
|
@ -40,6 +40,11 @@ ru:
|
|||
target_platform: Целевая платформа
|
||||
target_architecture: Целевая архитектура
|
||||
members: Участники
|
||||
arch: Архитектура
|
||||
mass_build: Массовая сборка
|
||||
build_task: Сборочное задание
|
||||
refresh_button: Обновить
|
||||
project: Проект
|
||||
|
||||
flash:
|
||||
platform:
|
||||
|
|
|
@ -48,6 +48,7 @@ Rosa::Application.routes.draw do
|
|||
post :add_member
|
||||
post :make_clone
|
||||
post :build_all
|
||||
get :build_all
|
||||
end
|
||||
get :autocomplete_user_uname, :on => :collection
|
||||
resources :repositories do
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class CreateMassBuilds < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :mass_builds do |t|
|
||||
t.integer :platform_id
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddMassBuildIdToBuildLists < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :build_lists, :mass_build_id, :integer
|
||||
end
|
||||
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120515095324) do
|
||||
ActiveRecord::Schema.define(:version => 20120518105225) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -118,6 +118,7 @@ ActiveRecord::Schema.define(:version => 20120515095324) do
|
|||
t.datetime "started_at"
|
||||
t.integer "duration"
|
||||
t.integer "advisory_id"
|
||||
t.integer "mass_build_id"
|
||||
end
|
||||
|
||||
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"
|
||||
|
@ -211,6 +212,13 @@ ActiveRecord::Schema.define(:version => 20120515095324) do
|
|||
|
||||
add_index "labels", ["project_id"], :name => "index_labels_on_project_id"
|
||||
|
||||
create_table "mass_builds", :force => true do |t|
|
||||
t.integer "platform_id"
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "platforms", :force => true do |t|
|
||||
t.string "description"
|
||||
t.string "name", :null => false
|
||||
|
@ -304,8 +312,6 @@ ActiveRecord::Schema.define(:version => 20120515095324) do
|
|||
t.integer "build_count", :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true
|
||||
|
||||
create_table "register_requests", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
|
@ -369,11 +375,9 @@ ActiveRecord::Schema.define(:version => 20120515095324) do
|
|||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe MassBuild do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue