Commit d3991289 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Handle after script CI config in new classes

This also makes Script to return an array of commands instead of
concatented command, which is our current direction.
parent fc00c545
......@@ -14,7 +14,7 @@ module Ci
ALLOWED_CACHE_KEYS = [:key, :untracked, :paths]
ALLOWED_ARTIFACTS_KEYS = [:name, :untracked, :paths, :when, :expire_in]
attr_reader :after_script, :path, :cache
attr_reader :path, :cache
def initialize(config, path = nil)
@ci_config = Gitlab::Ci::Config.new(config)
......@@ -65,10 +65,9 @@ module Ci
def initial_parsing
@before_script = @ci_config.before_script
@image = @ci_config.image
@after_script = @config[:after_script]
@image = @config[:image]
@after_script = @ci_config.after_script
@services = @ci_config.services
@stages = @config[:stages] || @config[:types]
@variables = @config[:variables] || {}
@cache = @config[:cache]
......@@ -93,7 +92,7 @@ module Ci
{
stage_idx: stages.index(job[:stage]),
stage: job[:stage],
commands: [job[:before_script] || [@before_script], job[:script]].flatten.compact.join("\n"),
commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
tag_list: job[:tags] || [],
name: name,
only: job[:only],
......@@ -123,10 +122,6 @@ module Ci
end
def validate_global!
unless @after_script.nil? || validate_array_of_strings(@after_script)
raise ValidationError, "after_script should be an array of strings"
end
unless @stages.nil? || validate_array_of_strings(@stages)
raise ValidationError, "stages should be an array of strings"
end
......
......@@ -7,7 +7,7 @@ module Gitlab
##
# Temporary delegations that should be removed after refactoring
#
delegate :before_script, :image, :services, to: :@global
delegate :before_script, :image, :services, :after_script, to: :@global
def initialize(config)
@config = Loader.new(config).load!
......
......@@ -17,6 +17,9 @@ module Gitlab
allow_node :services, Services,
description: 'Docker images that will be linked to the container.'
allow_node :after_script, Script,
description: 'Script that will be executed after each job.'
end
end
end
......
......@@ -5,11 +5,6 @@ module Gitlab
##
# Entry that represents a script.
#
# Each element in the value array is a command that will be executed
# by GitLab Runner. Currently we concatenate these commands with
# new line character as a separator, what is compatible with
# implementation in Runner.
#
class Script < Entry
include Validatable
......@@ -18,7 +13,7 @@ module Gitlab
end
def value
@config.join("\n")
@config
end
end
end
......
......@@ -965,7 +965,7 @@ EOT
config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "after_script should be an array of strings")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "After script config should be an array of strings")
end
it "returns errors if job after_script parameter is not an array of strings" do
......
......@@ -11,7 +11,7 @@ describe Gitlab::Ci::Config::Node::Factory do
.with(value: ['ls', 'pwd'])
.create!
expect(entry.value).to eq "ls\npwd"
expect(entry.value).to eq ['ls', 'pwd']
end
context 'when setting description' do
......@@ -21,7 +21,7 @@ describe Gitlab::Ci::Config::Node::Factory do
.with(description: 'test description')
.create!
expect(entry.value).to eq "ls\npwd"
expect(entry.value).to eq ['ls', 'pwd']
expect(entry.description).to eq 'test description'
end
end
......
......@@ -23,7 +23,8 @@ describe Gitlab::Ci::Config::Node::Global do
let(:hash) do
{ before_script: ['ls', 'pwd'],
image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'] }
services: ['postgres:9.1', 'mysql:5.5'],
after_script: ['make clean'] }
end
describe '#process!' do
......@@ -34,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
it 'creates node object for each entry' do
expect(global.nodes.count).to eq 3
expect(global.nodes.count).to eq 4
end
it 'creates node object using valid class' do
......@@ -71,7 +72,7 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#before_script' do
it 'returns correct script' do
expect(global.before_script).to eq "ls\npwd"
expect(global.before_script).to eq ['ls', 'pwd']
end
end
......@@ -86,6 +87,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.services).to eq ['postgres:9.1', 'mysql:5.5']
end
end
describe '#after_script' do
it 'returns after script' do
expect(global.after_script).to eq ['make clean']
end
end
end
end
......
......@@ -10,8 +10,8 @@ describe Gitlab::Ci::Config::Node::Script do
let(:config) { ['ls', 'pwd'] }
describe '#value' do
it 'returns concatenated command' do
expect(entry.value).to eq "ls\npwd"
it 'returns array of strings' do
expect(entry.value).to eq config
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment