BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ccbdb402
Commit
ccbdb402
authored
Jul 09, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate CI job stage entry into CI configuration
parent
1b624ba4
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
24 deletions
+67
-24
entry.rb
lib/gitlab/ci/config/node/entry.rb
+11
-5
job.rb
lib/gitlab/ci/config/node/job.rb
+24
-0
stage.rb
lib/gitlab/ci/config/node/stage.rb
+2
-2
gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+3
-3
global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+2
-2
job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+10
-2
jobs_spec.rb
spec/lib/gitlab/ci/config/node/jobs_spec.rb
+4
-3
stage_spec.rb
spec/lib/gitlab/ci/config/node/stage_spec.rb
+11
-7
No files found.
lib/gitlab/ci/config/node/entry.rb
View file @
ccbdb402
...
@@ -20,21 +20,21 @@ module Gitlab
...
@@ -20,21 +20,21 @@ module Gitlab
end
end
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
@validator
.
validate
(
:new
)
end
end
def
process!
def
process!
return
unless
valid?
return
unless
valid?
nodes
.
each
do
|
key
,
essence
|
compose!
@entries
[
key
]
=
create
(
key
,
essence
)
end
@entries
.
each_value
(
&
:process!
)
@entries
.
each_value
(
&
:process!
)
end
end
def
validate!
def
validate!
if
@validator
.
valid?
(
:new
)
@validator
.
validate
(
:processed
)
@validator
.
validate
(
:processed
)
end
@entries
.
each_value
(
&
:validate!
)
@entries
.
each_value
(
&
:validate!
)
end
end
...
@@ -95,6 +95,12 @@ module Gitlab
...
@@ -95,6 +95,12 @@ module Gitlab
private
private
def
compose!
nodes
.
each
do
|
key
,
essence
|
@entries
[
key
]
=
create
(
key
,
essence
)
end
end
def
create
(
entry
,
essence
)
def
create
(
entry
,
essence
)
raise
NotImplementedError
raise
NotImplementedError
end
end
...
...
lib/gitlab/ci/config/node/job.rb
View file @
ccbdb402
...
@@ -7,6 +7,30 @@ module Gitlab
...
@@ -7,6 +7,30 @@ module Gitlab
#
#
class
Job
<
Entry
class
Job
<
Entry
include
Configurable
include
Configurable
node
:stage
,
Stage
,
description:
'Pipeline stage this job will be executed into.'
node
:type
,
Stage
,
description:
'Deprecated: stage this job will be executed into.'
helpers
:stage
,
:type
def
value
@config
.
merge
(
stage:
stage_value
)
end
private
def
compose!
super
if
type_defined?
&&
!
stage_defined?
@entries
[
:stage
]
=
@entries
[
:type
]
end
@entries
.
delete
(
:type
)
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/stage.rb
View file @
ccbdb402
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
include
Validatable
include
Validatable
validations
do
validations
do
validates
:config
,
key:
true
validates
:config
,
type:
String
validates
:global
,
required_attribute:
true
validates
:global
,
required_attribute:
true
validate
:known_stage
,
on: :processed
validate
:known_stage
,
on: :processed
...
@@ -27,7 +27,7 @@ module Gitlab
...
@@ -27,7 +27,7 @@ module Gitlab
end
end
def
self
.
default
def
self
.
default
:test
'test'
end
end
end
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
ccbdb402
...
@@ -1082,21 +1082,21 @@ EOT
...
@@ -1082,21 +1082,21 @@ EOT
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
1
}
})
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
1
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: stage parameter should be build, test, deploy
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:type config should be a string
"
)
end
end
it
"returns errors if job stage is not a pre-defined stage"
do
it
"returns errors if job stage is not a pre-defined stage"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: stage parameter should be build, test, deploy
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:type config should be one of defined stages (build, test, deploy)
"
)
end
end
it
"returns errors if job stage is not a defined stage"
do
it
"returns errors if job stage is not a defined stage"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: stage parameter should be build, test
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:type config should be one of defined stages (build, test)
"
)
end
end
it
"returns errors if stages is not an array"
do
it
"returns errors if stages is not an array"
do
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
ccbdb402
...
@@ -129,8 +129,8 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -129,8 +129,8 @@ describe Gitlab::Ci::Config::Node::Global do
describe
'#jobs'
do
describe
'#jobs'
do
it
'returns jobs configuration'
do
it
'returns jobs configuration'
do
expect
(
global
.
jobs
)
expect
(
global
.
jobs
)
.
to
eq
(
rspec:
{
script:
'rspec'
},
.
to
eq
(
rspec:
{
script:
'rspec'
,
stage:
'test'
},
spinach:
{
script:
'spinach'
})
spinach:
{
script:
'spinach'
,
stage:
'test'
})
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
ccbdb402
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
global:
global
)
}
let
(
:global
)
{
spy
(
'Global'
)
}
describe
'validations'
do
describe
'validations'
do
before
do
entry
.
process!
entry
.
validate!
end
context
'when entry config value is correct'
do
context
'when entry config value is correct'
do
let
(
:config
)
{
{
script:
'rspec'
}
}
let
(
:config
)
{
{
script:
'rspec'
}
}
describe
'#value'
do
describe
'#value'
do
it
'returns key value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
script:
'rspec'
)
expect
(
entry
.
value
)
.
to
eq
(
script:
'rspec'
,
stage:
'test'
)
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
ccbdb402
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Jobs
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Jobs
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
global:
spy
)
}
describe
'validations'
do
describe
'validations'
do
context
'when entry config value is correct'
do
context
'when entry config value is correct'
do
...
@@ -61,8 +61,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
...
@@ -61,8 +61,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
describe
'#value'
do
describe
'#value'
do
it
'returns key value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
rspec:
{
script:
'rspec'
},
expect
(
entry
.
value
)
spinach:
{
script:
'spinach'
})
.
to
eq
(
rspec:
{
script:
'rspec'
,
stage:
'test'
},
spinach:
{
script:
'spinach'
,
stage:
'test'
})
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/stage_spec.rb
View file @
ccbdb402
...
@@ -6,7 +6,11 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -6,7 +6,11 @@ describe Gitlab::Ci::Config::Node::Stage do
describe
'validations'
do
describe
'validations'
do
context
'when stage config value is correct'
do
context
'when stage config value is correct'
do
let
(
:config
)
{
:build
}
let
(
:config
)
{
'build'
}
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
(
%w[build]
)
end
describe
'#value'
do
describe
'#value'
do
it
'returns a stage key'
do
it
'returns a stage key'
do
...
@@ -39,16 +43,16 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -39,16 +43,16 @@ describe Gitlab::Ci::Config::Node::Stage do
it
'reports errors about wrong type'
do
it
'reports errors about wrong type'
do
expect
(
stage
.
errors
)
expect
(
stage
.
errors
)
.
to
include
'stage config should be a string
or symbol
'
.
to
include
'stage config should be a string'
end
end
end
end
context
'when stage is not present in global configuration'
do
context
'when stage is not present in global configuration'
do
let
(
:config
)
{
:unknown
}
let
(
:config
)
{
'unknown'
}
before
do
before
do
allow
(
global
)
allow
(
global
)
.
to
receive
(
:stages
).
and_return
(
[
:test
,
:
deploy
])
.
to
receive
(
:stages
).
and_return
(
%w[test
deploy]
)
end
end
it
'reports error about missing stage'
do
it
'reports error about missing stage'
do
...
@@ -65,7 +69,7 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -65,7 +69,7 @@ describe Gitlab::Ci::Config::Node::Stage do
describe
'#known?'
do
describe
'#known?'
do
before
do
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
(
[
:test
,
:
deploy
])
allow
(
global
).
to
receive
(
:stages
).
and_return
(
%w[test
deploy]
)
end
end
context
'when stage is not known'
do
context
'when stage is not known'
do
...
@@ -77,7 +81,7 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -77,7 +81,7 @@ describe Gitlab::Ci::Config::Node::Stage do
end
end
context
'when stage is known'
do
context
'when stage is known'
do
let
(
:config
)
{
:test
}
let
(
:config
)
{
'test'
}
it
'returns false'
do
it
'returns false'
do
expect
(
stage
.
known?
).
to
be
true
expect
(
stage
.
known?
).
to
be
true
...
@@ -87,7 +91,7 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -87,7 +91,7 @@ describe Gitlab::Ci::Config::Node::Stage do
describe
'.default'
do
describe
'.default'
do
it
'returns default stage'
do
it
'returns default stage'
do
expect
(
described_class
.
default
).
to
eq
:test
expect
(
described_class
.
default
).
to
eq
'test'
end
end
end
end
end
end
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