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
Léo-Paul Géneau
gitlab-ce
Commits
db3d0319
Commit
db3d0319
authored
Mar 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Evaluate only/except policies outside of YAML processor
parent
9b5a912f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
12 deletions
+62
-12
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+15
-0
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+14
-8
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+28
-1
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+5
-3
No files found.
lib/gitlab/ci/pipeline/seed/build.rb
View file @
db3d0319
...
...
@@ -3,6 +3,8 @@ module Gitlab
module
Pipeline
module
Seed
class
Build
<
Seed
::
Base
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:pipeline
,
:attributes
delegate
:dig
,
to: :attributes
...
...
@@ -10,6 +12,9 @@ module Gitlab
def
initialize
(
pipeline
,
attributes
)
@pipeline
=
pipeline
@attributes
=
attributes
@only
=
attributes
.
delete
(
:only
)
@except
=
attributes
.
delete
(
:except
)
end
# TODO find a different solution
...
...
@@ -29,6 +34,16 @@ module Gitlab
)
end
def
included?
strong_memoize
(
:inclusion
)
do
only_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
@only
)
except_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
@except
)
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
end
end
def
to_resource
::
Ci
::
Build
.
new
(
attributes
)
end
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
db3d0319
...
...
@@ -8,11 +8,11 @@ module Gitlab
delegate
:size
,
to: :seeds
delegate
:dig
,
to: :seeds
def
initialize
(
pipeline
,
name
,
build
s
)
def
initialize
(
pipeline
,
attribute
s
)
@pipeline
=
pipeline
@
name
=
name
@
attributes
=
attributes
@seeds
=
builds
.
map
do
|
attributes
|
@seeds
=
attributes
.
fetch
(
:builds
)
.
map
do
|
attributes
|
Seed
::
Build
.
new
(
@pipeline
,
attributes
)
end
end
...
...
@@ -22,17 +22,23 @@ module Gitlab
end
def
attributes
{
name:
@
name
,
{
name:
@
attributes
.
fetch
(
:name
)
,
pipeline:
@pipeline
,
project:
@pipeline
.
project
}
end
# TODO specs
#
def
included?
@seeds
.
any?
(
&
:included?
)
end
def
to_resource
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@stage
||=
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@seeds
.
each
do
|
seed
|
seed
.
to_resource
.
tap
do
|
build
|
stage
.
builds
<<
build
end
next
unless
seed
.
included?
stage
.
builds
<<
seed
.
to_resource
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
db3d0319
...
...
@@ -53,6 +53,22 @@ module Gitlab
}.
compact
}
end
# REFACTORING, this needs improvement
#
def
build_seed_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
#
def
pipeline_stage_builds
(
stage
,
pipeline
)
selected_jobs
=
@jobs
.
select
do
|
_
,
job
|
next
unless
job
[
:stage
]
==
stage
...
...
@@ -69,13 +85,24 @@ module Gitlab
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
end
def
stage_seed_attributes
(
stage
)
{
name:
stage
,
index:
@stages
.
index
(
stage
),
builds:
build_seed_attributes
(
stage
)
}
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
#
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
,
builds
)
.
new
(
pipeline
,
stage
_seed_attributes
(
stage
)
)
end
end
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
db3d0319
...
...
@@ -3,12 +3,14 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:builds
)
do
[{
name:
'rspec'
},
{
name:
'spinach'
}]
let
(
:attributes
)
do
{
name:
'test'
,
index:
0
,
builds:
[{
name:
'rspec'
},
{
name:
'spinach'
}]
}
end
subject
do
described_class
.
new
(
pipeline
,
'test'
,
build
s
)
described_class
.
new
(
pipeline
,
attribute
s
)
end
describe
'#size'
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