Commit a291e015 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix/ci-skipped-status' into 'master'

Build status `canceled` if any of the jobs canceled

Before this change in case of any of the jobs had been canceled, build status was `failed`.

Closes #14207

See merge request !3778
parents 5addff7e 40a25732
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.8.0 (unreleased) v 8.8.0 (unreleased)
- Make build status canceled if any of the jobs was canceled and none failed
- Remove future dates from contribution calendar graph. - Remove future dates from contribution calendar graph.
- Use ActionDispatch Remote IP for Akismet checking - Use ActionDispatch Remote IP for Akismet checking
- Fix error when visiting commit builds page before build was updated - Fix error when visiting commit builds page before build was updated
......
...@@ -18,7 +18,7 @@ module Statuseable ...@@ -18,7 +18,7 @@ module Statuseable
WHEN (#{builds})=0 THEN NULL WHEN (#{builds})=0 THEN NULL
WHEN (#{builds})=(#{success})+(#{ignored}) THEN 'success' WHEN (#{builds})=(#{success})+(#{ignored}) THEN 'success'
WHEN (#{builds})=(#{pending}) THEN 'pending' WHEN (#{builds})=(#{pending}) THEN 'pending'
WHEN (#{builds})=(#{canceled}) THEN 'canceled' WHEN (#{builds})=(#{canceled})+(#{success})+(#{ignored}) THEN 'canceled'
WHEN (#{builds})=(#{skipped}) THEN 'skipped' WHEN (#{builds})=(#{skipped}) THEN 'skipped'
WHEN (#{running})+(#{pending})>0 THEN 'running' WHEN (#{running})+(#{pending})>0 THEN 'running'
ELSE 'failed' ELSE 'failed'
......
...@@ -158,97 +158,123 @@ describe Ci::Commit, models: true do ...@@ -158,97 +158,123 @@ describe Ci::Commit, models: true do
stub_ci_commit_yaml_file(YAML.dump(yaml)) stub_ci_commit_yaml_file(YAML.dump(yaml))
end end
it 'properly creates builds' do context 'when builds are successful' do
expect(create_builds).to be_truthy it 'properly creates builds' do
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(create_builds).to be_truthy
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(commit.builds.pluck(:name)).to contain_exactly('build')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'pending') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'success')
commit.reload expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'success', 'success')
expect(commit.status).to eq('success') commit.reload
expect(commit.status).to eq('success')
end
end end
it 'properly creates builds when test fails' do context 'when test job fails' do
expect(create_builds).to be_truthy it 'properly creates builds' do
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(create_builds).to be_truthy
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(commit.builds.pluck(:name)).to contain_exactly('build')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:drop) commit.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending')
commit.builds.running_or_pending.each(&:success) commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'pending')
commit.builds.running_or_pending.each(&:success) commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'success') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'success', 'success')
commit.reload commit.reload
expect(commit.status).to eq('failed') expect(commit.status).to eq('failed')
end
end end
it 'properly creates builds when test and test_failure fails' do context 'when test and test_failure jobs fail' do
expect(create_builds).to be_truthy it 'properly creates builds' do
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(create_builds).to be_truthy
expect(commit.builds.pluck(:status)).to contain_exactly('pending') expect(commit.builds.pluck(:name)).to contain_exactly('build')
commit.builds.running_or_pending.each(&:success) expect(commit.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending')
commit.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'success')
commit.reload
expect(commit.status).to eq('failed')
end
end
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') context 'when deploy job fails' do
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') it 'properly creates builds' do
commit.builds.running_or_pending.each(&:drop) expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:drop) commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
commit.builds.running_or_pending.each(&:success) commit.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'test_failure', 'cleanup') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'failed', 'failed', 'success') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'pending')
commit.reload commit.builds.running_or_pending.each(&:success)
expect(commit.status).to eq('failed')
end
it 'properly creates builds when deploy fails' do expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'success')
expect(create_builds).to be_truthy commit.reload
expect(commit.builds.pluck(:name)).to contain_exactly('build') expect(commit.status).to eq('failed')
expect(commit.builds.pluck(:status)).to contain_exactly('pending') end
commit.builds.running_or_pending.each(&:success) end
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test') context 'when build is canceled in the second stage' do
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending') it 'does not schedule builds after build has been canceled' do
commit.builds.running_or_pending.each(&:success) expect(create_builds).to be_truthy
expect(commit.builds.pluck(:name)).to contain_exactly('build')
expect(commit.builds.pluck(:status)).to contain_exactly('pending')
commit.builds.running_or_pending.each(&:success)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy') expect(commit.builds.running_or_pending).to_not be_empty
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'pending')
commit.builds.running_or_pending.each(&:drop)
expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test', 'deploy', 'cleanup') expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'pending') expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
commit.builds.running_or_pending.each(&:success) commit.builds.running_or_pending.each(&:cancel)
expect(commit.builds.pluck(:status)).to contain_exactly('success', 'success', 'failed', 'success') expect(commit.builds.running_or_pending).to be_empty
commit.reload expect(commit.reload.status).to eq('canceled')
expect(commit.status).to eq('failed') end
end end
end end
end end
......
...@@ -61,9 +61,35 @@ describe Statuseable do ...@@ -61,9 +61,35 @@ describe Statuseable do
let(:statuses) do let(:statuses) do
[create(type, status: :success), create(type, status: :canceled)] [create(type, status: :success), create(type, status: :canceled)]
end end
it { is_expected.to eq 'canceled' }
end
context 'one failed and one canceled' do
let(:statuses) do
[create(type, status: :failed), create(type, status: :canceled)]
end
it { is_expected.to eq 'failed' } it { is_expected.to eq 'failed' }
end end
context 'one failed but allowed to fail and one canceled' do
let(:statuses) do
[create(type, status: :failed, allow_failure: true),
create(type, status: :canceled)]
end
it { is_expected.to eq 'canceled' }
end
context 'one running one canceled' do
let(:statuses) do
[create(type, status: :running), create(type, status: :canceled)]
end
it { is_expected.to eq 'running' }
end
context 'all canceled' do context 'all canceled' do
let(:statuses) do let(:statuses) do
[create(type, status: :canceled), create(type, status: :canceled)] [create(type, status: :canceled), create(type, status: :canceled)]
......
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