From a687a6601b789e67cad77335cd393cb3393092f1 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 16 Jan 2012 23:51:20 +0200 Subject: [PATCH 1/2] Save commit_hash during build_list create. Tag git repo during build_list publish. Write and fix specs. Refs #103 --- app/controllers/build_lists_controller.rb | 3 +++ .../20120113212924_add_commit_hash_to_build_lists.rb | 9 +++++++++ db/schema.rb | 3 ++- spec/controllers/build_lists_controller_spec.rb | 9 +++++++-- spec/factories/build_list_factory.rb | 1 + spec/spec_helper.rb | 5 +++++ 6 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20120113212924_add_commit_hash_to_build_lists.rb diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 86d2b9064..63494911f 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -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 diff --git a/db/migrate/20120113212924_add_commit_hash_to_build_lists.rb b/db/migrate/20120113212924_add_commit_hash_to_build_lists.rb new file mode 100644 index 000000000..504d49f9a --- /dev/null +++ b/db/migrate/20120113212924_add_commit_hash_to_build_lists.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 83b6e610d..fd6715f37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index e337c1fd6..6566a7f93 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -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) @@ -34,6 +36,7 @@ describe BuildListsController do it 'should be able to perform create action' do post :create, {:project_id => @project.id}.merge(@create_params) + @project.build_lists.last.commit_hash.should == @project.git_repository.commits.last.id response.should redirect_to(@project) end end @@ -57,7 +60,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 +302,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) } diff --git a/spec/factories/build_list_factory.rb b/spec/factories/build_list_factory.rb index 10c4fc3b5..608c48a50 100644 --- a/spec/factories/build_list_factory.rb +++ b/spec/factories/build_list_factory.rb @@ -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| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a79b3ce74..095a7030f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 From b5170e2f2a151a71e4582b7ee4662be25af6f585 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 17 Jan 2012 14:25:54 +0200 Subject: [PATCH 2/2] Write specs for tag based build. Refs #103 --- spec/controllers/build_lists_controller_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index 6566a7f93..3dbba5397 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -36,9 +36,19 @@ describe BuildListsController do it 'should be able to perform create action' do post :create, {:project_id => @project.id}.merge(@create_params) - @project.build_lists.last.commit_hash.should == @project.git_repository.commits.last.id 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