Merge pull request #106 from warpc/103-bl_publish_new_params

Сохранение сборочного коммита, добавление неподписанного тега на сохраненный коммит после публикации
This commit is contained in:
santaux 2012-01-17 04:34:15 -08:00
commit 62d0419bdd
6 changed files with 37 additions and 3 deletions

View File

@ -39,6 +39,7 @@ class BuildListsController < ApplicationController
Arch.where(:id => params[:arches]).each do |arch|
Platform.main.where(:id => params[:bpls]).each do |bpl|
@build_list = @project.build_lists.build(params[:build_list])
@build_list.commit_hash = @project.git_repository.commits(@build_list.project_version.match(/(.+)_latest$/).to_a.last || @build_list.project_version).first.id
@build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :bpl => bpl.name, :pl => @build_list.pl}
if @build_list.save
@ -83,6 +84,8 @@ class BuildListsController < ApplicationController
if params[:status].to_i == 0 # ok
@build_list.status = BuildList::BUILD_PUBLISHED
@build_list.package_version = "#{params[:version]}-#{params[:release]}"
system("cd #{@build_list.project.git_repository.path} &&
git tag -a -m '#{@build_list.package_version}' #{@build_list.package_version} #{@build_list.commit_hash}") # TODO REDO through grit
else
@build_list.status = BuildList::FAILED_PUBLISH
end

View File

@ -0,0 +1,9 @@
class AddCommitHashToBuildLists < ActiveRecord::Migration
def self.up
add_column :build_lists, :commit_hash, :string
end
def self.down
remove_column :build_lists, :commit_hash
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120113151305) do
ActiveRecord::Schema.define(:version => 20120113212924) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -73,6 +73,7 @@ ActiveRecord::Schema.define(:version => 20120113151305) do
t.integer "user_id"
t.boolean "auto_publish", :default => true
t.string "package_version"
t.string "commit_hash"
end
add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id"

View File

@ -27,6 +27,8 @@ describe BuildListsController do
end
shared_examples_for 'create build list' do
before {test_git_commit(@project)}
it 'should be able to perform new action' do
get :new, :project_id => @project.id
response.should render_template(:new)
@ -36,6 +38,17 @@ describe BuildListsController do
post :create, {:project_id => @project.id}.merge(@create_params)
response.should redirect_to(@project)
end
it 'should save correct commit_hash for branch based build' do
post :create, {:project_id => @project.id}.merge(@create_params).deep_merge(:build_list => {:project_version => "master_latest"})
@project.build_lists.last.commit_hash.should == @project.git_repository.commits('master').last.id
end
it 'should save correct commit_hash for tag based build' do
system("cd #{@project.git_repository.path} && git tag -a -m '4.7.5.3' 4.7.5.3") # TODO REDO through grit
post :create, {:project_id => @project.id}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"})
@project.build_lists.last.commit_hash.should == @project.git_repository.commits('4.7.5.3').last.id
end
end
shared_examples_for 'not create build list' do
@ -57,7 +70,7 @@ describe BuildListsController do
platform = Factory(:platform_with_repos)
@create_params = {
:build_list => {
:project_version => 'v1.0',
:project_version => 'master_latest',
:pl_id => platform.id,
:update_type => 'security',
:include_repos => [platform.repositories.first.id]
@ -299,12 +312,14 @@ describe BuildListsController do
let(:build_list) { Factory(:build_list_core) }
describe 'publish_build' do
before {test_git_commit(build_list.project); build_list.update_attribute :commit_hash, build_list.project.git_repository.commits.last.id}
def do_get(status)
get :publish_build, :id => build_list.bs_id, :status => status, :version => '4.7.5.3', :release => '1'
build_list.reload
end
it { do_get(BuildServer::SUCCESS); response.should be_ok }
it { do_get(BuildServer::SUCCESS); build_list.project.git_repository.tags.last.name.should == build_list.package_version; response.should be_ok }
it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) }
it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to('4.7.5.3-1') }
it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildList::FAILED_PUBLISH) }

View File

@ -8,6 +8,7 @@ Factory.define(:build_list) do |p|
p.build_requires true
p.update_type 'security'
p.include_repos {|bl| bl.pl.repositories.map(&:id)}
p.commit_hash 'e681644ed702fae285483d2ca73d85ee2930b8de'
end
Factory.define(:build_list_core, :parent => :build_list) do |p|

View File

@ -37,6 +37,11 @@ def stub_rsync_methods
any_instance_of(Platform, :umount_directory_for_rsync => true)
end
def test_git_commit(project)
project.git_repository.repo.index.add('test', 'TEST')
project.git_repository.repo.index.commit('Test commit')
end
Delayed::Worker.delay_jobs = false # Execute all jobs realtime
# Add testing root_path