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
9b5a912f
Commit
9b5a912f
authored
Mar 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to test pipeline stage seeds
parent
b82de0f0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
36 deletions
+39
-36
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-0
lib/gitlab/ci/pipeline/chain/create.rb
lib/gitlab/ci/pipeline/chain/create.rb
+4
-6
lib/gitlab/ci/pipeline/chain/populate.rb
lib/gitlab/ci/pipeline/chain/populate.rb
+4
-3
lib/gitlab/ci/pipeline/chain/validate/config.rb
lib/gitlab/ci/pipeline/chain/validate/config.rb
+1
-1
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+4
-0
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+4
-7
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+11
-11
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+8
-8
No files found.
app/models/ci/pipeline.rb
View file @
9b5a912f
...
@@ -381,6 +381,9 @@ module Ci
...
@@ -381,6 +381,9 @@ module Ci
end
end
end
end
##
# TODO, setting yaml_errors should be moved to the pipeline creation chain.
#
def
config_processor
def
config_processor
return
unless
ci_yaml_file
return
unless
ci_yaml_file
return
@config_processor
if
defined?
(
@config_processor
)
return
@config_processor
if
defined?
(
@config_processor
)
...
...
lib/gitlab/ci/pipeline/chain/create.rb
View file @
9b5a912f
...
@@ -9,16 +9,14 @@ module Gitlab
...
@@ -9,16 +9,14 @@ module Gitlab
::
Ci
::
Pipeline
.
transaction
do
::
Ci
::
Pipeline
.
transaction
do
pipeline
.
save!
pipeline
.
save!
# TODO populate environments with find_or_initialize_by in the chain too.
##
##
# Create the environment before the build starts. This sets its slug and
# Create environments before the pipeline starts.
# makes it available as an environment variable
#
#
pipeline
.
builds
.
each
do
|
build
|
pipeline
.
builds
.
each
do
|
build
|
if
build
.
has_environment?
if
build
.
has_environment?
environment_name
=
build
.
expanded_environment_name
project
.
environments
.
find_or_create_by
(
project
.
environments
.
find_or_create_by
(
name:
environment_name
)
name:
build
.
expanded_environment_name
)
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/chain/populate.rb
View file @
9b5a912f
...
@@ -9,12 +9,13 @@ module Gitlab
...
@@ -9,12 +9,13 @@ module Gitlab
def
perform!
def
perform!
##
##
# Populate pipeline with seeds block.
# Populate pipeline with block `CreatePipelineService#execute`.
#
# It comes from a block argument to CreatePipelineService#execute.
#
#
@command
.
seeds_block
&
.
call
(
pipeline
)
@command
.
seeds_block
&
.
call
(
pipeline
)
##
# Populate pipeline with all stages and builds.
#
pipeline
.
stage_seeds
.
each
do
|
seed
|
pipeline
.
stage_seeds
.
each
do
|
seed
|
seed
.
user
=
current_user
seed
.
user
=
current_user
...
...
lib/gitlab/ci/pipeline/chain/validate/config.rb
View file @
9b5a912f
...
@@ -16,7 +16,7 @@ module Gitlab
...
@@ -16,7 +16,7 @@ module Gitlab
@pipeline
.
drop!
(
:config_error
)
@pipeline
.
drop!
(
:config_error
)
end
end
return
error
(
@pipeline
.
yaml_errors
)
error
(
@pipeline
.
yaml_errors
)
end
end
end
end
...
...
lib/gitlab/ci/pipeline/seed/build.rb
View file @
9b5a912f
...
@@ -3,6 +3,10 @@ module Gitlab
...
@@ -3,6 +3,10 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Seed
module
Seed
class
Build
<
Seed
::
Base
class
Build
<
Seed
::
Base
attr_reader
:pipeline
,
:attributes
delegate
:dig
,
to: :attributes
def
initialize
(
pipeline
,
attributes
)
def
initialize
(
pipeline
,
attributes
)
@pipeline
=
pipeline
@pipeline
=
pipeline
@attributes
=
attributes
@attributes
=
attributes
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
9b5a912f
...
@@ -3,7 +3,10 @@ module Gitlab
...
@@ -3,7 +3,10 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Seed
module
Seed
class
Stage
<
Seed
::
Base
class
Stage
<
Seed
::
Base
delegate
:size
,
to: :@seeds
attr_reader
:pipeline
,
:seeds
delegate
:size
,
to: :seeds
delegate
:dig
,
to: :seeds
def
initialize
(
pipeline
,
name
,
builds
)
def
initialize
(
pipeline
,
name
,
builds
)
@pipeline
=
pipeline
@pipeline
=
pipeline
...
@@ -24,12 +27,6 @@ module Gitlab
...
@@ -24,12 +27,6 @@ module Gitlab
project:
@pipeline
.
project
}
project:
@pipeline
.
project
}
end
end
# TODO decouple
#
def
builds_attributes
@seeds
.
map
(
&
:attributes
)
end
def
to_resource
def
to_resource
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@seeds
.
each
do
|
seed
|
@seeds
.
each
do
|
seed
|
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
9b5a912f
...
@@ -17,20 +17,20 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
...
@@ -17,20 +17,20 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
end
end
end
end
describe
'#
stage_
attributes'
do
describe
'#attributes'
do
it
'returns hash attributes of a stage'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
).
to
include
(
:name
,
:project
)
expect
(
subject
.
attributes
).
to
include
(
:name
,
:project
)
end
end
end
end
describe
'#
builds_attribute
s'
do
describe
'#
seed
s'
do
it
'returns hash attributes of all builds'
do
it
'returns hash attributes of all builds'
do
expect
(
subject
.
builds_attribute
s
.
size
).
to
eq
2
expect
(
subject
.
seed
s
.
size
).
to
eq
2
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds_attributes
)
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
)
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
end
end
...
@@ -40,17 +40,17 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
...
@@ -40,17 +40,17 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
end
end
it
'returns protected builds'
do
it
'returns protected builds'
do
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
protected:
true
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
protected:
true
))
end
end
end
end
context
'when a ref is
un
protected'
do
context
'when a ref is
not
protected'
do
before
do
before
do
allow_any_instance_of
(
Project
).
to
receive
(
:protected_for?
).
and_return
(
false
)
allow_any_instance_of
(
Project
).
to
receive
(
:protected_for?
).
and_return
(
false
)
end
end
it
'returns unprotected builds'
do
it
'returns unprotected builds'
do
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
protected:
false
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
protected:
false
))
end
end
end
end
end
end
...
@@ -61,7 +61,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
...
@@ -61,7 +61,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
it
'assignes relevant pipeline attributes'
do
it
'assignes relevant pipeline attributes'
do
subject
.
user
=
user
subject
.
user
=
user
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
user:
user
))
end
end
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
9b5a912f
...
@@ -121,9 +121,9 @@ module Gitlab
...
@@ -121,9 +121,9 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
second
.
attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
0
,
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
end
end
...
@@ -142,7 +142,7 @@ module Gitlab
...
@@ -142,7 +142,7 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
...
@@ -161,7 +161,7 @@ module Gitlab
...
@@ -161,7 +161,7 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
...
@@ -183,8 +183,8 @@ module Gitlab
...
@@ -183,8 +183,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
end
end
...
@@ -209,7 +209,7 @@ module Gitlab
...
@@ -209,7 +209,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
end
end
...
...
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