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
8b13b8c4
Commit
8b13b8c4
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
b16b754f
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 @
8b13b8c4
...
@@ -3,6 +3,8 @@ module Gitlab
...
@@ -3,6 +3,8 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Seed
module
Seed
class
Build
<
Seed
::
Base
class
Build
<
Seed
::
Base
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:pipeline
,
:attributes
attr_reader
:pipeline
,
:attributes
delegate
:dig
,
to: :attributes
delegate
:dig
,
to: :attributes
...
@@ -10,6 +12,9 @@ module Gitlab
...
@@ -10,6 +12,9 @@ module Gitlab
def
initialize
(
pipeline
,
attributes
)
def
initialize
(
pipeline
,
attributes
)
@pipeline
=
pipeline
@pipeline
=
pipeline
@attributes
=
attributes
@attributes
=
attributes
@only
=
attributes
.
delete
(
:only
)
@except
=
attributes
.
delete
(
:except
)
end
end
# TODO find a different solution
# TODO find a different solution
...
@@ -29,6 +34,16 @@ module Gitlab
...
@@ -29,6 +34,16 @@ module Gitlab
)
)
end
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
def
to_resource
::
Ci
::
Build
.
new
(
attributes
)
::
Ci
::
Build
.
new
(
attributes
)
end
end
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
8b13b8c4
...
@@ -8,11 +8,11 @@ module Gitlab
...
@@ -8,11 +8,11 @@ module Gitlab
delegate
:size
,
to: :seeds
delegate
:size
,
to: :seeds
delegate
:dig
,
to: :seeds
delegate
:dig
,
to: :seeds
def
initialize
(
pipeline
,
name
,
build
s
)
def
initialize
(
pipeline
,
attribute
s
)
@pipeline
=
pipeline
@pipeline
=
pipeline
@
name
=
name
@
attributes
=
attributes
@seeds
=
builds
.
map
do
|
attributes
|
@seeds
=
attributes
.
fetch
(
:builds
)
.
map
do
|
attributes
|
Seed
::
Build
.
new
(
@pipeline
,
attributes
)
Seed
::
Build
.
new
(
@pipeline
,
attributes
)
end
end
end
end
...
@@ -22,17 +22,23 @@ module Gitlab
...
@@ -22,17 +22,23 @@ module Gitlab
end
end
def
attributes
def
attributes
{
name:
@
name
,
{
name:
@
attributes
.
fetch
(
:name
)
,
pipeline:
@pipeline
,
pipeline:
@pipeline
,
project:
@pipeline
.
project
}
project:
@pipeline
.
project
}
end
end
# TODO specs
#
def
included?
@seeds
.
any?
(
&
:included?
)
end
def
to_resource
def
to_resource
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@stage
||=
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@seeds
.
each
do
|
seed
|
@seeds
.
each
do
|
seed
|
seed
.
to_resource
.
tap
do
|
build
|
next
unless
seed
.
included?
stage
.
builds
<<
build
end
stage
.
builds
<<
seed
.
to_resource
end
end
end
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
8b13b8c4
...
@@ -53,6 +53,22 @@ module Gitlab
...
@@ -53,6 +53,22 @@ module Gitlab
}.
compact
}
}.
compact
}
end
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
)
def
pipeline_stage_builds
(
stage
,
pipeline
)
selected_jobs
=
@jobs
.
select
do
|
_
,
job
|
selected_jobs
=
@jobs
.
select
do
|
_
,
job
|
next
unless
job
[
:stage
]
==
stage
next
unless
job
[
:stage
]
==
stage
...
@@ -69,13 +85,24 @@ module Gitlab
...
@@ -69,13 +85,24 @@ module Gitlab
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
end
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
)
def
stage_seeds
(
pipeline
)
seeds
=
@stages
.
uniq
.
map
do
|
stage
|
seeds
=
@stages
.
uniq
.
map
do
|
stage
|
builds
=
pipeline_stage_builds
(
stage
,
pipeline
)
builds
=
pipeline_stage_builds
(
stage
,
pipeline
)
if
builds
.
any?
if
builds
.
any?
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
.
new
(
pipeline
,
stage
,
builds
)
.
new
(
pipeline
,
stage
_seed_attributes
(
stage
)
)
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
8b13b8c4
...
@@ -3,12 +3,14 @@ require 'spec_helper'
...
@@ -3,12 +3,14 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
do
describe
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:builds
)
do
let
(
:attributes
)
do
[{
name:
'rspec'
},
{
name:
'spinach'
}]
{
name:
'test'
,
index:
0
,
builds:
[{
name:
'rspec'
},
{
name:
'spinach'
}]
}
end
end
subject
do
subject
do
described_class
.
new
(
pipeline
,
'test'
,
build
s
)
described_class
.
new
(
pipeline
,
attribute
s
)
end
end
describe
'#size'
do
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