Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
29b96d92
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
29b96d92
编写于
6月 23, 2016
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move CI stages configuration to new CI config
上级
2240807c
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
147 addition
and
29 deletion
+147
-29
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+8
-17
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+1
-1
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+9
-3
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+4
-0
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+1
-1
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+10
-0
lib/gitlab/ci/config/node/stages.rb
lib/gitlab/ci/config/node/stages.rb
+22
-0
lib/gitlab/ci/config/node/undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+4
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+4
-4
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+32
-3
spec/lib/gitlab/ci/config/node/stages_spec.rb
spec/lib/gitlab/ci/config/node/stages_spec.rb
+46
-0
spec/lib/gitlab/ci/config/node/undefined_spec.rb
spec/lib/gitlab/ci/config/node/undefined_spec.rb
+6
-0
未找到文件。
lib/ci/gitlab_ci_yaml_processor.rb
浏览文件 @
29b96d92
...
...
@@ -4,7 +4,6 @@ module Ci
include
Gitlab
::
Ci
::
Config
::
Node
::
LegacyValidationHelpers
DEFAULT_STAGES
=
%w(build test deploy)
DEFAULT_STAGE
=
'test'
ALLOWED_YAML_KEYS
=
[
:before_script
,
:after_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_JOB_KEYS
=
[
:tags
,
:script
,
:only
,
:except
,
:type
,
:image
,
:services
,
...
...
@@ -46,7 +45,7 @@ module Ci
end
def
stages
@stages
||
DEFAULT_STAGES
@stages
end
def
global_variables
...
...
@@ -68,8 +67,8 @@ module Ci
@after_script
=
@ci_config
.
after_script
@services
=
@ci_config
.
services
@variables
=
@ci_config
.
variables
@stages
=
@ci_config
.
stages
@stages
=
@config
[
:stages
]
||
@config
[
:types
]
@cache
=
@config
[
:cache
]
@jobs
=
{}
...
...
@@ -90,7 +89,7 @@ module Ci
def
build_job
(
name
,
job
)
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage_idx:
@
stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
commands:
[
job
[
:before_script
]
||
@before_script
,
job
[
:script
]].
flatten
.
compact
.
join
(
"
\n
"
),
tag_list:
job
[
:tags
]
||
[],
...
...
@@ -112,7 +111,7 @@ module Ci
end
def
validate!
validate_global
!
validate_global
_cache!
if
@cache
@jobs
.
each
do
|
name
,
job
|
validate_job!
(
name
,
job
)
...
...
@@ -121,14 +120,6 @@ module Ci
true
end
def
validate_global!
unless
@stages
.
nil?
||
validate_array_of_strings
(
@stages
)
raise
ValidationError
,
"stages should be an array of strings"
end
validate_global_cache!
if
@cache
end
def
validate_global_cache!
@cache
.
keys
.
each
do
|
key
|
unless
ALLOWED_CACHE_KEYS
.
include?
key
...
...
@@ -225,8 +216,8 @@ module Ci
end
def
validate_job_stage!
(
name
,
job
)
unless
job
[
:stage
].
is_a?
(
String
)
&&
job
[
:stage
].
in?
(
stages
)
raise
ValidationError
,
"
#{
name
}
job: stage parameter should be
#{
stages
.
join
(
", "
)
}
"
unless
job
[
:stage
].
is_a?
(
String
)
&&
job
[
:stage
].
in?
(
@
stages
)
raise
ValidationError
,
"
#{
name
}
job: stage parameter should be
#{
@
stages
.
join
(
", "
)
}
"
end
end
...
...
@@ -290,12 +281,12 @@ module Ci
raise
ValidationError
,
"
#{
name
}
job: dependencies parameter should be an array of strings"
end
stage_index
=
stages
.
index
(
job
[
:stage
])
stage_index
=
@
stages
.
index
(
job
[
:stage
])
job
[
:dependencies
].
each
do
|
dependency
|
raise
ValidationError
,
"
#{
name
}
job: undefined dependency:
#{
dependency
}
"
unless
@jobs
[
dependency
.
to_sym
]
unless
stages
.
index
(
@jobs
[
dependency
.
to_sym
][
:stage
])
<
stage_index
unless
@
stages
.
index
(
@jobs
[
dependency
.
to_sym
][
:stage
])
<
stage_index
raise
ValidationError
,
"
#{
name
}
job: dependency
#{
dependency
}
is not defined in prior stages"
end
end
...
...
lib/gitlab/ci/config.rb
浏览文件 @
29b96d92
...
...
@@ -8,7 +8,7 @@ module Gitlab
# Temporary delegations that should be removed after refactoring
#
delegate
:before_script
,
:image
,
:services
,
:after_script
,
:variables
,
to: :@global
:stages
,
to: :@global
def
initialize
(
config
)
@config
=
Loader
.
new
(
config
).
load!
...
...
lib/gitlab/ci/config/node/configurable.rb
浏览文件 @
29b96d92
...
...
@@ -38,14 +38,20 @@ module Gitlab
private
def
node
(
symbol
,
entry_class
,
metadata
)
factory
=
Node
::
Factory
.
new
(
entry_class
)
.
with
(
description:
metadata
[
:description
])
define_method
(
"
#{
symbol
}
_defined?"
)
do
@nodes
[
symbol
].
try
(
:defined?
)
end
define_method
(
symbol
)
do
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
=>
factory
)
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
浏览文件 @
29b96d92
...
...
@@ -52,6 +52,10 @@ module Gitlab
@config
end
def
defined?
true
end
def
self
.
default
end
...
...
lib/gitlab/ci/config/node/factory.rb
浏览文件 @
29b96d92
...
...
@@ -22,7 +22,7 @@ module Gitlab
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
##
# We assume unspecified entry is undefined.
# We assume
that
unspecified entry is undefined.
# See issue #18775.
#
if
@attributes
[
:value
].
nil?
...
...
lib/gitlab/ci/config/node/global.rb
浏览文件 @
29b96d92
...
...
@@ -23,6 +23,16 @@ module Gitlab
node
:variables
,
Variables
,
description:
'Environment variables that will be used.'
node
:stages
,
Stages
,
description:
'Configuration of stages for this pipeline.'
node
:types
,
Stages
,
description:
'Stages for this pipeline (deprecated key).'
def
stages
stages_defined?
?
stages_value
:
types_value
end
end
end
end
...
...
lib/gitlab/ci/config/node/stages.rb
0 → 100644
浏览文件 @
29b96d92
module
Gitlab
module
Ci
class
Config
module
Node
##
# Entry that represents a configuration for pipeline stages.
#
class
Stages
<
Entry
include
Validatable
validations
do
validates
:config
,
array_of_strings:
true
end
def
self
.
default
%w(build test deploy)
end
end
end
end
end
end
lib/gitlab/ci/config/node/undefined.rb
浏览文件 @
29b96d92
...
...
@@ -19,6 +19,10 @@ module Gitlab
def
value
@config
.
default
end
def
defined?
false
end
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
浏览文件 @
29b96d92
...
...
@@ -1081,17 +1081,17 @@ EOT
end
it
"returns errors if stages is not an array"
do
config
=
YAML
.
dump
({
typ
es:
"test"
,
rspec:
{
script:
"test"
}
})
config
=
YAML
.
dump
({
stag
es:
"test"
,
rspec:
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
stages
should be an array of strings"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
Stages config
should be an array of strings"
)
end
it
"returns errors if stages is not an array of strings"
do
config
=
YAML
.
dump
({
typ
es:
[
true
,
"test"
],
rspec:
{
script:
"test"
}
})
config
=
YAML
.
dump
({
stag
es:
[
true
,
"test"
],
rspec:
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
stages
should be an array of strings"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
Stages config
should be an array of strings"
)
end
it
"returns errors if variables is not a map"
do
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
浏览文件 @
29b96d92
...
...
@@ -26,7 +26,8 @@ describe Gitlab::Ci::Config::Node::Global do
image:
'ruby:2.2'
,
services:
[
'postgres:9.1'
,
'mysql:5.5'
],
variables:
{
VAR
:
'value'
},
after_script:
[
'make clean'
]
}
after_script:
[
'make clean'
],
stages:
[
'build'
,
'pages'
]
}
end
describe
'#process!'
do
...
...
@@ -37,7 +38,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
it
'creates node object for each entry'
do
expect
(
global
.
nodes
.
count
).
to
eq
5
expect
(
global
.
nodes
.
count
).
to
eq
7
end
it
'creates node object using valid class'
do
...
...
@@ -101,6 +102,22 @@ describe Gitlab::Ci::Config::Node::Global do
expect
(
global
.
variables
).
to
eq
(
VAR
:
'value'
)
end
end
describe
'#stages'
do
context
'when stages key defined'
do
it
'returns array of stages'
do
expect
(
global
.
stages
).
to
eq
%w[build pages]
end
end
context
'when deprecated types key defined'
do
let
(
:hash
)
{
{
types:
[
'test'
,
'deploy'
]
}
}
it
'returns array of types as stages'
do
expect
(
global
.
stages
).
to
eq
%w[test deploy]
end
end
end
end
end
...
...
@@ -110,7 +127,7 @@ describe Gitlab::Ci::Config::Node::Global do
describe
'#nodes'
do
it
'instantizes all nodes'
do
expect
(
global
.
nodes
.
count
).
to
eq
5
expect
(
global
.
nodes
.
count
).
to
eq
7
end
it
'contains undefined nodes'
do
...
...
@@ -124,6 +141,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect
(
global
.
variables
).
to
eq
({})
end
end
describe
'#stages'
do
it
'returns an array of default stages'
do
expect
(
global
.
stages
).
to
eq
%w[build test deploy]
end
end
end
##
...
...
@@ -188,4 +211,10 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
end
describe
'#defined?'
do
it
'is concrete entry that is defined'
do
expect
(
global
.
defined?
).
to
be
true
end
end
end
spec/lib/gitlab/ci/config/node/stages_spec.rb
0 → 100644
浏览文件 @
29b96d92
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Stages
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
context
'when entry config value is correct'
do
let
(
:config
)
{
[
:stage1
,
:stage2
]
}
describe
'#value'
do
it
'returns array of stages'
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
let
(
:config
)
{
{
test:
true
}
}
describe
'#errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
.
to
include
'Stages config should be an array of strings'
end
end
describe
'#valid?'
do
it
'is not valid'
do
expect
(
entry
).
not_to
be_valid
end
end
end
end
describe
'.default'
do
it
'returns default stages'
do
expect
(
described_class
.
default
).
to
eq
%w[build test deploy]
end
end
end
spec/lib/gitlab/ci/config/node/undefined_spec.rb
浏览文件 @
29b96d92
...
...
@@ -31,4 +31,10 @@ describe Gitlab::Ci::Config::Node::Undefined do
expect
(
undefined
.
value
).
to
eq
'some value'
end
end
describe
'#undefined?'
do
it
'is not a concrete entry that is defined'
do
expect
(
undefined
.
defined?
).
to
be
false
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录