Commit 18fbd333 authored by James Fargher's avatar James Fargher

Put Auto-DevOps workflow rules behind feature flags

Require both workflow_rules and auto_devops_beta feature flags to be
enabled so that we don't get errors for workflow and so we can easily
turn this off.
parent 856cba26
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
strong_memoize(:content) do strong_memoize(:content) do
next unless project&.auto_devops_enabled? next unless project&.auto_devops_enabled?
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') template = Gitlab::Template::GitlabCiYmlTemplate.find(template_name)
YAML.dump('include' => [{ 'template' => template.full_name }]) YAML.dump('include' => [{ 'template' => template.full_name }])
end end
end end
...@@ -19,6 +19,22 @@ module Gitlab ...@@ -19,6 +19,22 @@ module Gitlab
def source def source
:auto_devops_source :auto_devops_source
end end
private
def template_name
if beta_enabled?
'Beta/Auto-DevOps'
else
'Auto-DevOps'
end
end
def beta_enabled?
Feature.enabled?(:auto_devops_beta, project, default_enabled: true) &&
# workflow:rules are required by `Beta/Auto-DevOps.gitlab-ci.yml`
Feature.enabled?(:workflow_rules, project, default_enabled: true)
end
end end
end end
end end
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
strong_memoize(:content) do strong_memoize(:content) do
next unless project&.auto_devops_enabled? next unless project&.auto_devops_enabled?
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') template = Gitlab::Template::GitlabCiYmlTemplate.find(template_name)
template.content template.content
end end
end end
...@@ -19,6 +19,22 @@ module Gitlab ...@@ -19,6 +19,22 @@ module Gitlab
def source def source
:auto_devops_source :auto_devops_source
end end
private
def template_name
if beta_enabled?
'Beta/Auto-DevOps'
else
'Auto-DevOps'
end
end
def beta_enabled?
Feature.enabled?(:auto_devops_beta, project, default_enabled: true) &&
# workflow:rules are required by `Beta/Auto-DevOps.gitlab-ci.yml`
Feature.enabled?(:workflow_rules, project, default_enabled: true)
end
end end
end end
end end
......
...@@ -73,7 +73,6 @@ stages: ...@@ -73,7 +73,6 @@ stages:
- cleanup - cleanup
include: include:
- template: Jobs/Detect-Buildpack.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Detect-Buildpack.gitlab-ci.yml
- template: Jobs/Build.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml - template: Jobs/Build.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml
- template: Jobs/Test.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml - template: Jobs/Test.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml
- template: Jobs/Code-Quality.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml - template: Jobs/Code-Quality.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml
......
include:
- template: Auto-DevOps.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml
- template: Jobs/Detect-Buildpack.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Detect-Buildpack.gitlab-ci.yml
...@@ -40,7 +40,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do ...@@ -40,7 +40,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
subject.perform! subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source' expect(pipeline.config_source).to eq 'auto_devops_source'
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
expect(command.config_content).to eq(template.content) expect(command.config_content).to eq(template.content)
end end
end end
...@@ -52,7 +52,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do ...@@ -52,7 +52,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
subject.perform! subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source' expect(pipeline.config_source).to eq 'auto_devops_source'
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
expect(command.config_content).to eq(template.content) expect(command.config_content).to eq(template.content)
end end
end end
...@@ -82,12 +82,32 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do ...@@ -82,12 +82,32 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
expect(project).to receive(:auto_devops_enabled?).and_return(true) expect(project).to receive(:auto_devops_enabled?).and_return(true)
end end
it 'returns the content of AutoDevops template' do context 'when beta is enabled' do
subject.perform! before do
stub_feature_flags(auto_devops_beta: true)
end
expect(pipeline.config_source).to eq 'auto_devops_source' it 'returns the content of AutoDevops template' do
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') subject.perform!
expect(command.config_content).to eq(template.content)
expect(pipeline.config_source).to eq 'auto_devops_source'
template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
expect(command.config_content).to eq(template.content)
end
end
context 'when beta is disabled' do
before do
stub_feature_flags(auto_devops_beta: false)
end
it 'returns the content of AutoDevops template' do
subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source'
template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps')
expect(command.config_content).to eq(template.content)
end
end end
end end
...@@ -190,15 +210,38 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do ...@@ -190,15 +210,38 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
expect(project).to receive(:auto_devops_enabled?).and_return(true) expect(project).to receive(:auto_devops_enabled?).and_return(true)
end end
it 'builds root config including the auto-devops template' do context 'when beta is enabled' do
subject.perform! before do
stub_feature_flags(auto_devops_beta: true)
end
expect(pipeline.config_source).to eq 'auto_devops_source' it 'builds root config including the auto-devops template' do
expect(command.config_content).to eq(<<~EOY) subject.perform!
---
include: expect(pipeline.config_source).to eq 'auto_devops_source'
- template: Auto-DevOps.gitlab-ci.yml expect(command.config_content).to eq(<<~EOY)
EOY ---
include:
- template: Beta/Auto-DevOps.gitlab-ci.yml
EOY
end
end
context 'when beta is disabled' do
before do
stub_feature_flags(auto_devops_beta: false)
end
it 'builds root config including the auto-devops template' do
subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source'
expect(command.config_content).to eq(<<~EOY)
---
include:
- template: Auto-DevOps.gitlab-ci.yml
EOY
end
end end
end end
......
...@@ -133,6 +133,8 @@ describe 'Auto-DevOps.gitlab-ci.yml' do ...@@ -133,6 +133,8 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
end end
with_them do with_them do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps') }
let(:user) { create(:admin) } let(:user) { create(:admin) }
let(:project) { create(:project, :custom_repo, files: files) } let(:project) { create(:project, :custom_repo, files: files) }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) } let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) }
......
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