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
iv
gitlab-ce
Commits
56e88b8c
Commit
56e88b8c
authored
Jun 24, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new ci config entry that handles cache config
parent
ce4478ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
12 deletions
+151
-12
lib/gitlab/ci/config/node/cache.rb
lib/gitlab/ci/config/node/cache.rb
+39
-0
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+16
-12
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+3
-0
spec/lib/gitlab/ci/config/node/cache_spec.rb
spec/lib/gitlab/ci/config/node/cache_spec.rb
+60
-0
spec/lib/gitlab/ci/config/node/configurable_spec.rb
spec/lib/gitlab/ci/config/node/configurable_spec.rb
+33
-0
No files found.
lib/gitlab/ci/config/node/cache.rb
0 → 100644
View file @
56e88b8c
module
Gitlab
module
Ci
class
Config
module
Node
##
# Entry that represents a cache configuration
#
class
Cache
<
Entry
include
Configurable
validations
do
validate
:allowed_keys
def
unknown_keys
return
[]
unless
@node
.
config
.
is_a?
(
Hash
)
@node
.
config
.
keys
-
@node
.
class
.
nodes
.
keys
end
def
allowed_keys
if
unknown_keys
.
any?
errors
.
add
(
:config
,
"contains unknown keys
#{
unknown_keys
}
"
)
end
end
end
node
:key
,
Node
::
Key
,
description:
'Cache key used to define a cache affinity.'
node
:untracked
,
Boolean
,
description:
'Cache all untracked files.'
node
:paths
,
Paths
,
description:
'Specify which paths should be cached across builds.'
end
end
end
end
end
lib/gitlab/ci/config/node/configurable.rb
View file @
56e88b8c
...
...
@@ -32,28 +32,32 @@ module Gitlab
class_methods
do
def
nodes
Hash
[
@nodes
.
map
{
|
key
,
factory
|
[
key
,
factory
.
dup
]
}]
Hash
[
(
@nodes
||
{})
.
map
{
|
key
,
factory
|
[
key
,
factory
.
dup
]
}]
end
private
def
node
(
symbol
,
entry_class
,
metadata
)
define_method
(
"
#{
symbol
}
_defined?"
)
do
@nodes
[
symbol
].
try
(
:defined?
)
end
define_method
(
"
#{
symbol
}
_value"
)
do
raise
Entry
::
InvalidError
unless
valid?
@nodes
[
symbol
].
try
(
:value
)
end
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
factory
=
Node
::
Factory
.
new
(
entry_class
)
.
with
(
description:
metadata
[
:description
])
(
@nodes
||=
{}).
merge!
(
symbol
.
to_sym
=>
factory
)
end
def
helpers
(
*
nodes
)
nodes
.
each
do
|
symbol
|
define_method
(
"
#{
symbol
}
_defined?"
)
do
@nodes
[
symbol
].
try
(
:defined?
)
end
define_method
(
"
#{
symbol
}
_value"
)
do
raise
Entry
::
InvalidError
unless
valid?
@nodes
[
symbol
].
try
(
:value
)
end
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
56e88b8c
...
...
@@ -30,6 +30,9 @@ module Gitlab
node
:types
,
Stages
,
description:
'Stages for this pipeline (deprecated key).'
helpers
:before_script
,
:image
,
:services
,
:after_script
,
:variables
,
:stages
,
:types
def
stages
stages_defined?
?
stages_value
:
types_value
end
...
...
spec/lib/gitlab/ci/config/node/cache_spec.rb
0 → 100644
View file @
56e88b8c
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Cache
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
before
{
entry
.
process!
}
context
'when entry config value is correct'
do
let
(
:config
)
do
{
key:
'some key'
,
untracked:
true
,
paths:
[
'some/path/'
]
}
end
describe
'#value'
do
it
'returns hash value'
do
expect
(
entry
.
value
).
to
eq
config
end
end
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
context
'when entry value is not correct'
do
describe
'#errors'
do
context
'when is not a hash'
do
let
(
:config
)
{
'ls'
}
it
'reports errors with config value'
do
expect
(
entry
.
errors
)
.
to
include
'Cache config should be a hash'
end
end
context
'when descendants are invalid'
do
let
(
:config
)
{
{
key:
1
}
}
it
'reports error with descendants'
do
expect
(
entry
.
errors
)
.
to
include
'Key config should be a string or symbol'
end
end
context
'when there is an unknown key present'
do
let
(
:config
)
{
{
invalid:
true
}
}
it
'reports error with descendants'
do
expect
(
entry
.
errors
)
.
to
include
'Cache config contains unknown keys [:invalid]'
end
end
end
end
end
end
spec/lib/gitlab/ci/config/node/configurable_spec.rb
View file @
56e88b8c
...
...
@@ -7,6 +7,39 @@ describe Gitlab::Ci::Config::Node::Configurable do
node
.
include
(
described_class
)
end
describe
'validations'
do
let
(
:validator
)
{
node
.
validator
.
new
(
instance
)
}
before
do
node
.
class_eval
do
attr_reader
:config
def
initialize
(
config
)
@config
=
config
end
end
validator
.
validate
end
context
'when node validator is invalid'
do
let
(
:instance
)
{
node
.
new
(
'ls'
)
}
it
'returns invalid validator'
do
expect
(
validator
).
to
be_invalid
end
end
context
'when node instance is valid'
do
let
(
:instance
)
{
node
.
new
(
key:
'value'
)
}
it
'returns valid validator'
do
expect
(
validator
).
to
be_valid
end
end
end
describe
'configured nodes'
do
before
do
node
.
class_eval
do
...
...
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