Commit 204c5193 authored by James Fargher's avatar James Fargher

Add global rules to match herokuish detect for Auto-DevOps

This adds a long list of filename rules to decide if Auto-DevOps is
likely to work or not.
parent c02c1c9e
---
title: Don't run Auto DevOps when no dockerfile or matching buildpack exists
merge_request: 20267
author:
type: changed
......@@ -4,7 +4,7 @@ require 'spec_helper'
describe API::Triggers do
let(:user) { create(:user) }
let(:project) { create(:project, :repository, creator: user) }
let(:project) { create(:project, :repository, :auto_devops, creator: user) }
describe 'POST /projects/:project_id/trigger/pipeline' do
context 'when triggering a pipeline from a job token' do
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
describe MergeTrains::CreatePipelineService do
let(:project) { create(:project, :repository) }
let(:project) { create(:project, :repository, :auto_devops) }
set(:maintainer) { create(:user) }
let(:service) { described_class.new(project, maintainer) }
let(:previous_ref) { 'refs/heads/master' }
......
......@@ -72,6 +72,83 @@ stages:
- performance
- cleanup
workflow:
rules:
- if: '$BUILDPACK_URL || $AUTO_DEVOPS_EXPLICITLY_ENABLED == "1"'
- exists:
- Dockerfile
# https://github.com/heroku/heroku-buildpack-clojure
- exists:
- project.clj
# https://github.com/heroku/heroku-buildpack-go
- exists:
- go.mod
- Gopkg.mod
- Godeps/Godeps.json
- vendor/vendor.json
- glide.yaml
- src/**/*.go
# https://github.com/heroku/heroku-buildpack-gradle
- exists:
- gradlew
- build.gradle
- settings.gradle
# https://github.com/heroku/heroku-buildpack-java
- exists:
- pom.xml
- pom.atom
- pom.clj
- pom.groovy
- pom.rb
- pom.scala
- pom.yaml
- pom.yml
# https://github.com/heroku/heroku-buildpack-multi
- exists:
- .buildpacks
# https://github.com/heroku/heroku-buildpack-nodejs
- exists:
- package.json
# https://github.com/heroku/heroku-buildpack-php
- exists:
- composer.json
- index.php
# https://github.com/heroku/heroku-buildpack-play
# TODO: detect script excludes some scala files
- exists:
- '**/conf/application.conf'
# https://github.com/heroku/heroku-buildpack-python
# TODO: detect script checks that all of these exist, not any
- exists:
- requirements.txt
- setup.py
- Pipfile
# https://github.com/heroku/heroku-buildpack-ruby
- exists:
- Gemfile
# https://github.com/heroku/heroku-buildpack-scala
- exists:
- '*.sbt'
- project/*.scala
- .sbt/*.scala
- project/build.properties
# https://github.com/dokku/buildpack-nginx
- exists:
- .static
include:
- 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
......
......@@ -9,7 +9,7 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
let(:user) { create(:admin) }
let(:default_branch) { 'master' }
let(:pipeline_branch) { default_branch }
let(:project) { create(:project, :custom_repo, files: { 'README.md' => '' }) }
let(:project) { create(:project, :auto_devops, :custom_repo, files: { 'README.md' => '' }) }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_branch ) }
let(:pipeline) { service.execute!(:push) }
let(:build_names) { pipeline.builds.pluck(:name) }
......@@ -107,4 +107,50 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
end
end
end
describe 'build-pack detection' do
using RSpec::Parameterized::TableSyntax
where(:case_name, :files, :variables, :include_build_names, :not_include_build_names) do
'No match' | { 'README.md' => '' } | {} | %w() | %w(build test)
'Buildpack' | { 'README.md' => '' } | { 'BUILDPACK_URL' => 'http://example.com' } | %w(build test) | %w()
'Explicit set' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '1' } | %w(build test) | %w()
'Explicit unset' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '0' } | %w() | %w(build test)
'Dockerfile' | { 'Dockerfile' => '' } | {} | %w(build test) | %w()
'Clojure' | { 'project.clj' => '' } | {} | %w(build test) | %w()
'Go modules' | { 'go.mod' => '' } | {} | %w(build test) | %w()
'Go gb' | { 'src/gitlab.com/gopackage.go' => '' } | {} | %w(build test) | %w()
'Gradle' | { 'gradlew' => '' } | {} | %w(build test) | %w()
'Java' | { 'pom.xml' => '' } | {} | %w(build test) | %w()
'Multi-buildpack' | { '.buildpacks' => '' } | {} | %w(build test) | %w()
'NodeJS' | { 'package.json' => '' } | {} | %w(build test) | %w()
'PHP' | { 'composer.json' => '' } | {} | %w(build test) | %w()
'Play' | { 'conf/application.conf' => '' } | {} | %w(build test) | %w()
'Python' | { 'Pipfile' => '' } | {} | %w(build test) | %w()
'Ruby' | { 'Gemfile' => '' } | {} | %w(build test) | %w()
'Scala' | { 'build.sbt' => '' } | {} | %w(build test) | %w()
'Static' | { '.static' => '' } | {} | %w(build test) | %w()
end
with_them do
let(:user) { create(:admin) }
let(:project) { create(:project, :custom_repo, files: files) }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) }
let(:pipeline) { service.execute(:push) }
let(:build_names) { pipeline.builds.pluck(:name) }
before do
stub_ci_pipeline_yaml_file(template.content)
allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
variables.each do |(key, value)|
create(:ci_variable, project: project, key: key, value: value)
end
end
it 'creates a pipeline with the expected jobs' do
expect(build_names).to include(*include_build_names)
expect(build_names).not_to include(*not_include_build_names)
end
end
end
end
......@@ -493,6 +493,7 @@ describe Ci::CreatePipelineService do
before do
stub_ci_pipeline_yaml_file(nil)
allow_any_instance_of(Project).to receive(:auto_devops_enabled?).and_return(true)
create(:project_auto_devops, project: project)
end
it 'pull it from Auto-DevOps' do
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
describe ExternalPullRequests::CreatePipelineService do
describe '#execute' do
set(:project) { create(:project, :repository) }
set(:project) { create(:project, :auto_devops, :repository) }
set(:user) { create(:user) }
let(:pull_request) { create(:external_pull_request, project: project) }
......
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