Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
70bda3e8
Commit
70bda3e8
authored
Jun 07, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement script in Ci config and use in legacy one
parent
c2d6d61d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
13 deletions
+51
-13
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+1
-1
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+5
-0
lib/gitlab/ci/config/node/before_script.rb
lib/gitlab/ci/config/node/before_script.rb
+10
-0
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+4
-0
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+4
-0
spec/lib/gitlab/ci/config/node/before_script_spec.rb
spec/lib/gitlab/ci/config/node/before_script_spec.rb
+19
-6
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+8
-6
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
70bda3e8
...
@@ -82,7 +82,7 @@ module Ci
...
@@ -82,7 +82,7 @@ module Ci
{
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
stage:
job
[
:stage
],
commands:
[
job
[
:before_script
]
||
@before_script
,
job
[
:script
]].
flatten
.
join
(
"
\n
"
),
commands:
[
job
[
:before_script
]
||
[
@ci_config
.
before_script
],
job
[
:script
]].
flatten
.
compact
.
join
(
"
\n
"
),
tag_list:
job
[
:tags
]
||
[],
tag_list:
job
[
:tags
]
||
[],
name:
name
,
name:
name
,
only:
job
[
:only
],
only:
job
[
:only
],
...
...
lib/gitlab/ci/config.rb
View file @
70bda3e8
...
@@ -5,6 +5,11 @@ module Gitlab
...
@@ -5,6 +5,11 @@ module Gitlab
delegate
:valid?
,
:errors
,
to: :@global
delegate
:valid?
,
:errors
,
to: :@global
##
# Temporary delegations that should be removed after refactoring
#
delegate
:before_script
,
to: :@global
def
initialize
(
config
)
def
initialize
(
config
)
loader
=
Loader
.
new
(
config
)
loader
=
Loader
.
new
(
config
)
...
...
lib/gitlab/ci/config/node/before_script.rb
View file @
70bda3e8
...
@@ -5,6 +5,16 @@ module Gitlab
...
@@ -5,6 +5,16 @@ module Gitlab
class
BeforeScript
<
Entry
class
BeforeScript
<
Entry
include
ValidationHelpers
include
ValidationHelpers
def
description
'Script that is executed before the one defined in a job.'
end
def
script
raise
unless
valid?
@value
.
join
(
"
\n
"
)
end
def
validate!
def
validate!
unless
validate_array_of_strings
(
@value
)
unless
validate_array_of_strings
(
@value
)
@errors
<<
'before_script should be an array of strings'
@errors
<<
'before_script should be an array of strings'
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
70bda3e8
...
@@ -55,6 +55,10 @@ module Gitlab
...
@@ -55,6 +55,10 @@ module Gitlab
raise
NotImplementedError
raise
NotImplementedError
end
end
def
description
raise
NotImplementedError
end
class
<<
self
class
<<
self
attr_reader
:nodes
attr_reader
:nodes
...
...
lib/gitlab/ci/config/node/global.rb
View file @
70bda3e8
...
@@ -4,6 +4,10 @@ module Gitlab
...
@@ -4,6 +4,10 @@ module Gitlab
module
Node
module
Node
class
Global
<
Entry
class
Global
<
Entry
add_node
:before_script
,
BeforeScript
add_node
:before_script
,
BeforeScript
def
before_script
@before_script
.
script
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/before_script_spec.rb
View file @
70bda3e8
...
@@ -2,25 +2,38 @@ require 'spec_helper'
...
@@ -2,25 +2,38 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
BeforeScript
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
BeforeScript
do
let
(
:entry
)
{
described_class
.
new
(
value
,
double
)}
let
(
:entry
)
{
described_class
.
new
(
value
,
double
)}
describe
'#validate!'
do
before
{
entry
.
validate!
}
before
{
entry
.
validate!
}
context
'when entry value is correct'
do
context
'when entry value is correct'
do
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
describe
'#script'
do
it
'returns concatenated command'
do
expect
(
entry
.
script
).
to
eq
"ls
\n
pwd"
end
end
describe
'#errors'
do
it
'does not append errors'
do
it
'does not append errors'
do
expect
(
entry
.
errors
).
to
be_empty
expect
(
entry
.
errors
).
to
be_empty
end
end
end
end
end
context
'when entry value is not correct'
do
context
'when entry value is not correct'
do
let
(
:value
)
{
'ls'
}
let
(
:value
)
{
'ls'
}
describe
'#errors'
do
it
'saves errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
expect
(
entry
.
errors
)
.
to
include
/should be an array of strings/
.
to
include
/should be an array of strings/
end
end
end
end
describe
'#script'
do
it
'raises error'
do
expect
{
entry
.
script
}.
to
raise_error
end
end
end
end
end
end
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
70bda3e8
...
@@ -3,6 +3,8 @@ require 'spec_helper'
...
@@ -3,6 +3,8 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Global
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Global
do
let
(
:global
)
{
described_class
.
new
(
hash
)
}
let
(
:global
)
{
described_class
.
new
(
hash
)
}
before
{
global
.
process!
}
describe
'#keys'
do
describe
'#keys'
do
it
'can contain global config keys'
do
it
'can contain global config keys'
do
expect
(
global
.
keys
).
to
include
:before_script
expect
(
global
.
keys
).
to
include
:before_script
...
@@ -19,8 +21,6 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -19,8 +21,6 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe
'#process!'
do
describe
'#process!'
do
before
{
global
.
process!
}
it
'creates nodes hash'
do
it
'creates nodes hash'
do
expect
(
global
.
nodes
).
to
be_an
Array
expect
(
global
.
nodes
).
to
be_an
Array
end
end
...
@@ -40,6 +40,12 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -40,6 +40,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect
(
global
).
not_to
be_leaf
expect
(
global
).
not_to
be_leaf
end
end
end
end
describe
'#before_script'
do
it
'returns correct script'
do
expect
(
global
.
before_script
).
to
eq
"ls
\n
pwd"
end
end
end
end
context
'when hash is not valid'
do
context
'when hash is not valid'
do
...
@@ -47,8 +53,6 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -47,8 +53,6 @@ describe Gitlab::Ci::Config::Node::Global do
{
before_script:
'ls'
}
{
before_script:
'ls'
}
end
end
before
{
global
.
process!
}
describe
'#valid?'
do
describe
'#valid?'
do
it
'is not valid'
do
it
'is not valid'
do
expect
(
global
).
not_to
be_valid
expect
(
global
).
not_to
be_valid
...
@@ -66,8 +70,6 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -66,8 +70,6 @@ describe Gitlab::Ci::Config::Node::Global do
context
'when value is not a hash'
do
context
'when value is not a hash'
do
let
(
:hash
)
{
[]
}
let
(
:hash
)
{
[]
}
before
{
global
.
process!
}
describe
'#valid?'
do
describe
'#valid?'
do
it
'is not valid'
do
it
'is not valid'
do
expect
(
global
).
not_to
be_valid
expect
(
global
).
not_to
be_valid
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment