diff options
author | Valery Sizov <valery@gitlab.com> | 2015-06-15 14:18:46 +0000 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2015-06-15 14:18:46 +0000 |
commit | 4fc1a22b1707cf0a99d6843f5ff47a75e16eb964 (patch) | |
tree | fa7291e903ed67676b58b433dd368d6017747e08 | |
parent | 2555bc84b25a1d66c52e2b24768ae7fb1e6dadbb (diff) | |
parent | a0eb5cd539dfd547a82377c8ded16083e5e7073d (diff) | |
download | gitlab-ci-4fc1a22b1707cf0a99d6843f5ff47a75e16eb964.tar.gz |
Merge branch 'new_syntax_fixes' into 'master'
New syntax of .gitlab-ci.yml
https://dev.gitlab.org/gitlab/gitlab-ci/issues/269
- [x] Parser
- [x] Job migrator
- [x] Documentation
See merge request !137
-rw-r--r-- | db/migrate/20150601043227_migrate_jobs_to_yaml.rb (renamed from db/migrate/20150601043226_migrate_jobs_to_yaml.rb) | 9 | ||||
-rw-r--r-- | doc/builds_configuration/README.md | 21 | ||||
-rw-r--r-- | lib/gitlab_ci_yaml_processor.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab_ci_yaml_processor_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/create_commit_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/gitlab_stubs/gitlab_ci.yml | 10 |
6 files changed, 37 insertions, 31 deletions
diff --git a/db/migrate/20150601043226_migrate_jobs_to_yaml.rb b/db/migrate/20150601043227_migrate_jobs_to_yaml.rb index ba7a7dc..32338dc 100644 --- a/db/migrate/20150601043226_migrate_jobs_to_yaml.rb +++ b/db/migrate/20150601043227_migrate_jobs_to_yaml.rb @@ -25,8 +25,8 @@ class MigrateJobsToYaml < ActiveRecord::Migration # Create Jobs select_all(sql).each do |job| config[job["name"].to_s] = { - test: job["commands"] && job["commands"].split("\n").map(&:strip), - tags: job["tags"] + script: job["commands"] && job["commands"].split("\n").map(&:strip), + tags: job["tags"].split(",").map(&:strip) } except = build_except_param(parse_boolean_value(job["build_branches"]), parse_boolean_value(job["build_tags"])) @@ -39,8 +39,9 @@ class MigrateJobsToYaml < ActiveRecord::Migration # Create Deploy Jobs select_all(sql.sub("parallel", 'deploy')).each do |job| config[job["name"].to_s] = { - deploy: job["commands"] && job["commands"].split("\n").map(&:strip), - tags: job["tags"] + script: job["commands"] && job["commands"].split("\n").map(&:strip), + type: "deploy", + tags: job["tags"].split(",").map(&:strip) } except = build_except_param(parse_boolean_value(job["build_branches"]), parse_boolean_value(job["build_tags"])) diff --git a/doc/builds_configuration/README.md b/doc/builds_configuration/README.md index 25d1090..f7405d7 100644 --- a/doc/builds_configuration/README.md +++ b/doc/builds_configuration/README.md @@ -9,7 +9,7 @@ before_script: - bundle exec rake db:create rspec: - test: "rake spec" + script: "rake spec" tags: - ruby - postgres @@ -17,7 +17,8 @@ rspec: - branches staging: - deploy: "cap deploy stating" + script: "cap deploy stating" + type: deploy tags: - capistrano - debian @@ -34,21 +35,21 @@ Here you can specify parameters of your builds: ```yaml rspec: - test: "rake spec" # (required) - shell command for runner - tags: # (optional) - runner tags, only runners which have these tags will be used + script: "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) + only: # (optional) - git refs (branches and tags) - master ``` `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: +`script` is a shell script which is used by runner. It will be also prepanded with `before_script`. This parameter can also cantain several commands using array: ```yaml -test: +script: - uname -a - bundle exec rspec ``` @@ -59,7 +60,8 @@ Deploy Builds that will be run when all other builds have succeeded. Define them ```yaml production: - deploy: "cap deploy production" # (required) - shell command for runner + script: "cap deploy production" # (required) - shell command for runner + type: deploy tags: - ruby - postgres @@ -67,7 +69,8 @@ production: - master ``` `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`. +`script` - is a shell script which will be prepended with `before_script`. +`type: deploy` is a parameter which indicates that it is a deploy job About `only` and `except` parameters you can read in the [refs settings explanation](#refs-settings-explanation) ### before_script diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb index 274754f..9a69ca6 100644 --- a/lib/gitlab_ci_yaml_processor.rb +++ b/lib/gitlab_ci_yaml_processor.rb @@ -7,9 +7,9 @@ class GitlabCiYamlProcessor @config.delete(:before_script) - @jobs = @config.select{|key, value| value[:test]} + @jobs = @config.select{|key, value| value[:type] != "deploy"} - @deploy_jobs = @config.select{|key, value| value[:deploy]} + @deploy_jobs = @config.select{|key, value| value[:type] == "deploy"} end def deploy_builds_for_ref(ref, tag = false) @@ -27,7 +27,7 @@ class GitlabCiYamlProcessor def builds @jobs.map do |name, job| { - script: "#{@before_script.join("\n")}\n#{normilize_script(job[:test])}", + script: "#{@before_script.join("\n")}\n#{normilize_script(job[:script])}", tags: job[:tags] || [], name: name, only: job[:only], @@ -39,7 +39,7 @@ class GitlabCiYamlProcessor def deploy_builds @deploy_jobs.map do |name, job| { - script: "#{@before_script.join("\n")}\n#{normilize_script(job[:deploy])}", + script: "#{@before_script.join("\n")}\n#{normilize_script(job[:script])}", tags: job[:tags] || [], name: name, only: job[:only], diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb index 96dcf64..8976c12 100644 --- a/spec/lib/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb @@ -6,7 +6,7 @@ describe GitlabCiYamlProcessor do it "returns builds if no branch specified" do config = YAML.dump({ before_script: ["pwd"], - rspec: {test: "rspec"} + rspec: {script: "rspec"} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -24,7 +24,7 @@ describe GitlabCiYamlProcessor do it "does not return builds if only has another branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {test: "rspec", only: ["deploy"]} + rspec: {script: "rspec", only: ["deploy"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -35,7 +35,7 @@ describe GitlabCiYamlProcessor do it "does not return builds if only has regexp with another branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {test: "rspec", only: ["/^deploy$/"]} + rspec: {script: "rspec", only: ["/^deploy$/"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -46,7 +46,7 @@ describe GitlabCiYamlProcessor do it "returns builds if only has specified this branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {test: "rspec", only: ["master"]} + rspec: {script: "rspec", only: ["master"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -57,7 +57,7 @@ describe GitlabCiYamlProcessor do it "does not build tags" do config = YAML.dump({ before_script: ["pwd"], - rspec: {test: "rspec", exclude: ["tags"]} + rspec: {script: "rspec", exclude: ["tags"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -70,7 +70,7 @@ describe GitlabCiYamlProcessor do it "returns builds if no branch specified" do config = YAML.dump({ before_script: ["pwd"], - rspec: {deploy: "rspec"} + rspec: {script: "rspec", type: "deploy"} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -88,7 +88,7 @@ describe GitlabCiYamlProcessor do it "does not return builds if only has another branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {deploy: "rspec", only: ["deploy"]} + rspec: {script: "rspec", type: "deploy", only: ["deploy"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -99,7 +99,7 @@ describe GitlabCiYamlProcessor do it "does not return builds if only has regexp with another branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {deploy: "rspec", only: ["/^deploy$/"]} + rspec: {script: "rspec", type: "deploy", only: ["/^deploy$/"]} }) config_processor = GitlabCiYamlProcessor.new(config) @@ -110,7 +110,7 @@ describe GitlabCiYamlProcessor do it "returns builds if only has specified this branch" do config = YAML.dump({ before_script: ["pwd"], - rspec: {deploy: "rspec", only: ["master"]} + rspec: {script: "rspec", type: "deploy", only: ["master"]} }) config_processor = GitlabCiYamlProcessor.new(config) diff --git a/spec/services/create_commit_service_spec.rb b/spec/services/create_commit_service_spec.rb index c04aaa6..f6255f6 100644 --- a/spec/services/create_commit_service_spec.rb +++ b/spec/services/create_commit_service_spec.rb @@ -25,7 +25,7 @@ describe CreateCommitService do context "deploy builds" do it "calls create_deploy_builds if there are no builds" do - config = YAML.dump({production: {deploy: "ls"}}) + config = YAML.dump({production: {script: "ls", type: "deploy"}}) Commit.any_instance.should_receive(:create_deploy_builds) service.execute(project, ref: 'refs/heads/master', diff --git a/spec/support/gitlab_stubs/gitlab_ci.yml b/spec/support/gitlab_stubs/gitlab_ci.yml index bf09f73..5de4e6d 100644 --- a/spec/support/gitlab_stubs/gitlab_ci.yml +++ b/spec/support/gitlab_stubs/gitlab_ci.yml @@ -4,7 +4,7 @@ before_script: - bundle exec rake db:create rspec: - test: "rake spec" + script: "rake spec" tags: - ruby - postgres @@ -12,7 +12,7 @@ rspec: - branches spinach: - test: "rake spinach" + script: "rake spinach" tags: - ruby - mysql @@ -20,7 +20,8 @@ spinach: - tags staging: - deploy: "cap deploy stating" + script: "cap deploy stating" + type: deploy tags: - capistrano - debian @@ -28,7 +29,8 @@ staging: - stable production: - deploy: + type: deploy + script: - cap deploy production - cap notify tags: |