diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/sections/lint.scss | 8 | ||||
-rw-r--r-- | app/controllers/lints_controller.rb | 22 | ||||
-rw-r--r-- | app/views/lints/_create.html.haml | 53 | ||||
-rw-r--r-- | app/views/lints/create.js.haml | 2 | ||||
-rw-r--r-- | app/views/lints/show.html.haml | 25 | ||||
-rw-r--r-- | app/views/projects/_form.html.haml | 4 | ||||
-rw-r--r-- | app/views/shared/_guide.html.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | doc/builds_configuration/README.md | 10 | ||||
-rw-r--r-- | lib/gitlab_ci_yaml_processor.rb | 8 | ||||
-rw-r--r-- | spec/features/lint_spec.rb | 29 | ||||
-rw-r--r-- | spec/lib/gitlab_ci_yaml_processor_spec.rb | 6 |
13 files changed, 161 insertions, 11 deletions
@@ -10,6 +10,7 @@ v7.12.0 - Dont retry build when push same commit in same ref twice - Admin area: show amount of runners with last contact less than a minute ago - Fix re-adding project with the same name but different gitlab_id + - Implementation of Lint (.gitlab-ci.yml validation tool) v7.11.0 - Deploy Jobs API calls diff --git a/app/assets/stylesheets/sections/lint.scss b/app/assets/stylesheets/sections/lint.scss new file mode 100644 index 0000000..7191b5d --- /dev/null +++ b/app/assets/stylesheets/sections/lint.scss @@ -0,0 +1,8 @@ +.incorrect-syntax{ + font-size: 19px; + color: red; +} +.correct-syntax{ + font-size: 19px; + color: #47a447; +}
\ No newline at end of file diff --git a/app/controllers/lints_controller.rb b/app/controllers/lints_controller.rb new file mode 100644 index 0000000..d1b42f6 --- /dev/null +++ b/app/controllers/lints_controller.rb @@ -0,0 +1,22 @@ +class LintsController < ApplicationController + before_filter :authenticate_user! + + def show + end + + def create + if params[:content].blank? + @status = false + @error = "Please provide content of your file" + else + @config_processor = GitlabCiYamlProcessor.new params[:content] + @status = true + end + rescue Psych::SyntaxError => e + @error = e.message + @status = false + rescue Exception => e + @error = "Undefined error" + @status = false + end +end diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml new file mode 100644 index 0000000..64a7d65 --- /dev/null +++ b/app/views/lints/_create.html.haml @@ -0,0 +1,53 @@ +- if @status + %p + %b Status: + syntax is correct + %i.icon-ok.correct-syntax + + %table.table.table-bordered + %thead + %tr + %th Parameter + %th Value + %tbody + - @config_processor.builds.each do |build| + %tr + %td Job - #{build[:name]} + %td + %pre + = simple_format build[:commands] + + %b Tag list: + #{build[:tag_list]} + %br + %b Build for branches: + #{build[:branches] ? "true": "false"} + %br + %b Build for tags: + #{build[:tags] ? "true": "false"} + + - @config_processor.deploy_builds.each do |build| + %tr + %td Deploy Job - #{build[:name]} + %td + %pre + = simple_format build[:commands] + + %b Tag list: + #{build[:tag_list]} + %br + %b Refs: + #{build[:refs]} + + %tr + %td Skip Refs + %td= @config_processor.skip_refs + +-else + %p + %b Status: + syntax is incorrect + %i.icon-remove.incorrect-syntax + Error: #{@error} + +
\ No newline at end of file diff --git a/app/views/lints/create.js.haml b/app/views/lints/create.js.haml new file mode 100644 index 0000000..a96c0b1 --- /dev/null +++ b/app/views/lints/create.js.haml @@ -0,0 +1,2 @@ +:plain + $(".results").html("#{escape_javascript(render "create")}")
\ No newline at end of file diff --git a/app/views/lints/show.html.haml b/app/views/lints/show.html.haml new file mode 100644 index 0000000..d105495 --- /dev/null +++ b/app/views/lints/show.html.haml @@ -0,0 +1,25 @@ +%h2 Check your .gitlab-ci.yml +%hr + += form_tag '/lint', method: :post, remote: true do + .control-group + = label_tag :content, "Content of .gitlab-ci.yml", class: 'control-label' + .controls + = text_area_tag :content, nil, class: 'form-control span1', rows: 7, require: true + + .control-group.clearfix + .controls.pull-left.prepend-top-10 + = submit_tag "Validate", class: 'btn btn-success submit-yml' + + +%p.text-center.loading + %i.icon-refresh.icon-spin + +.results.prepend-top-20 + +:coffeescript + $(".loading").hide() + $('form').bind 'ajax:beforeSend', -> + $(".loading").show() + $('form').bind 'ajax:complete', -> + $(".loading").hide() diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 7f3cc56..e7c1bad 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -1,3 +1,7 @@ +.bs-callout.help-callout + %p + If you want to test your .gitlab-ci.yml, you can use special tool - #{link_to "Lint", lint_path} + = nested_form_for @project, html: { class: 'form-horizontal' } do |f| - if @project.errors.any? #error_explanation diff --git a/app/views/shared/_guide.html.haml b/app/views/shared/_guide.html.haml index a1709dd..8a3f663 100644 --- a/app/views/shared/_guide.html.haml +++ b/app/views/shared/_guide.html.haml @@ -6,7 +6,7 @@ Add at least one runner to the project. Go to #{link_to 'Runners page', project_runners_path(@project), target: :blank} for instructions. %li - Put the .gitlab-ci.yml in the root of your repository. Examples can be found in #{link_to "Configuraton of your builds with .gitlab-ci.yml", "http://doc.gitlab.com/ci/builds_configuration/README.html", target: :blank} + Put the .gitlab-ci.yml in the root of your repository. Examples can be found in #{link_to "Configuraton of your builds with .gitlab-ci.yml", "http://doc.gitlab.com/ci/builds_configuration/README.html", target: :blank}. You can also test your .gitlab-ci.yml in the #{link_to "Lint", lint_path} %li Visit #{link_to 'GitLab project settings', @project.gitlab_url + "/services/gitlab_ci/edit", target: :blank} and press the "Test settings" button. diff --git a/config/routes.rb b/config/routes.rb index 7ad8220..bc77ee8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ Rails.application.routes.draw do API::API.logger Rails.logger mount API::API => '/api' + resource :lint, only: [:show, :create] + resource :help do get :oauth2 end diff --git a/doc/builds_configuration/README.md b/doc/builds_configuration/README.md index 2fca14b..06c2c8e 100644 --- a/doc/builds_configuration/README.md +++ b/doc/builds_configuration/README.md @@ -58,7 +58,7 @@ jobs: ``` In this way, the name of the build will be taken from command line. -## deploy_jobs +### deploy_jobs Deploy Jobs that will be run when all other jobs have succeeded. Define them using a hash: ```yaml @@ -80,5 +80,9 @@ deploy_jobs: - "bundle exec cap deploy" ``` -## 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.
\ No newline at end of file +### 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. + +## Debugging of your builds with .gitlab-ci.yml + +Each instance of GitLab CI has an embeded debug tool Lint. You can find link to the Lint in the projects settings page or use short url `/lint`. diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb index 3368232..32f7938 100644 --- a/lib/gitlab_ci_yaml_processor.rb +++ b/lib/gitlab_ci_yaml_processor.rb @@ -35,13 +35,13 @@ class GitlabCiYamlProcessor def create_commit_for_tag?(ref) normalized_jobs.any?{|job| job[:tags] == true} || - normalized_deploy_jobs.any?{|job| job[:refs].empty? || refs_matches?(job[:refs], ref)} + normalized_deploy_jobs.any?{|job| job[:refs].blank? || refs_matches?(job[:refs].split(",").map(&:strip), ref)} end def deploy_builds_for_ref(ref) deploy_builds.select do |build_attrs| refs = build_attrs.delete(:refs) - refs.empty? || refs_matches?(refs, ref) + refs.blank? || refs_matches?(refs.split(",").map(&:strip), ref) end end @@ -84,11 +84,11 @@ class GitlabCiYamlProcessor def normalized_deploy_jobs @deploy_jobs.map do |job| if job.is_a?(String) - { script: job, runner: "", refs: [], name: job[0..10].strip } + { script: job, runner: "", refs: "", name: job[0..10].strip } else { script: normalized_script(job[:script]), - refs: (job[:refs] || "").split(",").map(&:strip), + refs: job[:refs] || "", name: job[:name] || job[:script][0..10].strip, runner: job[:runner] || "", } diff --git a/spec/features/lint_spec.rb b/spec/features/lint_spec.rb new file mode 100644 index 0000000..4a1ea26 --- /dev/null +++ b/spec/features/lint_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe "Lint" do + before do + login_as :user + end + + it "Yaml parsing", js: true do + content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + visit lint_path + 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") + end + end + + it "Yaml parsing with error", js: true do + visit lint_path + fill_in "content", with: "" + click_on "Validate" + page.should have_content("Status: syntax is incorrect") + page.should have_content("Error: Please provide content of your file") + end +end diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb index 2ce140c..22d0d6b 100644 --- a/spec/lib/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb @@ -68,7 +68,7 @@ describe GitlabCiYamlProcessor do commands: "\nls", name: "ls", deploy: true, - refs: [], + refs: "", tag_list: "" } end @@ -85,7 +85,7 @@ describe GitlabCiYamlProcessor do commands: "pwd\nls", name: "ls", deploy: true, - refs: [], + refs: "", tag_list: "" } end @@ -102,7 +102,7 @@ describe GitlabCiYamlProcessor do commands: "pwd\nls", name: "Rspec", deploy: true, - refs: ["master", "deploy"], + refs: "master,deploy", tag_list: "" } end |