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
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
Show 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
end
end
##
# TODO, setting yaml_errors should be moved to the pipeline creation chain.
#
def
config_processor
return
unless
ci_yaml_file
return
@config_processor
if
defined?
(
@config_processor
)
...
...
lib/gitlab/ci/pipeline/chain/create.rb
View file @
9b5a912f
...
...
@@ -9,16 +9,14 @@ module Gitlab
::
Ci
::
Pipeline
.
transaction
do
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
# makes it available as an environment variable
# Create environments before the pipeline starts.
#
pipeline
.
builds
.
each
do
|
build
|
if
build
.
has_environment?
environment_name
=
build
.
expanded_environment_name
project
.
environments
.
find_or_create_by
(
name:
environment_name
)
project
.
environments
.
find_or_create_by
(
name:
build
.
expanded_environment_name
)
end
end
end
...
...
lib/gitlab/ci/pipeline/chain/populate.rb
View file @
9b5a912f
...
...
@@ -9,12 +9,13 @@ module Gitlab
def
perform!
##
# Populate pipeline with seeds block.
#
# It comes from a block argument to CreatePipelineService#execute.
# Populate pipeline with block `CreatePipelineService#execute`.
#
@command
.
seeds_block
&
.
call
(
pipeline
)
##
# Populate pipeline with all stages and builds.
#
pipeline
.
stage_seeds
.
each
do
|
seed
|
seed
.
user
=
current_user
...
...
lib/gitlab/ci/pipeline/chain/validate/config.rb
View file @
9b5a912f
...
...
@@ -16,7 +16,7 @@ module Gitlab
@pipeline
.
drop!
(
:config_error
)
end
return
error
(
@pipeline
.
yaml_errors
)
error
(
@pipeline
.
yaml_errors
)
end
end
...
...
lib/gitlab/ci/pipeline/seed/build.rb
View file @
9b5a912f
...
...
@@ -3,6 +3,10 @@ module Gitlab
module
Pipeline
module
Seed
class
Build
<
Seed
::
Base
attr_reader
:pipeline
,
:attributes
delegate
:dig
,
to: :attributes
def
initialize
(
pipeline
,
attributes
)
@pipeline
=
pipeline
@attributes
=
attributes
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
9b5a912f
...
...
@@ -3,7 +3,10 @@ module Gitlab
module
Pipeline
module
Seed
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
)
@pipeline
=
pipeline
...
...
@@ -24,12 +27,6 @@ module Gitlab
project:
@pipeline
.
project
}
end
# TODO decouple
#
def
builds_attributes
@seeds
.
map
(
&
:attributes
)
end
def
to_resource
::
Ci
::
Stage
.
new
(
attributes
).
tap
do
|
stage
|
@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
end
end
describe
'#
stage_
attributes'
do
describe
'#attributes'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
).
to
include
(
:name
,
:project
)
end
end
describe
'#
builds_attribute
s'
do
describe
'#
seed
s'
do
it
'returns hash attributes of all builds'
do
expect
(
subject
.
builds_attribute
s
.
size
).
to
eq
2
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds_attributes
)
expect
(
subject
.
seed
s
.
size
).
to
eq
2
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
)
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
end
...
...
@@ -40,17 +40,17 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
end
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
context
'when a ref is
un
protected'
do
context
'when a ref is
not
protected'
do
before
do
allow_any_instance_of
(
Project
).
to
receive
(
:protected_for?
).
and_return
(
false
)
end
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
...
...
@@ -61,7 +61,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
it
'assignes relevant pipeline attributes'
do
subject
.
user
=
user
expect
(
subject
.
builds_attributes
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
seeds
.
map
(
&
:attributes
)
).
to
all
(
include
(
user:
user
))
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
9b5a912f
...
...
@@ -121,9 +121,9 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
dig
(
0
,
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
...
...
@@ -142,7 +142,7 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
1
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
...
...
@@ -161,7 +161,7 @@ module Gitlab
expect
(
seeds
.
size
).
to
eq
1
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
...
...
@@ -183,8 +183,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
dig
(
0
,
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
dig
(
1
,
0
,
:name
)).
to
eq
'production'
end
end
...
...
@@ -209,7 +209,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
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
...
...
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