Коммит 01431ae3 создал по автору James Fargher's avatar James Fargher
Просмотр файлов

Initial detection of Auto-DevOps buildable projects

владелец 34f5eb1b
...@@ -809,11 +809,16 @@ def ci_yaml_from_repo ...@@ -809,11 +809,16 @@ def ci_yaml_from_repo
def implied_ci_yaml_file def implied_ci_yaml_file
return unless project return unless project
if project.auto_devops_enabled? if project.auto_devops_enabled? && auto_devops_buildable?
Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content
end end
end end
def auto_devops_buildable?
project.has_auto_devops_explicitly_enabled? ||
Gitlab::AutoDevops::BuildableDetector.new(project, sha).buildable?
end
def pipeline_data def pipeline_data
Gitlab::DataBuilder::Pipeline.build(self) Gitlab::DataBuilder::Pipeline.build(self)
end end
......
...@@ -665,10 +665,14 @@ def auto_devops_enabled? ...@@ -665,10 +665,14 @@ def auto_devops_enabled?
if auto_devops&.enabled.nil? if auto_devops&.enabled.nil?
has_auto_devops_implicitly_enabled? has_auto_devops_implicitly_enabled?
else else
auto_devops.enabled? has_auto_devops_explicitly_enabled?
end end
end end
def has_auto_devops_explicitly_enabled?
auto_devops&.enabled?
end
def has_auto_devops_implicitly_enabled? def has_auto_devops_implicitly_enabled?
auto_devops_config = first_auto_devops_config auto_devops_config = first_auto_devops_config
......
# frozen_string_literal: true
module Gitlab
module AutoDevops
class BuildableDetector
VARIABLES = [
'BUILDPACK_URL'
].freeze
FILE_PATTERNS = [
'Dockerfile',
# https://github.com/heroku/heroku-buildpack-clojure
'project.clj',
# https://github.com/heroku/heroku-buildpack-go
'go.mod',
'Gopkg.mod',
'Godeps/Godeps.json',
'vendor/vendor.json',
'glide.yaml',
'src/**.go',
# https://github.com/heroku/heroku-buildpack-gradle
'gradlew',
'build.gradle',
'settings.gradle',
# https://github.com/heroku/heroku-buildpack-java
'pom.xml',
'pom.atom',
'pom.clj',
'pom.groovy',
'pom.rb',
'pom.scala',
'pom.yaml',
'pom.yml',
# https://github.com/heroku/heroku-buildpack-multi
'.buildpacks',
# https://github.com/heroku/heroku-buildpack-nodejs
'package.json',
# https://github.com/heroku/heroku-buildpack-php
'composer.json',
'index.php',
# https://github.com/heroku/heroku-buildpack-play
# TODO: detect script excludes some scala files
'*/conf/application.conf',
'*modules*',
# https://github.com/heroku/heroku-buildpack-python
# TODO: detect script checks that all of these exist, not any
'requirements.txt',
'setup.py',
'Pipfile',
# https://github.com/heroku/heroku-buildpack-ruby
'Gemfile',
# https://github.com/heroku/heroku-buildpack-scala
'*.sbt',
'project/*.scala',
'.sbt/*.scala',
'project/build.properties',
# https://github.com/dokku/buildpack-nginx
'.static'
].freeze
def initialize(project, ref)
@project = project
@ref = ref
end
def buildable?
detected_variables? || detected_files?
end
private
attr_accessor :project, :ref
def detected_variables?
project.ci_variables_for(ref: ref).where(key: VARIABLES).exists?
end
def detected_files?
return unless tree = project.repository.tree(ref)
tree.blobs.find do |blob|
FILE_PATTERNS.any? do |pattern|
File.fnmatch?(pattern, blob.path, File::FNM_CASEFOLD)
end
end
rescue Gitlab::Git::Repository::NoRepository
# nop
end
end
end
end
...@@ -11,7 +11,11 @@ class Config < Chain::Base ...@@ -11,7 +11,11 @@ class Config < Chain::Base
def perform! def perform!
unless @pipeline.config_processor unless @pipeline.config_processor
unless @pipeline.ci_yaml_file unless @pipeline.ci_yaml_file
return error("Missing #{@pipeline.ci_yaml_file_path} file") if @pipeline.project.auto_devops_enabled?
return error("Auto-DevOps enabled but no buildable files found")
else
return error("Missing #{@pipeline.ci_yaml_file_path} file")
end
end end
if @command.save_incompleted && @pipeline.has_yaml_errors? if @command.save_incompleted && @pipeline.has_yaml_errors?
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::AutoDevops::BuildableDetector do
describe '#buildable?' do
let(:project) { create(:project) }
let(:ref) { :head }
subject(:detector) { described_class.new(project, ref) }
context 'no matching variables or files' do
it 'is not buildable' do
expect(detector).to_not be_buildable
end
end
context 'matching variable' do
before do
create(:ci_variable, project: project, key: 'BUILDPACK_URL')
end
it 'is buildable' do
expect(detector).to be_buildable
end
end
context 'matching file' do
let(:project) { create(:project, :custom_repo, files: { 'Dockerfile' => '' }) }
it 'is buildable' do
expect(detector).to be_buildable
end
end
end
end
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать