Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
000f9d01
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,发现更多精彩内容 >>
提交
000f9d01
编写于
3月 22, 2018
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Decouple YAML processor from pipeline objects
上级
0e51842d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
57 deletion
+43
-57
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+7
-1
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+14
-34
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+22
-22
未找到文件。
app/models/ci/pipeline.rb
浏览文件 @
000f9d01
...
...
@@ -362,7 +362,13 @@ module Ci
def
stage_seeds
return
[]
unless
config_processor
@stage_seeds
||=
config_processor
.
stage_seeds
(
self
)
strong_memoize
(
:stage_seeds
)
do
seeds
=
config_processor
.
stages
.
map
do
|
attributes
|
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
.
new
(
self
,
attributes
)
end
seeds
.
select
(
&
:included?
)
end
end
def
has_kubernetes_active?
...
...
lib/gitlab/ci/yaml_processor.rb
浏览文件 @
000f9d01
...
...
@@ -53,60 +53,40 @@ module Gitlab
}.
compact
}
end
# REFACTORING, this needs improvement
# REFACTORING, this needs improvement
, and specs
#
def
build_seed
_attributes
(
stage
)
def
stage
_attributes
(
stage
)
selected
=
@jobs
.
values
.
select
do
|
job
|
job
[
:stage
]
==
stage
end
selected
.
map
do
|
job
|
build_attributes
(
job
[
:name
])
.
merge
(
only:
job
.
fetch
(
:only
,
{}))
.
merge
(
except:
job
.
fetch
(
:except
,
{}))
end
end
# REFACTORING,
slated for removal
# REFACTORING,
needs specs
#
def
pipeline_stage_builds
(
stage
,
pipeline
)
selected_jobs
=
@jobs
.
select
do
|
_
,
job
|
next
unless
job
[
:stage
]
==
stage
only_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:only
,
{}))
except_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:except
,
{}))
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
end
def
seed_attributes
(
stage
)
seeds
=
stage_attributes
(
stage
).
map
do
|
attributes
|
job
=
@jobs
.
fetch
(
attributes
[
:name
].
to_sym
)
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
attributes
.
merge
(
only:
job
.
fetch
(
:only
,
{}))
.
merge
(
except:
job
.
fetch
(
:except
,
{}))
end
def
stage_seed_attributes
(
stage
)
{
name:
stage
,
index:
@stages
.
index
(
stage
),
builds:
build_seed_attributes
(
stage
)
}
builds:
seeds
}
end
# REFACTORING, slated for removal
# * WARNING this method is currently evaluating only/except policies
# in two places - Seed::Build, and in pipeline_stage_builds
# * WARNING it needs to be refactored to use SSOT
# REFACTORING, needs specs
#
def
stage_seeds
(
pipeline
)
seeds
=
@stages
.
uniq
.
map
do
|
stage
|
builds
=
pipeline_stage_builds
(
stage
,
pipeline
)
if
builds
.
any?
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
.
new
(
pipeline
,
stage_seed_attributes
(
stage
))
end
def
stages
@stages
.
uniq
.
map
do
|
stage
|
seed_attributes
(
stage
)
end
seeds
.
compact
end
def
self
.
validation_message
(
content
)
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
浏览文件 @
000f9d01
...
...
@@ -203,7 +203,7 @@ module Gitlab
let
(
:config_data
)
{
YAML
.
dump
(
config
)
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config_data
)
}
subject
{
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
}
subject
{
config_processor
.
stage_attributes
(
'test'
).
first
}
describe
"before_script"
do
context
"in global context"
do
...
...
@@ -286,8 +286,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
).
to
eq
({
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage_idx:
1
,
name:
"rspec"
,
...
...
@@ -321,8 +321,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
).
to
eq
({
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage_idx:
1
,
name:
"rspec"
,
...
...
@@ -354,8 +354,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
).
to
eq
({
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage_idx:
1
,
name:
"rspec"
,
...
...
@@ -383,8 +383,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
).
to
eq
({
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage_idx:
1
,
name:
"rspec"
,
...
...
@@ -529,8 +529,8 @@ module Gitlab
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_attributes
(
"test"
)
builds
=
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
))
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:when
]).
to
eq
(
when_state
)
end
...
...
@@ -561,8 +561,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
,
...
...
@@ -580,8 +580,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
,
...
...
@@ -600,8 +600,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"test/"
],
untracked:
false
,
key:
'local'
,
...
...
@@ -629,8 +629,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
).
first
).
to
eq
({
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage_idx:
1
,
name:
"rspec"
,
...
...
@@ -666,8 +666,8 @@ module Gitlab
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_attributes
(
"test"
)
builds
=
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
))
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:options
][
:artifacts
][
:when
]).
to
eq
(
when_state
)
end
...
...
@@ -682,7 +682,7 @@ module Gitlab
end
let
(
:processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
YAML
.
dump
(
config
))
}
let
(
:builds
)
{
processor
.
pipeline_stage_builds
(
'deploy'
,
pipeline
(
ref:
'master'
)
)
}
let
(
:builds
)
{
processor
.
stage_attributes
(
'deploy'
)
}
context
'when a production environment is specified'
do
let
(
:environment
)
{
'production'
}
...
...
@@ -839,7 +839,7 @@ module Gitlab
describe
"Hidden jobs"
do
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
subject
{
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"master"
)
)
}
subject
{
config_processor
.
stage_attributes
(
"test"
)
}
shared_examples
'hidden_job_handling'
do
it
"doesn't create jobs that start with dot"
do
...
...
@@ -887,7 +887,7 @@ module Gitlab
describe
"YAML Alias/Anchor"
do
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
subject
{
config_processor
.
pipeline_stage_builds
(
"build"
,
pipeline
(
ref:
"master"
)
)
}
subject
{
config_processor
.
stage_attributes
(
"build"
)
}
shared_examples
'job_templates_handling'
do
it
"is correctly supported for jobs"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录