diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 14:56:09 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 16:04:35 +0200 |
commit | efdf54f25a83462a750cacd4ea7919c7d38e67d1 (patch) | |
tree | e1823788941ac74352446c065a26b79eb22f985d /app | |
parent | d841ed56d39db1b33947b9b9c0291beaa7dcdd43 (diff) | |
download | gitlab-ci-efdf54f25a83462a750cacd4ea7919c7d38e67d1.tar.gz |
Allow to specify flexible list of types in yaml
```
types:
- test
- deploy
- notify
rspec:
script: "rspec"
rubocop:
script: "rubocop"
staging:
type: deploy
script: "echo deploy"
only:
- master
production:
type: deploy
script: "echo production"
only:
- tags
dockerhub:
type: notify
script: "curl http://docker/hub/web/hook"
downstream:
type: notify
script: "curl http://build/downstream/jobs"
```
This will trigger two test jobs in parallel, when finished it will trigged either staging or production, when finished it will trigger dockerhub and downstream in parallel.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/lints_controller.rb | 2 | ||||
-rw-r--r-- | app/models/build.rb | 4 | ||||
-rw-r--r-- | app/models/commit.rb | 86 | ||||
-rw-r--r-- | app/services/create_commit_service.rb | 4 | ||||
-rw-r--r-- | app/views/builds/_build.html.haml | 10 | ||||
-rw-r--r-- | app/views/commits/_commit.html.haml | 4 | ||||
-rw-r--r-- | app/views/commits/show.html.haml | 4 | ||||
-rw-r--r-- | app/views/lints/_create.html.haml | 48 |
8 files changed, 75 insertions, 87 deletions
diff --git a/app/controllers/lints_controller.rb b/app/controllers/lints_controller.rb index 9d5f445..b6ff69c 100644 --- a/app/controllers/lints_controller.rb +++ b/app/controllers/lints_controller.rb @@ -10,8 +10,8 @@ class LintsController < ApplicationController @error = "Please provide content of .gitlab-ci.yml" else @config_processor = GitlabCiYamlProcessor.new params[:content] + @types = @config_processor.types @builds = @config_processor.builds - @deploy_builds = @config_processor.deploy_builds @status = true end rescue GitlabCiYamlProcessor::ValidationError => e diff --git a/app/models/build.rb b/app/models/build.rb index 5e6522d..11bd967 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -111,8 +111,8 @@ class Build < ActiveRecord::Base WebHookService.new.build_end(build) end - if build.commit.success? && !build.deploy? - build.commit.create_deploy_builds + if build.commit.success? + build.commit.create_next_builds end project.execute_services(build) diff --git a/app/models/commit.rb b/app/models/commit.rb index e173ed4..c7584c6 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -93,67 +93,67 @@ class Commit < ActiveRecord::Base recipients.uniq end - def create_builds - return if skip_ci? + def job_type + return unless config_processor + job_types = builds_without_retry.select(&:active?).map(&:job_type) + config_processor.types.find { |job_type| job_types.include? job_type } + end - begin - builds_for_ref = config_processor.builds_for_ref(ref, tag) - rescue GitlabCiYamlProcessor::ValidationError => e - save_yaml_error(e.message) and return - rescue Exception => e - logger.error e.message + "\n" + e.backtrace.join("\n") - save_yaml_error("Undefined yaml error") and return - end + def create_builds_for_type(job_type) + return if skip_ci? + return unless config_processor - builds_for_ref.each do |build_attrs| + builds_attrs = config_processor.builds_for_type_and_ref(job_type, ref, tag) + builds_attrs.map do |build_attrs| builds.create!({ project: project, name: build_attrs[:name], commands: build_attrs[:script], tag_list: build_attrs[:tags], options: build_attrs[:options], - allow_failure: build_attrs[:allow_failure] + allow_failure: build_attrs[:allow_failure], + job_type: build_attrs[:type] }) end end + def create_next_builds + return if skip_ci? + return unless config_processor + + build_types = builds.group_by(&:job_type) + + config_processor.types.any? do |job_type| + !build_types.include?(job_type) && create_builds_for_type(job_type).present? + end + end + + def create_builds + return if skip_ci? + return unless config_processor + + config_processor.types.any? do |job_type| + create_builds_for_type(job_type).present? + end + end + def builds_without_retry + return unless config_processor @builds_without_retry ||= begin + job_types = config_processor.types grouped_builds = builds.group_by(&:name) - grouped_builds.map do |name, builds| + grouped_builds = grouped_builds.map do |name, builds| builds.sort_by(&:id).last end + grouped_builds.sort_by do |build| + [job_types.index(build.job_type), build.name] + end end end def retried_builds - @retried_builds ||= (builds - builds_without_retry) - end - - def create_deploy_builds - return if skip_ci? - - begin - deploy_builds_for_ref = config_processor.deploy_builds_for_ref(ref, tag) - rescue GitlabCiYamlProcessor::ValidationError => e - save_yaml_error(e.message) and return - rescue Exception => e - logger.error e.message + "\n" + e.backtrace.join("\n") - save_yaml_error("Undefined yaml error") and return - end - - deploy_builds_for_ref.each do |build_attrs| - builds.create!({ - project: project, - name: build_attrs[:name], - commands: build_attrs[:script], - tag_list: build_attrs[:tags], - options: build_attrs[:options], - allow_failure: build_attrs[:allow_failure], - deploy: true - }) - end + @retried_builds ||= (builds.order(id: :desc) - builds_without_retry) end def status @@ -225,6 +225,13 @@ class Commit < ActiveRecord::Base def config_processor @config_processor ||= GitlabCiYamlProcessor.new(push_data[:ci_yaml_file] || project.generated_yaml_config) + rescue GitlabCiYamlProcessor::ValidationError => e + save_yaml_error(e.message) + nil + rescue Exception => e + logger.error e.message + "\n" + e.backtrace.join("\n") + save_yaml_error("Undefined yaml error") + nil end def skip_ci? @@ -235,6 +242,7 @@ class Commit < ActiveRecord::Base private def save_yaml_error(error) + return unless self.yaml_errors? self.yaml_errors = error save end diff --git a/app/services/create_commit_service.rb b/app/services/create_commit_service.rb index f9d16a5..4ae1852 100644 --- a/app/services/create_commit_service.rb +++ b/app/services/create_commit_service.rb @@ -42,10 +42,6 @@ class CreateCommitService commit.create_builds unless commit.builds.any? - if commit.builds.empty? - commit.create_deploy_builds - end - commit end end diff --git a/app/views/builds/_build.html.haml b/app/views/builds/_build.html.haml index f2a340d..598f734 100644 --- a/app/views/builds/_build.html.haml +++ b/app/views/builds/_build.html.haml @@ -7,14 +7,8 @@ %strong Build ##{build.id} %td - - if build.commit.tag? - Tag - · - #{build.ref} - - else - Commit - · - #{build.short_sha} + = build.job_type + %td = build.name .pull-right diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml index e5068d2..7fae74e 100644 --- a/app/views/commits/_commit.html.haml +++ b/app/views/commits/_commit.html.haml @@ -1,6 +1,10 @@ %tr.build.alert{class: commit_status_alert_class(commit)} %td.status = commit.status + - if commit.running? + · + = commit.job_type + %td.build-link = link_to project_ref_commit_path(commit.project, commit.ref, commit.sha) do diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index b1b586c..5925b9d 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -68,7 +68,7 @@ %tr %th Status %th Build ID - %th Trigger + %th Type %th Name %th Duration %th Finished at @@ -86,7 +86,7 @@ %tr %th Status %th Build ID - %th Trigger + %th Type %th Name %th Duration %th Finished at diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml index 70b6f8c..f82b406 100644 --- a/app/views/lints/_create.html.haml +++ b/app/views/lints/_create.html.haml @@ -10,37 +10,23 @@ %th Parameter %th Value %tbody - - @builds.each do |build| - %tr - %td Job - #{build[:name]} - %td - %pre - = simple_format build[:script] - - %b Tag list: - = build[:tags] - %br - %b Refs only: - = build[:only] && build[:only].join(", ") - %br - %b Refs except: - = build[:except] && build[:except].join(", ") + - @types.each do |type| + - @builds.select { |build| build[:type] == type }.each do |build| + %tr + %td #{type.capitalize} Job - #{build[:name]} + %td + %pre + = simple_format build[:script] - - @deploy_builds.each do |build| - %tr - %td Deploy Job - #{build[:name]} - %td - %pre - = simple_format build[:script] - - %b Tag list: - = build[:tags] - %br - %b Refs only: - = build[:only] && build[:only].join(", ") - %br - %b Refs except: - = build[:except] && build[:except].join(", ") + %br + %b Tag list: + = build[:tags] + %br + %b Refs only: + = build[:only] && build[:only].join(", ") + %br + %b Refs except: + = build[:except] && build[:except].join(", ") -else %p @@ -49,5 +35,5 @@ %i.icon-remove.incorrect-syntax %b Error: = @error - +
\ No newline at end of file |