From f7c80e9f31944c0001c9bef23d1a8efe33e4adce Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 15:05:46 +0200 Subject: [PATCH] Revert references to global node in CI job entry --- lib/ci/gitlab_ci_yaml_processor.rb | 8 +- lib/gitlab/ci/config/node/job.rb | 20 +-- spec/lib/gitlab/ci/config/node/global_spec.rb | 6 +- spec/lib/gitlab/ci/config/node/job_spec.rb | 116 ------------------ spec/lib/gitlab/ci/config/node/jobs_spec.rb | 2 - 5 files changed, 8 insertions(+), 144 deletions(-) diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index e18d5b907b4..144f9cd7b74 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -80,7 +80,7 @@ module Ci { stage_idx: @stages.index(job[:stage]), stage: job[:stage], - commands: job[:commands], + commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"), tag_list: job[:tags] || [], name: name, only: job[:only], @@ -112,12 +112,8 @@ module Ci end def validate_job_keys!(name, job) - ## - # TODO, remove refactoring keys - # - refactoring_keys = [:commands] job.keys.each do |key| - unless (ALLOWED_JOB_KEYS + refactoring_keys).include? key + unless ALLOWED_JOB_KEYS.include? key raise ValidationError, "#{name} job: unknown parameter #{key}" end end diff --git a/lib/gitlab/ci/config/node/job.rb b/lib/gitlab/ci/config/node/job.rb index 822b428926a..f01a46a8ddc 100644 --- a/lib/gitlab/ci/config/node/job.rb +++ b/lib/gitlab/ci/config/node/job.rb @@ -43,25 +43,13 @@ module Gitlab @config.merge(to_hash.compact) end - def before_script - if before_script_defined? - before_script_value - else - @global.before_script - end - end - - def commands - [before_script, script].compact.join("\n") - end - private def to_hash - { script: script, - stage: stage, - commands: commands, - after_script: after_script } + { before_script: before_script_value, + script: script_value, + stage: stage_value, + after_script: after_script_value } end def compose! diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index fa5ff016995..dfcaebe35be 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -130,11 +130,9 @@ describe Gitlab::Ci::Config::Node::Global do it 'returns jobs configuration' do expect(global.jobs) .to eq(rspec: { script: %w[rspec ls], - stage: 'test', - commands: "ls\npwd\nrspec\nls" }, + stage: 'test' }, spinach: { script: %w[spinach], - stage: 'test', - commands: "ls\npwd\nspinach" }) + stage: 'test' }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 2ac7509cb6d..ee3eea9c27a 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -66,131 +66,15 @@ describe Gitlab::Ci::Config::Node::Job do expect(entry.value) .to eq(before_script: %w[ls pwd], script: %w[rspec], - commands: "ls\npwd\nrspec", stage: 'test', after_script: %w[cleanup]) end end end - describe '#before_script' do - context 'when global entry has before script' do - before do - allow(global).to receive(:before_script) - .and_return(%w[ls pwd]) - end - - context 'when before script is overridden' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[whoami] - end - end - - context 'when before script is not overriden' do - let(:config) do - { script: %w[spinach] } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[ls pwd] - end - end - end - - context 'when global entry does not have before script' do - before do - allow(global).to receive(:before_script) - .and_return(nil) - end - - context 'when job has before script' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[whoami] - end - end - - context 'when job does not have before script' do - let(:config) do - { script: %w[ls test] } - end - - it 'returns correct script' do - expect(entry.before_script).to be_nil - end - end - end - end - describe '#relevant?' do it 'is a relevant entry' do expect(entry).to be_relevant end end - - describe '#commands' do - context 'when global entry has before script' do - before do - allow(global).to receive(:before_script) - .and_return(%w[ls pwd]) - end - - context 'when before script is overridden' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "whoami\nrspec" - end - end - - context 'when before script is not overriden' do - let(:config) do - { script: %w[rspec spinach] } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "ls\npwd\nrspec\nspinach" - end - end - end - - context 'when global entry does not have before script' do - before do - allow(global).to receive(:before_script) - .and_return(nil) - end - context 'when job has before script' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "whoami\nrspec" - end - end - - context 'when job does not have before script' do - let(:config) do - { script: %w[ls test] } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "ls\ntest" - end - end - end - end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index fe7ae61ed81..40837b5f857 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -64,10 +64,8 @@ describe Gitlab::Ci::Config::Node::Jobs do it 'returns key value' do expect(entry.value) .to eq(rspec: { script: %w[rspec], - commands: 'rspec', stage: 'test' }, spinach: { script: %w[spinach], - commands: 'spinach', stage: 'test' }) end end