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
5fd8933d
Commit
5fd8933d
authored
Nov 05, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use instance based approach for Normalizer
parent
a8da5238
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
52 deletions
+48
-52
lib/gitlab/ci/config/normalizer.rb
lib/gitlab/ci/config/normalizer.rb
+46
-50
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+1
-1
spec/lib/gitlab/ci/config/normalizer_spec.rb
spec/lib/gitlab/ci/config/normalizer_spec.rb
+1
-1
No files found.
lib/gitlab/ci/config/normalizer.rb
View file @
5fd8933d
...
@@ -4,58 +4,54 @@ module Gitlab
...
@@ -4,58 +4,54 @@ module Gitlab
module
Ci
module
Ci
class
Config
class
Config
class
Normalizer
class
Normalizer
class
<<
self
def
initialize
(
jobs_config
)
def
normalize_jobs
(
jobs_config
)
@jobs_config
=
jobs_config
parallelized_config
,
parallelized_jobs
=
parallelize_jobs
(
jobs_config
)
end
parallelize_dependencies
(
parallelized_config
,
parallelized_jobs
)
end
def
normalize_jobs
parallelized_jobs
=
parallelize_jobs
private
parallelize_dependencies
(
parallelized_jobs
)
end
def
parallelize_jobs
(
jobs_config
)
parallelized_jobs
=
{}
private
parallelized_config
=
jobs_config
.
map
do
|
name
,
config
|
def
parallelize_jobs
if
config
[
:parallel
]
parallelized_jobs
=
{}
total
=
config
[
:parallel
]
names
=
parallelize_job_names
(
name
,
total
)
@jobs_config
=
@jobs_config
.
map
do
|
name
,
config
|
parallelized_jobs
[
name
]
=
names
.
map
(
&
:first
)
if
config
[
:parallel
]
Hash
[
names
.
collect
{
|
job_name
,
index
|
[
job_name
.
to_sym
,
config
.
merge
(
name:
job_name
,
instance:
index
)]
}]
total
=
config
[
:parallel
]
else
names
=
self
.
class
.
parallelize_job_names
(
name
,
total
)
{
name
=>
config
}
parallelized_jobs
[
name
]
=
names
.
map
(
&
:first
)
end
Hash
[
names
.
collect
{
|
job_name
,
index
|
[
job_name
.
to_sym
,
config
.
merge
(
name:
job_name
,
instance:
index
)]
}]
end
.
reduce
(
:merge
)
else
{
name
=>
config
}
[
parallelized_config
,
parallelized_jobs
]
end
def
parallelize_dependencies
(
jobs_config
,
parallelized_jobs
)
jobs_config
.
map
do
|
name
,
config
|
if
config
[
:dependencies
]
deps
=
config
[
:dependencies
].
map
do
|
dep
|
if
parallelized_jobs
.
keys
.
include?
(
dep
.
to_sym
)
parallelized_jobs
[
dep
.
to_sym
]
else
dep
end
end
.
flatten
{
name
=>
config
.
merge
(
dependencies:
deps
)
}
else
{
name
=>
config
}
end
end
.
reduce
(
:merge
)
end
def
parallelize_job_names
(
name
,
total
)
jobs
=
[]
1
.
upto
(
total
)
do
|
idx
|
jobs
<<
[
"
#{
name
}
#{
idx
}
/
#{
total
}
"
,
idx
]
end
end
end
.
reduce
(
:merge
)
parallelized_jobs
end
def
parallelize_dependencies
(
parallelized_jobs
)
@jobs_config
.
map
do
|
name
,
config
|
if
config
[
:dependencies
]
deps
=
config
[
:dependencies
].
map
do
|
dep
|
if
parallelized_jobs
.
keys
.
include?
(
dep
.
to_sym
)
parallelized_jobs
[
dep
.
to_sym
]
else
dep
end
end
.
flatten
{
name
=>
config
.
merge
(
dependencies:
deps
)
}
else
{
name
=>
config
}
end
end
.
reduce
(
:merge
)
end
jobs
def
self
.
parallelize_job_names
(
name
,
total
)
end
Array
.
new
(
total
)
{
|
index
|
[
"
#{
name
}
#{
index
+
1
}
/
#{
total
}
"
,
index
+
1
]
}
end
end
end
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
5fd8933d
...
@@ -104,7 +104,7 @@ module Gitlab
...
@@ -104,7 +104,7 @@ module Gitlab
##
##
# Jobs
# Jobs
#
#
@jobs
=
Ci
::
Config
::
Normalizer
.
n
ormalize_jobs
(
@ci_config
.
jobs
)
@jobs
=
Ci
::
Config
::
Normalizer
.
n
ew
(
@ci_config
.
jobs
).
normalize_jobs
@jobs
.
each
do
|
name
,
job
|
@jobs
.
each
do
|
name
,
job
|
# logical validation for job
# logical validation for job
...
...
spec/lib/gitlab/ci/config/normalizer_spec.rb
View file @
5fd8933d
...
@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Normalizer do
...
@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Normalizer do
let
(
:config
)
{
{
job_name
=>
job_config
}
}
let
(
:config
)
{
{
job_name
=>
job_config
}
}
describe
'.normalize_jobs'
do
describe
'.normalize_jobs'
do
subject
{
described_class
.
n
ormalize_jobs
(
config
)
}
subject
{
described_class
.
n
ew
(
config
).
normalize_jobs
}
it
'does not have original job'
do
it
'does not have original job'
do
is_expected
.
not_to
include
(
job_name
)
is_expected
.
not_to
include
(
job_name
)
...
...
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