summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-06-12 15:05:01 +0000
committerValery Sizov <valery@gitlab.com>2015-06-12 15:05:01 +0000
commit83940de53b7d66be5496c69d20eb834607696897 (patch)
treed05871619e2906d2acc26d83b5a4f8eb1f07da37
parent1a80d6973073f33fd77b7d556d66f81abfe22e62 (diff)
parentf70fa3eb45104304a1ea5a33edb0ea8bea3f0d32 (diff)
downloadgitlab-ci-83940de53b7d66be5496c69d20eb834607696897.tar.gz
Merge branch 'new_syntax' into 'master'
New syntax of .gitlab-ci.yml See merge request !136
-rw-r--r--app/models/commit.rb26
-rw-r--r--app/services/create_commit_service.rb10
-rw-r--r--app/views/commits/show.html.haml4
-rw-r--r--app/views/lints/_create.html.haml27
-rw-r--r--db/migrate/20150601043226_migrate_jobs_to_yaml.rb (renamed from db/migrate/20150601043225_migrate_jobs_to_yaml.rb)47
-rw-r--r--doc/builds_configuration/README.md127
-rw-r--r--lib/gitlab_ci_yaml_processor.rb122
-rw-r--r--spec/controllers/projects_controller_spec.rb3
-rw-r--r--spec/features/lint_spec.rb9
-rw-r--r--spec/lib/gitlab_ci_yaml_processor_spec.rb179
-rw-r--r--spec/models/commit_spec.rb2
-rw-r--r--spec/models/project_services/hip_chat_message_spec.rb2
-rw-r--r--spec/models/project_services/slack_message_spec.rb2
-rw-r--r--spec/services/create_commit_service_spec.rb50
-rw-r--r--spec/support/gitlab_stubs/gitlab_ci.yml57
15 files changed, 309 insertions, 358 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 3bc38b6..f27a385 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -92,11 +92,15 @@ class Commit < ActiveRecord::Base
end
def create_builds
- filter_param = tag? ? :tags : :branches
- config_processor.builds.each do |build_attrs|
- if build_attrs[filter_param]
- builds.create!({ project: project }.merge(build_attrs.extract!(:name, :commands, :tag_list)))
- end
+ return if push_data[:commits].last[:message] =~ /(\[ci skip\])/
+
+ config_processor.builds_for_ref(ref, tag).each do |build_attrs|
+ builds.create!({
+ project: project,
+ name: build_attrs[:name],
+ commands: build_attrs[:script],
+ tag_list: build_attrs[:tags]
+ })
end
end
@@ -115,8 +119,16 @@ class Commit < ActiveRecord::Base
end
def create_deploy_builds
- config_processor.deploy_builds_for_ref(ref).each do |build_attrs|
- builds.create!({ project: project }.merge(build_attrs))
+ return if push_data[:commits].last[:message] =~ /(\[ci skip\])/
+
+ config_processor.deploy_builds_for_ref(ref, tag).each do |build_attrs|
+ builds.create!({
+ project: project,
+ name: build_attrs[:name],
+ commands: build_attrs[:script],
+ tag_list: build_attrs[:tags],
+ deploy: true
+ })
end
end
diff --git a/app/services/create_commit_service.rb b/app/services/create_commit_service.rb
index 81d552a..de5ece3 100644
--- a/app/services/create_commit_service.rb
+++ b/app/services/create_commit_service.rb
@@ -17,15 +17,7 @@ class CreateCommitService
return false
end
- if params[:commits] && params[:commits].last[:message] =~ /(\[ci skip\])/
- return false
- end
-
- if origin_ref.start_with?('refs/tags/') && !config_processor.create_commit_for_tag?(ref)
- return false
- end
-
- if config_processor.skip_ref?(ref)
+ unless config_processor.any_jobs?(ref, origin_ref.start_with?('refs/tags/'))
return false
end
diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml
index cb8b866..3353f78 100644
--- a/app/views/commits/show.html.haml
+++ b/app/views/commits/show.html.haml
@@ -53,7 +53,7 @@
%th Status
%th Build ID
%th Trigger
- %th Job
+ %th Name
%th Duration
%th Finished at
- if @project.coverage_enabled?
@@ -71,7 +71,7 @@
%th Status
%th Build ID
%th Trigger
- %th Job
+ %th Name
%th Duration
%th Finished at
- if @project.coverage_enabled?
diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml
index 64a7d65..34920d7 100644
--- a/app/views/lints/_create.html.haml
+++ b/app/views/lints/_create.html.haml
@@ -15,33 +15,32 @@
%td Job - #{build[:name]}
%td
%pre
- = simple_format build[:commands]
+ = simple_format build[:script]
%b Tag list:
- #{build[:tag_list]}
+ = build[:tags]
%br
- %b Build for branches:
- #{build[:branches] ? "true": "false"}
+ %b Refs only:
+ = build[:only] && build[:only].join(", ")
%br
- %b Build for tags:
- #{build[:tags] ? "true": "false"}
+ %b Refs except:
+ = build[:except] && build[:except].join(", ")
- @config_processor.deploy_builds.each do |build|
%tr
%td Deploy Job - #{build[:name]}
%td
%pre
- = simple_format build[:commands]
+ = simple_format build[:script]
%b Tag list:
- #{build[:tag_list]}
+ = build[:tags]
%br
- %b Refs:
- #{build[:refs]}
-
- %tr
- %td Skip Refs
- %td= @config_processor.skip_refs
+ %b Refs only:
+ = build[:only] && build[:only].join(", ")
+ %br
+ %b Refs except:
+ = build[:except] && build[:except].join(", ")
-else
%p
diff --git a/db/migrate/20150601043225_migrate_jobs_to_yaml.rb b/db/migrate/20150601043226_migrate_jobs_to_yaml.rb
index aaf10a7..ba7a7dc 100644
--- a/db/migrate/20150601043225_migrate_jobs_to_yaml.rb
+++ b/db/migrate/20150601043226_migrate_jobs_to_yaml.rb
@@ -5,9 +5,9 @@
class MigrateJobsToYaml < ActiveRecord::Migration
def up
select_all("SELECT * FROM projects").each do |project|
- config = {jobs: [], deploy_jobs: []}
+ config = {}
- concatenate_expression = if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
+ concatenate_expression = if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
"string_agg(tags.name, ',')"
else
"GROUP_CONCAT(tags.name SEPARATOR ',')"
@@ -24,26 +24,31 @@ class MigrateJobsToYaml < ActiveRecord::Migration
# Create Jobs
select_all(sql).each do |job|
- config[:jobs] << {
- script: job["commands"] && job["commands"].split("\n").map(&:strip),
- name: job["name"],
- branches: parse_boolean_value(job["build_branches"]),
- tags: parse_boolean_value(job["build_tags"]),
- runner: job["tags"]
+ config[job["name"].to_s] = {
+ test: job["commands"] && job["commands"].split("\n").map(&:strip),
+ tags: job["tags"]
}
+
+ except = build_except_param(parse_boolean_value(job["build_branches"]), parse_boolean_value(job["build_tags"]))
+
+ if except
+ config[job["name"].to_s][:except] = except
+ end
end
# Create Deploy Jobs
select_all(sql.sub("parallel", 'deploy')).each do |job|
- config[:deploy_jobs] << {
- script: job["commands"] && job["commands"].split("\n").map(&:strip),
- name: job["name"],
- refs: job["refs"],
- runner: job["tags"]
+ config[job["name"].to_s] = {
+ deploy: job["commands"] && job["commands"].split("\n").map(&:strip),
+ tags: job["tags"]
}
- end
- config[:skip_refs] = project["skip_refs"]
+ except = build_except_param(parse_boolean_value(job["build_branches"]), parse_boolean_value(job["build_tags"]))
+
+ if except
+ config[job["name"].to_s][:except] = except
+ end
+ end
yaml_config = YAML.dump(config.deep_stringify_keys)
@@ -62,4 +67,16 @@ class MigrateJobsToYaml < ActiveRecord::Migration
def parse_boolean_value(value)
[ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value)
end
+
+ def build_except_param(branches, tags)
+ unless branches
+ return ["branches"]
+ end
+
+ unless tags
+ return ["tags"]
+ end
+
+ false
+ end
end
diff --git a/doc/builds_configuration/README.md b/doc/builds_configuration/README.md
index 06c2c8e..25d1090 100644
--- a/doc/builds_configuration/README.md
+++ b/doc/builds_configuration/README.md
@@ -1,87 +1,102 @@
## Configuraton of your builds with .gitlab-ci.yml
-From version 7.12, GitLab CI uses a .gitlab-ci.yml file for the configuration of your builds. It is place in the root of your repository and contains four main sections: skep_refs, before_script, jobs and deploy_jobs. Here is an example of how it looks:
+From version 7.12, GitLab CI uses a .gitlab-ci.yml file for the configuration of your builds. It is placed in the root of your repository and contains three type of objects: before_script, builds and deploy_builds. Here is an example of how it looks:
```yaml
-skip_refs: staging
-before_script: |
- bundle install
- bundle exec rake db:setup
-jobs:
-- script: "bundle exec rspec"
- name: Rspec
- runner: mysql,ruby
-- "bundle exec cucumber" # or even so
-deploy_jobs:
-- "bundle exec cap deploy"
+before_script:
+ - gem install bundler
+ - bundle install
+ - bundle exec rake db:create
+
+rspec:
+ test: "rake spec"
+ tags:
+ - ruby
+ - postgres
+ only:
+ - branches
+
+staging:
+ deploy: "cap deploy stating"
+ tags:
+ - capistrano
+ - debian
+ except:
+ - stable
+ - /^deploy-.*$/
```
Let's have a close look at each section.
-### skip_refs
-This parameter defines the ref or list of refs to skip. You can use glob pattern syntax as well. Example: "staging,feature-*"
-
-### jobs
-Here you can specify parameters of your builds. There are serveral ways you can configure it. Using hash:
+### builds
+Here you can specify parameters of your builds:
```yaml
-jobs:
-- script: "bundle exec rspec" # (required) - commands to run
- name: Rspec # (optional) - name of build
- runner: mysql,ruby # (optional) - runner tags, only runners which have these tags will be used
- branches: true # (optional) - make builds for regular branches
- tags: true # (optional) - make builds for tags
-```
-
-`script` can also cantain several commands using YAML multiline string:
+rspec:
+ test: "rake spec" # (required) - shell command for runner
+ tags: # (optional) - runner tags, only runners which have these tags will be used
+ - ruby
+ - postgres
+ only: # (optional) - git refs (branches and tags)
+ - master
-```yaml
-- script: |
- bundle updata
- bundle exec rspec
```
-you can also fill commands like an array:
+`rspec` is a key of this object and it determines the name of your build
+
+`test` is a script which is used by runner. It will be also prepanded with `before_script`. This parameter can also cantain several commands using array:
```yaml
-- script:
- - bundle update
+test:
+ - uname -a
- bundle exec rspec
```
+About `only` and `except` parameters you can read in the [refs settings explanation](#refs-settings-explanation)
-And there is one more way to specify build configuration, using a string:
+### deploy_builds
+Deploy Builds that will be run when all other builds have succeeded. Define them using simple syntax:
```yaml
-jobs:
-- bundle exec rspec
+production:
+ deploy: "cap deploy production" # (required) - shell command for runner
+ tags:
+ - ruby
+ - postgres
+ only:
+ - master
```
-In this way, the name of the build will be taken from command line.
+`production` - is a name of deploy build.
+`deploy` - is a script which will be prepended with `before_script`. Keep in mind that this parameter makes difference between deploy job and regular job. Last one requires `test` parameter instead of `deploy`.
+About `only` and `except` parameters you can read in the [refs settings explanation](#refs-settings-explanation)
-### deploy_jobs
-Deploy Jobs that will be run when all other jobs have succeeded. Define them using a hash:
+### before_script
+`before_script` is used to define the command that should be ran before all builds, including deploy builds. This can be an array or a multiline string.
-```yaml
-deploy_jobs:
-- script: | # (required) - command
- bundle update
- bundle exec cap deploy
- name: Deploy # (optional) - name
- refs: deploy # (optional) - run only when the above git refs strings match the branch or tag that was pushed.
- runner: ruby,deploy # (optional) - runner tags, only runners which have these tags will be used
+### Refs settings explanation
+There are two parameters that help you to set up refs policy for your build or deploy build on CI.
```
+only:
+ - master
+```
+`only` defines exact name of the branch or the tag which will be run. It also supports the regexp expressions:
-`script` can be a multiline script or array like for regular jobs.
-
-You can also define deploy jobs with a string:
-
-```yaml
-deploy_jobs:
-- "bundle exec cap deploy"
```
+only:
+ - /^issue-.*$/
+```
+You can also use an `except` parameter:
+```
+except:
+ - "deploy"
+```
+This parameter is used for excluding some refs. It is also supporting regexp expressions.
-### before_script
-`before_script` is used to define the command that should be ran before all builds, including deploy builds. This can be an array or a multiline string.
+There are also special keys like `branches` or `tags`. These parameters can be used for excluding all tags or branches.
+```
+except:
+ - branches
+```
## Debugging of your builds with .gitlab-ci.yml
diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb
index 32f7938..274754f 100644
--- a/lib/gitlab_ci_yaml_processor.rb
+++ b/lib/gitlab_ci_yaml_processor.rb
@@ -3,104 +3,86 @@ class GitlabCiYamlProcessor
def initialize(config)
@config = YAML.load(config).deep_symbolize_keys
- @skip_refs = @config[:skip_refs] || ""
@before_script = @config[:before_script] || []
- @jobs = @config[:jobs] || []
- @deploy_jobs = @config[:deploy_jobs] || []
+
+ @config.delete(:before_script)
+
+ @jobs = @config.select{|key, value| value[:test]}
+
+ @deploy_jobs = @config.select{|key, value| value[:deploy]}
end
- def builds
- normalized_jobs.map do |job|
- {
- name: job[:name],
- commands: "#{normalized_script(@before_script)}\n#{job[:script]}",
- tag_list: job[:runner],
- branches: job[:branches],
- tags: job[:tag]
- }
- end
+ def deploy_builds_for_ref(ref, tag = false)
+ deploy_builds.select{|build| process?(build[:only], build[:except], ref, tag)}
end
- def deploy_builds
- normalized_deploy_jobs.map do |job|
- {
- name: job[:name],
- commands: "#{normalized_script(@before_script)}\n#{job[:script]}",
- deploy: true,
- refs: job[:refs],
- tag_list: job[:runner]
- }
- end
+ def builds_for_ref(ref, tag = false)
+ builds.select{|build| process?(build[:only], build[:except], ref, tag)}
end
- def create_commit_for_tag?(ref)
- normalized_jobs.any?{|job| job[:tags] == true} ||
- normalized_deploy_jobs.any?{|job| job[:refs].blank? || refs_matches?(job[:refs].split(",").map(&:strip), ref)}
+ def any_jobs?(ref, tag = false)
+ builds_for_ref(ref, tag).any? || deploy_builds_for_ref(ref, tag).any?
end
- def deploy_builds_for_ref(ref)
- deploy_builds.select do |build_attrs|
- refs = build_attrs.delete(:refs)
- refs.blank? || refs_matches?(refs.split(",").map(&:strip), ref)
+ def builds
+ @jobs.map do |name, job|
+ {
+ script: "#{@before_script.join("\n")}\n#{normilize_script(job[:test])}",
+ tags: job[:tags] || [],
+ name: name,
+ only: job[:only],
+ except: job[:except]
+ }
end
end
- def skip_ref?(ref_name)
- @skip_refs.split(",").each do |ref|
- return true if File.fnmatch(ref, ref_name)
+ def deploy_builds
+ @deploy_jobs.map do |name, job|
+ {
+ script: "#{@before_script.join("\n")}\n#{normilize_script(job[:deploy])}",
+ tags: job[:tags] || [],
+ name: name,
+ only: job[:only],
+ except: job[:except]
+ }
end
-
- false
end
private
- # refs - list of refs. Glob syntax is supported. Ex. ["feature*", "bug"]
- # ref - ref that should be checked
- def refs_matches?(refs, ref)
- refs.each do |ref_pattern|
- return true if File.fnmatch(ref_pattern, ref)
- end
+ def process?(only_params, except_params, ref, tag)
+ return true if only_params.nil? && except_params.nil?
- false
- end
+ if only_params
+ return true if tag && only_params.include?("tags")
+ return true if !tag && only_params.include?("branches")
+
+ only_params.each do |pattern|
+ return match_ref?(pattern, ref)
+ end
+ else
+ return false if tag && except_params.include?("tags")
+ return false if !tag && except_params.include?("branches")
- def normalized_jobs
- @jobs.map do |job|
- if job.is_a?(String)
- { script: job, runner: "", name: job[0..10], branches: true, tags: true }
- else
- {
- script: normalized_script(job[:script]),
- runner: job[:runner] || "",
- name: job[:name] || job[:script][0..10],
- branches: job[:branches].nil? ? true : job[:branches],
- tags: job[:tags].nil? ? true : job[:tags]
- }
+ except_params.each do |pattern|
+ return false if match_ref?(pattern, ref)
end
end
end
- def normalized_deploy_jobs
- @deploy_jobs.map do |job|
- if job.is_a?(String)
- { script: job, runner: "", refs: "", name: job[0..10].strip }
- else
- {
- script: normalized_script(job[:script]),
- refs: job[:refs] || "",
- name: job[:name] || job[:script][0..10].strip,
- runner: job[:runner] || "",
- }
- end
+ def match_ref?(pattern, ref)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ ref
+ else
+ pattern == ref
end
end
- def normalized_script(script)
+ def normilize_script(script)
if script.is_a? Array
- script.map(&:strip).join("\n")
+ script.join("\n")
else
- script.strip
+ script
end
end
end
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 455a213..0069a78 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -12,7 +12,8 @@ describe ProjectsController do
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '1c8a9df454ef68c22c2a33cca8232bb50849e5c5',
token: @project.token,
- ci_yaml_file: gitlab_ci_yaml
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
expect(response).to be_success
diff --git a/spec/features/lint_spec.rb b/spec/features/lint_spec.rb
index 4a1ea26..1160f24 100644
--- a/spec/features/lint_spec.rb
+++ b/spec/features/lint_spec.rb
@@ -11,11 +11,10 @@ describe "Lint" do
fill_in "content", with: content
click_on "Validate"
within "table" do
- page.should have_content("Skip Refs")
- page.should have_content("Job - Rspec")
- page.should have_content("Job - Spinach")
- page.should have_content("Deploy Job - cap deploy")
- page.should have_content("Deploy Job - Deploy to staging")
+ page.should have_content("Job - rspec")
+ page.should have_content("Job - spinach")
+ page.should have_content("Deploy Job - staging")
+ page.should have_content("Deploy Job - production")
end
end
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb
index 22d0d6b..96dcf64 100644
--- a/spec/lib/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb
@@ -2,217 +2,120 @@ require 'spec_helper'
describe GitlabCiYamlProcessor do
- describe "#builds" do
- it "returns builds from string" do
- config = YAML.dump({
- jobs: ["ls"]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.builds.size.should == 1
- config_processor.builds.first.should == {
- branches: true,
- commands: "\nls",
- name: "ls",
- tag_list: "",
- tags: nil
- }
- end
-
- it "returns builds from string including before_script" do
+ describe "#builds_for_ref" do
+ it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: ["ls"]
+ rspec: {test: "rspec"}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.builds.first.should == {
- branches: true,
- commands: "pwd\nls",
- name: "ls",
- tag_list: "",
- tags: nil
+ config_processor.builds_for_ref("master").size.should == 1
+ config_processor.builds_for_ref("master").first.should == {
+ except: nil,
+ name: :rspec,
+ only: nil,
+ script: "pwd\nrspec",
+ tags: []
}
end
- it "returns builds from job hash" do
+ it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.builds.first.should == {
- branches: true,
- commands: "pwd\nls",
- name: "Rspec",
- tag_list: "mysql,ruby",
- tags: nil
- }
- end
- end
-
- describe "#deploy_builds" do
- it "returns deploy builds from string" do
- config = YAML.dump({
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", only: ["deploy"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.size.should == 1
- config_processor.deploy_builds.first.should == {
- commands: "\nls",
- name: "ls",
- deploy: true,
- refs: "",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 0
end
- it "returns deploy builds from string including before_script" do
+ it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", only: ["/^deploy$/"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.first.should == {
- commands: "pwd\nls",
- name: "ls",
- deploy: true,
- refs: "",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 0
end
- it "returns deploy builds from job hash" do
+ it "returns builds if only has specified this branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Rspec", refs: "master,deploy"}]
+ rspec: {test: "rspec", only: ["master"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.first.should == {
- commands: "pwd\nls",
- name: "Rspec",
- deploy: true,
- refs: "master,deploy",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 1
end
- end
- describe "create_commit_for_tag?" do
- it "returns true because there is a job for tags" do
+ it "does not build tags" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runners: "mysql,ruby", tags: true}],
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", exclude: ["tags"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns true because there is a deploy job for this tag" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: [{script: "ls", refs: "deploy"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns true because there is a deploy job without tag specified" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: ["ls"]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns false because there is no deploy job for this ref nor job for tags" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: [{script: "ls", refs: "master"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_false
+ config_processor.builds_for_ref("0-1", true).size.should == 1
end
end
describe "#deploy_builds_for_ref" do
- it "returns deploy job for ref" do
+ it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}, {script: "pwd", refs: "staging"}]
+ rspec: {deploy: "rspec"}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds_for_ref("deploy").size.should == 1
- config_processor.deploy_builds_for_ref("deploy").first[:name].should == 'Deploy!1'
+ config_processor.deploy_builds_for_ref("master").size.should == 1
+ config_processor.deploy_builds_for_ref("master").first.should == {
+ except: nil,
+ name: :rspec,
+ only: nil,
+ script: "pwd\nrspec",
+ tags: []
+ }
end
- it "returns deploy job for ref including job without ref specified" do
+ it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}, "pwd"]
+ rspec: {deploy: "rspec", only: ["deploy"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds_for_ref("deploy").size.should == 2
+ config_processor.deploy_builds_for_ref("master").size.should == 0
end
- it "returns empty array because there is no deploy job for this ref" do
+ it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}]
+ rspec: {deploy: "rspec", only: ["/^deploy$/"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.deploy_builds_for_ref("master").size.should == 0
end
- end
- describe "skip_ref?" do
- it "skips ref" do
+ it "returns builds if only has specified this branch" do
config = YAML.dump({
- skip_refs: "master"
+ before_script: ["pwd"],
+ rspec: {deploy: "rspec", only: ["master"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.skip_ref?("master").should be_true
- config_processor.skip_ref?("deploy").should be_false
- end
-
- it "does not skip ref if no refs specified" do
- config = YAML.dump({})
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.skip_ref?("master").should be_false
+ config_processor.deploy_builds_for_ref("master").size.should == 1
end
end
-
end \ No newline at end of file
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 1658ae6..8c0073e 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -138,7 +138,7 @@ describe Commit do
commit.create_deploy_builds
commit.builds.reload
- commit.builds.size.should == 1
+ commit.builds.size.should == 2
end
end
diff --git a/spec/models/project_services/hip_chat_message_spec.rb b/spec/models/project_services/hip_chat_message_spec.rb
index d4bfb31..5fa5549 100644
--- a/spec/models/project_services/hip_chat_message_spec.rb
+++ b/spec/models/project_services/hip_chat_message_spec.rb
@@ -8,7 +8,7 @@ describe HipChatMessage do
context "One build" do
let(:commit) do
commit = FactoryGirl.create(:commit, project: project)
- commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]})
+ commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { test: 'pwd' }})
commit.save
commit
end
diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb
index 03c0cd3..857935d 100644
--- a/spec/models/project_services/slack_message_spec.rb
+++ b/spec/models/project_services/slack_message_spec.rb
@@ -8,7 +8,7 @@ describe SlackMessage do
context "One build" do
let(:commit) do
commit = FactoryGirl.create(:commit, project: project)
- commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]})
+ commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { test: "ls" }})
commit.save
commit
end
diff --git a/spec/services/create_commit_service_spec.rb b/spec/services/create_commit_service_spec.rb
index ae118e4..c04aaa6 100644
--- a/spec/services/create_commit_service_spec.rb
+++ b/spec/services/create_commit_service_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe CreateCommitService do
let(:service) { CreateCommitService.new }
let(:project) { FactoryGirl.create(:project) }
-
+
describe :execute do
context 'valid params' do
let(:commit) do
@@ -11,8 +11,9 @@ describe CreateCommitService do
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
- ci_yaml_file: gitlab_ci_yaml
- )
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
+ )
end
it { commit.should be_kind_of(Commit) }
@@ -24,15 +25,27 @@ describe CreateCommitService do
context "deploy builds" do
it "calls create_deploy_builds if there are no builds" do
- config = YAML.dump({jobs: [], build_jobs: ["ls"]})
+ config = YAML.dump({production: {deploy: "ls"}})
Commit.any_instance.should_receive(:create_deploy_builds)
- service.execute(project, ref: 'refs/heads/master', before: '00000000', after: '31das312', ci_yaml_file: config)
+ service.execute(project,
+ ref: 'refs/heads/master',
+ before: '00000000',
+ after: '31das312',
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
+ )
end
it "does not call create_deploy_builds if there is build" do
- config = YAML.dump({jobs: ["ls"], build_jobs: ["ls"]})
+ config = YAML.dump({rspec: {test: "ls"},production: {deploy: "ls"}})
Commit.any_instance.should_not_receive(:create_deploy_builds)
- service.execute(project, ref: 'refs/heads/master', before: '00000000', after: '31das312', ci_yaml_file: config)
+ service.execute(project,
+ ref: 'refs/heads/master',
+ before: '00000000',
+ after: '31das312',
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
+ )
end
end
@@ -42,7 +55,8 @@ describe CreateCommitService do
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: gitlab_ci_yaml
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
)
result.should be_persisted
end
@@ -52,41 +66,43 @@ describe CreateCommitService do
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: YAML.dump({})
+ ci_yaml_file: YAML.dump({}),
+ commits: [ { message: "Message" } ]
)
result.should be_false
end
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
- config = YAML.dump({deploy_jobs: [{script: "ls", refs: "0_1"}]})
+ config = YAML.dump({deploy: {deploy: "ls", only: ["0_1"]}})
result = service.execute(project,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: config
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
)
result.should be_persisted
end
end
describe :ci_skip? do
- it "skips commit creation if there is [ci skip] tag in commit message" do
+ it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{message: "some message[ci skip]"}]
- result = service.execute(project,
+ commit = service.execute(project,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits,
ci_yaml_file: gitlab_ci_yaml
)
- result.should be_false
+ commit.builds.any?.should be_false
end
- it "does not skips commit creation if there is no [ci skip] tag in commit message" do
+ it "does not skips builds creation if there is no [ci skip] tag in commit message" do
commits = [{message: "some message"}]
- result = service.execute(project,
+ commit = service.execute(project,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -94,7 +110,7 @@ describe CreateCommitService do
ci_yaml_file: gitlab_ci_yaml
)
- result.should be_persisted
+ commit.builds.first.name.should == "staging"
end
end
diff --git a/spec/support/gitlab_stubs/gitlab_ci.yml b/spec/support/gitlab_stubs/gitlab_ci.yml
index 4f76e36..bf09f73 100644
--- a/spec/support/gitlab_stubs/gitlab_ci.yml
+++ b/spec/support/gitlab_stubs/gitlab_ci.yml
@@ -1,24 +1,39 @@
-# Refs to skip
-skip_refs: “deploy-*”
-
-# Run before each script
before_script:
- - ls
+ - gem install bundler
+ - bundle install
+ - bundle exec rake db:create
+
+rspec:
+ test: "rake spec"
+ tags:
+ - ruby
+ - postgres
+ only:
+ - branches
+
+spinach:
+ test: "rake spinach"
+ tags:
+ - ruby
+ - mysql
+ except:
+ - tags
-# Parallel jobs, each line is parallel build
-jobs:
- - script: "rake spec"
- runner: "ruby,postgres"
- name: "Rspec"
- - script: "rake spinach"
- runner: "ruby,mysql"
- name: "Spinach"
- tags: true
- branches: true
+staging:
+ deploy: "cap deploy stating"
+ tags:
+ - capistrano
+ - debian
+ except:
+ - stable
-# Parallel deploy jobs
-deploy_jobs:
- - "cap deploy production"
- - script: "cap deploy staging"
- refs: staging
- name: "Deploy to staging"
+production:
+ deploy:
+ - cap deploy production
+ - cap notify
+ tags:
+ - capistrano
+ - debian
+ only:
+ - master
+ - /^deploy-.*$/ \ No newline at end of file