BigW Consortium Gitlab

Commit c6bce7e6 by Kamil Trzcinski Committed by Grzegorz Bizon

Save Ci::Commit object to persist all created builds

parent 07af37a2
...@@ -66,7 +66,10 @@ module Ci ...@@ -66,7 +66,10 @@ module Ci
# We use around_transition to create builds for next stage as soon as possible, before the `after_*` is executed # We use around_transition to create builds for next stage as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |build, block| around_transition any => [:success, :failed, :canceled] do |build, block|
block.call block.call
build.commit.create_next_builds(build) if build.commit if build.commit
build.commit.create_next_builds(build)
build.commit.save
end
end end
after_transition any => [:success, :failed, :canceled] do |build| after_transition any => [:success, :failed, :canceled] do |build|
......
...@@ -13,7 +13,7 @@ module Ci ...@@ -13,7 +13,7 @@ module Ci
validate :valid_commit_sha validate :valid_commit_sha
# Invalidate object and save if when touched # Invalidate object and save if when touched
after_touch :update_state! after_touch :update_state
def self.truncate_sha(sha) def self.truncate_sha(sha)
sha[0...8] sha[0...8]
...@@ -159,7 +159,9 @@ module Ci ...@@ -159,7 +159,9 @@ module Ci
git_commit_message =~ /(\[ci skip\])/ if git_commit_message git_commit_message =~ /(\[ci skip\])/ if git_commit_message
end end
def update_state! private
def update_state
statuses.reload statuses.reload
self.status = if yaml_errors.blank? self.status = if yaml_errors.blank?
statuses.latest.status || 'skipped' statuses.latest.status || 'skipped'
......
...@@ -31,7 +31,7 @@ module Ci ...@@ -31,7 +31,7 @@ module Ci
pipeline.errors.add(:base, 'No builds for this pipeline.') pipeline.errors.add(:base, 'No builds for this pipeline.')
end end
pipeline.update_state! pipeline.save
pipeline pipeline
end end
......
...@@ -15,6 +15,7 @@ module Ci ...@@ -15,6 +15,7 @@ module Ci
) )
if ci_commit.create_builds(nil, trigger_request) if ci_commit.create_builds(nil, trigger_request)
ci_commit.save
trigger_request trigger_request
end end
end end
......
...@@ -55,11 +55,15 @@ describe Ci::Commit, models: true do ...@@ -55,11 +55,15 @@ describe Ci::Commit, models: true do
let!(:commit) { FactoryGirl.create :ci_commit, project: project, ref: 'master', tag: false } let!(:commit) { FactoryGirl.create :ci_commit, project: project, ref: 'master', tag: false }
def create_builds(trigger_request = nil) def create_builds(trigger_request = nil)
commit.create_builds(nil, trigger_request) if commit.create_builds(nil, trigger_request)
commit.save
end
end end
def create_next_builds def create_next_builds
commit.create_next_builds(commit.builds.order(:id).last) if commit.create_next_builds(commit.builds.order(:id).last)
commit.save
end
end end
it 'creates builds' do it 'creates builds' do
......
...@@ -22,6 +22,7 @@ describe Ci::API::API do ...@@ -22,6 +22,7 @@ describe Ci::API::API do
it "should start a build" do it "should start a build" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil) commit.create_builds(nil)
commit.save
build = commit.builds.first build = commit.builds.first
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -58,6 +59,7 @@ describe Ci::API::API do ...@@ -58,6 +59,7 @@ describe Ci::API::API do
it "returns options" do it "returns options" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil) commit.create_builds(nil)
commit.save
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -68,6 +70,7 @@ describe Ci::API::API do ...@@ -68,6 +70,7 @@ describe Ci::API::API do
it "returns variables" do it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil) commit.create_builds(nil)
commit.save
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -87,6 +90,7 @@ describe Ci::API::API do ...@@ -87,6 +90,7 @@ describe Ci::API::API do
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds(nil, trigger_request) commit.create_builds(nil, trigger_request)
commit.save
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value") project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
...@@ -105,6 +109,7 @@ describe Ci::API::API do ...@@ -105,6 +109,7 @@ describe Ci::API::API do
it "returns dependent builds" do it "returns dependent builds" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master') commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil, nil) commit.create_builds(nil, nil)
commit.save
commit.builds.where(stage: 'test').each(&:success) commit.builds.where(stage: 'test').each(&:success)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment