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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2725433a
Commit
2725433a
authored
Aug 17, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for `extends` key in CI/CD configuration
Conflicts: lib/gitlab/ci/config.rb
parent
10cd2ec2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
10 deletions
+51
-10
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+9
-3
lib/gitlab/ci/config/entry/job.rb
lib/gitlab/ci/config/entry/job.rb
+7
-4
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+1
-1
spec/lib/gitlab/ci/config_spec.rb
spec/lib/gitlab/ci/config_spec.rb
+34
-2
No files found.
lib/gitlab/ci/config.rb
View file @
2725433a
...
@@ -6,11 +6,17 @@ module Gitlab
...
@@ -6,11 +6,17 @@ module Gitlab
class
Config
class
Config
prepend
EE
::
Gitlab
::
Ci
::
Config
prepend
EE
::
Gitlab
::
Ci
::
Config
# EE would override this and utilize opts argument
ConfigError
=
Class
.
new
(
StandardError
)
def
initialize
(
config
,
opts
=
{})
def
initialize
(
config
,
opts
=
{})
@config
=
build_config
(
config
,
opts
)
@config
=
Extendable
::
Collection
.
new
(
build_config
(
config
,
opts
))
.
to_hash
@global
=
Entry
::
Global
.
new
(
@config
)
@global
=
Entry
::
Global
.
new
(
@config
)
@global
.
compose!
@global
.
compose!
rescue
Loader
::
FormatError
,
Extendable
::
Collection
::
ExtensionError
=>
e
raise
Config
::
ConfigError
,
e
.
message
end
end
def
valid?
def
valid?
...
@@ -62,7 +68,7 @@ module Gitlab
...
@@ -62,7 +68,7 @@ module Gitlab
private
private
# '
O
pts' argument is used in EE see /ee/lib/ee/gitlab/ci/config.rb
# '
o
pts' argument is used in EE see /ee/lib/ee/gitlab/ci/config.rb
def
build_config
(
config
,
opts
=
{})
def
build_config
(
config
,
opts
=
{})
Loader
.
new
(
config
).
load!
Loader
.
new
(
config
).
load!
end
end
...
...
lib/gitlab/ci/config/entry/job.rb
View file @
2725433a
...
@@ -9,9 +9,10 @@ module Gitlab
...
@@ -9,9 +9,10 @@ module Gitlab
include
Configurable
include
Configurable
include
Attributable
include
Attributable
ALLOWED_KEYS
=
%i[tags script only except type image services allow_failure
ALLOWED_KEYS
=
%i[tags script only except type image services
type stage when artifacts cache dependencies before_script
allow_failure type stage when artifacts cache
after_script variables environment coverage retry]
.
freeze
dependencies before_script after_script variables
environment coverage retry extends]
.
freeze
validations
do
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
validates
:config
,
allowed_keys:
ALLOWED_KEYS
...
@@ -32,6 +33,7 @@ module Gitlab
...
@@ -32,6 +33,7 @@ module Gitlab
'always or manual'
}
'always or manual'
}
validates
:dependencies
,
array_of_strings:
true
validates
:dependencies
,
array_of_strings:
true
validates
:extends
,
type:
String
end
end
end
end
...
@@ -81,7 +83,8 @@ module Gitlab
...
@@ -81,7 +83,8 @@ module Gitlab
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:artifacts
,
:commands
,
:environment
,
:coverage
,
:retry
:artifacts
,
:commands
,
:environment
,
:coverage
,
:retry
attributes
:script
,
:tags
,
:allow_failure
,
:when
,
:dependencies
,
:retry
attributes
:script
,
:tags
,
:allow_failure
,
:when
,
:dependencies
,
:retry
,
:extends
def
compose!
(
deps
=
nil
)
def
compose!
(
deps
=
nil
)
super
do
super
do
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
2725433a
...
@@ -16,7 +16,7 @@ module Gitlab
...
@@ -16,7 +16,7 @@ module Gitlab
end
end
initial_parsing
initial_parsing
rescue
Gitlab
::
Ci
::
Config
::
Loader
::
Format
Error
=>
e
rescue
Gitlab
::
Ci
::
Config
::
Config
Error
=>
e
raise
ValidationError
,
e
.
message
raise
ValidationError
,
e
.
message
end
end
...
...
spec/lib/gitlab/ci/config_spec.rb
View file @
2725433a
require
'spec_helper'
require
'fast_spec_helper'
require_dependency
'active_model'
describe
Gitlab
::
Ci
::
Config
do
describe
Gitlab
::
Ci
::
Config
do
let
(
:config
)
do
let
(
:config
)
do
...
@@ -42,6 +44,36 @@ describe Gitlab::Ci::Config do
...
@@ -42,6 +44,36 @@ describe Gitlab::Ci::Config do
end
end
end
end
context
'when using extendable hash'
do
let
(
:yml
)
do
<<-
EOS
image: ruby:2.2
rspec:
script: rspec
test:
extends: rspec
image: ruby:alpine
EOS
end
it
'correctly extends the hash'
do
hash
=
{
image:
'ruby:2.2'
,
rspec:
{
script:
'rspec'
},
test:
{
extends:
'rspec'
,
image:
'ruby:alpine'
,
script:
'rspec'
}
}
expect
(
config
).
to
be_valid
expect
(
config
.
to_hash
).
to
eq
hash
end
end
context
'when config is invalid'
do
context
'when config is invalid'
do
context
'when yml is incorrect'
do
context
'when yml is incorrect'
do
let
(
:yml
)
{
'// invalid'
}
let
(
:yml
)
{
'// invalid'
}
...
@@ -49,7 +81,7 @@ describe Gitlab::Ci::Config do
...
@@ -49,7 +81,7 @@ describe Gitlab::Ci::Config do
describe
'.new'
do
describe
'.new'
do
it
'raises error'
do
it
'raises error'
do
expect
{
config
}.
to
raise_error
(
expect
{
config
}.
to
raise_error
(
::
Gitlab
::
Ci
::
Config
::
Loader
::
Format
Error
,
described_class
::
Config
Error
,
/Invalid configuration format/
/Invalid configuration format/
)
)
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