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
Boxiang Sun
gitlab-ce
Commits
4ba960c1
Commit
4ba960c1
authored
Nov 06, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use instance based approach for Normalizer
parent
f48261a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
39 deletions
+41
-39
lib/gitlab/ci/config/normalizer.rb
lib/gitlab/ci/config/normalizer.rb
+39
-37
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 @
4ba960c1
...
...
@@ -4,57 +4,59 @@ module Gitlab
module
Ci
class
Config
class
Normalizer
class
<<
self
def
normalize_jobs
(
jobs_config
)
parallelized_jobs
=
extract_parallelized_jobs
(
jobs_config
)
parallelized_config
=
parallelize_jobs
(
jobs_config
,
parallelized_jobs
)
parallelize_dependencies
(
parallelized_config
,
parallelized_jobs
)
end
def
initialize
(
jobs_config
)
@jobs_config
=
jobs_config
end
def
normalize_jobs
extract_parallelized_jobs
parallelized_config
=
parallelize_jobs
parallelize_dependencies
(
parallelized_config
)
end
private
private
def
extract_parallelized_jobs
(
jobs_config
)
parallelized_jobs
=
{}
def
extract_parallelized_jobs
@
parallelized_jobs
=
{}
jobs_config
.
each
do
|
job_name
,
config
|
if
config
[
:parallel
]
parallelized_jobs
[
job_name
]
=
parallelize_job_names
(
job_name
,
config
[
:parallel
])
end
@jobs_config
.
each
do
|
job_name
,
config
|
if
config
[
:parallel
]
@parallelized_jobs
[
job_name
]
=
self
.
class
.
parallelize_job_names
(
job_name
,
config
[
:parallel
])
end
parallelized_jobs
end
def
parallelize_jobs
(
jobs_config
,
parallelized_jobs
)
jobs_config
.
each_with_object
({})
do
|
(
job_name
,
config
),
hash
|
if
parallelized_jobs
.
key?
(
job_name
)
parallelized_jobs
[
job_name
].
each
{
|
name
,
index
|
hash
[
name
.
to_sym
]
=
config
.
merge
(
name:
name
,
instance:
index
)
}
else
hash
[
job_name
]
=
config
end
@parallelized_jobs
end
hash
def
parallelize_jobs
@jobs_config
.
each_with_object
({})
do
|
(
job_name
,
config
),
hash
|
if
@parallelized_jobs
.
key?
(
job_name
)
@parallelized_jobs
[
job_name
].
each
{
|
name
,
index
|
hash
[
name
.
to_sym
]
=
config
.
merge
(
name:
name
,
instance:
index
)
}
else
hash
[
job_name
]
=
config
end
hash
end
end
def
parallelize_dependencies
(
parallelized_config
,
parallelized_jobs
)
parallelized_config
.
each_with_object
({})
do
|
(
job_name
,
config
),
hash
|
intersection
=
config
[
:dependencies
]
&
parallelized_jobs
.
keys
.
map
(
&
:to_s
)
if
intersection
&&
intersection
.
any?
deps
=
intersection
.
map
{
|
dep
|
parallelized_jobs
[
dep
.
to_sym
].
map
(
&
:first
)
}.
flatten
hash
[
job_name
]
=
config
.
merge
(
dependencies:
deps
)
else
hash
[
job_name
]
=
config
end
hash
def
parallelize_dependencies
(
parallelized_config
)
parallelized_config
.
each_with_object
({})
do
|
(
job_name
,
config
),
hash
|
intersection
=
config
[
:dependencies
]
&
@parallelized_jobs
.
keys
.
map
(
&
:to_s
)
if
intersection
&&
intersection
.
any?
deps
=
intersection
.
map
{
|
dep
|
@parallelized_jobs
[
dep
.
to_sym
].
map
(
&
:first
)
}.
flatten
hash
[
job_name
]
=
config
.
merge
(
dependencies:
deps
)
else
hash
[
job_name
]
=
config
end
end
def
parallelize_job_names
(
name
,
total
)
Array
.
new
(
total
)
{
|
index
|
[
"
#{
name
}
#{
index
+
1
}
/
#{
total
}
"
,
index
+
1
]
}
hash
end
end
def
self
.
parallelize_job_names
(
name
,
total
)
Array
.
new
(
total
)
{
|
index
|
[
"
#{
name
}
#{
index
+
1
}
/
#{
total
}
"
,
index
+
1
]
}
end
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
4ba960c1
...
...
@@ -104,7 +104,7 @@ module Gitlab
##
# 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
|
# logical validation for job
...
...
spec/lib/gitlab/ci/config/normalizer_spec.rb
View file @
4ba960c1
...
...
@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Normalizer do
let
(
:config
)
{
{
job_name
=>
job_config
}
}
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
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