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
end
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
@validator
.
validate
(
:new
)
end
def
process!
return
unless
valid?
nodes
.
each
do
|
key
,
essence
|
@entries
[
key
]
=
create
(
key
,
essence
)
end
compose!
@entries
.
each_value
(
&
:process!
)
end
def
validate!
if
@validator
.
valid?
(
:new
)
@validator
.
validate
(
:processed
)
end
@entries
.
each_value
(
&
:validate!
)
end
...
...
@@ -95,6 +95,12 @@ module Gitlab
private
def
compose!
nodes
.
each
do
|
key
,
essence
|
@entries
[
key
]
=
create
(
key
,
essence
)
end
end
def
create
(
entry
,
essence
)
raise
NotImplementedError
end
...
...
lib/gitlab/ci/config/node/job.rb
View file @
ccbdb402
...
...
@@ -7,6 +7,30 @@ module Gitlab
#
class
Job
<
Entry
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
...
...
lib/gitlab/ci/config/node/stage.rb
View file @
ccbdb402
...
...
@@ -9,7 +9,7 @@ module Gitlab
include
Validatable
validations
do
validates
:config
,
key:
true
validates
:config
,
type:
String
validates
:global
,
required_attribute:
true
validate
:known_stage
,
on: :processed
...
...
@@ -27,7 +27,7 @@ module Gitlab
end
def
self
.
default
:test
'test'
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
ccbdb402
...
...
@@ -1082,21 +1082,21 @@ EOT
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
1
}
})
expect
do
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
it
"returns errors if job stage is not a pre-defined stage"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
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
it
"returns errors if job stage is not a defined stage"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
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
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
describe
'#jobs'
do
it
'returns jobs configuration'
do
expect
(
global
.
jobs
)
.
to
eq
(
rspec:
{
script:
'rspec'
},
spinach:
{
script:
'spinach'
})
.
to
eq
(
rspec:
{
script:
'rspec'
,
stage:
'test'
},
spinach:
{
script:
'spinach'
,
stage:
'test'
})
end
end
end
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
ccbdb402
require
'spec_helper'
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
before
do
entry
.
process!
entry
.
validate!
end
context
'when entry config value is correct'
do
let
(
:config
)
{
{
script:
'rspec'
}
}
describe
'#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
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
ccbdb402
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Jobs
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
global:
spy
)
}
describe
'validations'
do
context
'when entry config value is correct'
do
...
...
@@ -61,8 +61,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
rspec:
{
script:
'rspec'
},
spinach:
{
script:
'spinach'
})
expect
(
entry
.
value
)
.
to
eq
(
rspec:
{
script:
'rspec'
,
stage:
'test'
},
spinach:
{
script:
'spinach'
,
stage:
'test'
})
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
describe
'validations'
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
it
'returns a stage key'
do
...
...
@@ -39,16 +43,16 @@ describe Gitlab::Ci::Config::Node::Stage do
it
'reports errors about wrong type'
do
expect
(
stage
.
errors
)
.
to
include
'stage config should be a string
or symbol
'
.
to
include
'stage config should be a string'
end
end
context
'when stage is not present in global configuration'
do
let
(
:config
)
{
:unknown
}
let
(
:config
)
{
'unknown'
}
before
do
allow
(
global
)
.
to
receive
(
:stages
).
and_return
(
[
:test
,
:
deploy
])
.
to
receive
(
:stages
).
and_return
(
%w[test
deploy]
)
end
it
'reports error about missing stage'
do
...
...
@@ -65,7 +69,7 @@ describe Gitlab::Ci::Config::Node::Stage do
describe
'#known?'
do
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
(
[
:test
,
:
deploy
])
allow
(
global
).
to
receive
(
:stages
).
and_return
(
%w[test
deploy]
)
end
context
'when stage is not known'
do
...
...
@@ -77,7 +81,7 @@ describe Gitlab::Ci::Config::Node::Stage do
end
context
'when stage is known'
do
let
(
:config
)
{
:test
}
let
(
:config
)
{
'test'
}
it
'returns false'
do
expect
(
stage
.
known?
).
to
be
true
...
...
@@ -87,7 +91,7 @@ describe Gitlab::Ci::Config::Node::Stage do
describe
'.default'
do
it
'returns default stage'
do
expect
(
described_class
.
default
).
to
eq
:test
expect
(
described_class
.
default
).
to
eq
'test'
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