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
5192f606
Commit
5192f606
authored
Mar 12, 2021
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracts cache initialization to collection class
parent
ba8bd0de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
154 additions
and
31 deletions
+154
-31
lib/gitlab/ci/build/cache.rb
lib/gitlab/ci/build/cache.rb
+46
-0
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+3
-31
spec/lib/gitlab/ci/build/cache_spec.rb
spec/lib/gitlab/ci/build/cache_spec.rb
+105
-0
No files found.
lib/gitlab/ci/build/cache.rb
0 → 100644
View file @
5192f606
# frozen_string_literal: true
module
Gitlab
module
Ci
module
Build
class
Cache
include
::
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
cache
,
pipeline
)
if
multiple_cache_per_job?
cache
=
Array
.
wrap
(
cache
)
@cache
=
cache
.
map
do
|
cache
|
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
.
new
(
pipeline
,
cache
)
end
else
@cache
=
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
.
new
(
pipeline
,
cache
)
end
end
def
cache_attributes
strong_memoize
(
:cache_attributes
)
do
if
multiple_cache_per_job?
if
@cache
.
empty?
{}
else
{
options:
{
cache:
@cache
.
map
(
&
:attributes
)
}
}
end
else
@cache
.
build_attributes
end
end
end
private
def
multiple_cache_per_job?
strong_memoize
(
:multiple_cache_per_job
)
do
::
Gitlab
::
Ci
::
Features
.
multiple_cache_per_job?
end
end
end
end
end
end
lib/gitlab/ci/pipeline/seed/build.rb
View file @
5192f606
...
@@ -28,16 +28,8 @@ module Gitlab
...
@@ -28,16 +28,8 @@ module Gitlab
.
fabricate
(
attributes
.
delete
(
:except
))
.
fabricate
(
attributes
.
delete
(
:except
))
@rules
=
Gitlab
::
Ci
::
Build
::
Rules
@rules
=
Gitlab
::
Ci
::
Build
::
Rules
.
new
(
attributes
.
delete
(
:rules
),
default_when:
'on_success'
)
.
new
(
attributes
.
delete
(
:rules
),
default_when:
'on_success'
)
@cache
=
Gitlab
::
Ci
::
Build
::
Cache
if
multiple_cache_per_job?
.
new
(
attributes
.
delete
(
:cache
),
pipeline
)
cache
=
Array
.
wrap
(
attributes
.
delete
(
:cache
))
@cache
=
cache
.
map
do
|
cache
|
Seed
::
Build
::
Cache
.
new
(
pipeline
,
cache
)
end
else
@cache
=
Seed
::
Build
::
Cache
.
new
(
pipeline
,
attributes
.
delete
(
:cache
))
end
end
end
def
name
def
name
...
@@ -69,7 +61,7 @@ module Gitlab
...
@@ -69,7 +61,7 @@ module Gitlab
.
deep_merge
(
pipeline_attributes
)
.
deep_merge
(
pipeline_attributes
)
.
deep_merge
(
rules_attributes
)
.
deep_merge
(
rules_attributes
)
.
deep_merge
(
allow_failure_criteria_attributes
)
.
deep_merge
(
allow_failure_criteria_attributes
)
.
deep_merge
(
cache_attributes
)
.
deep_merge
(
@cache
.
cache_attributes
)
end
end
def
bridge?
def
bridge?
...
@@ -203,26 +195,6 @@ module Gitlab
...
@@ -203,26 +195,6 @@ module Gitlab
end
end
end
end
def
cache_attributes
strong_memoize
(
:cache_attributes
)
do
if
multiple_cache_per_job?
if
@cache
.
empty?
{}
else
{
options:
{
cache:
@cache
.
map
(
&
:attributes
)
}
}
end
else
@cache
.
build_attributes
end
end
end
def
multiple_cache_per_job?
strong_memoize
(
:multiple_cache_per_job
)
do
::
Gitlab
::
Ci
::
Features
.
multiple_cache_per_job?
end
end
# If a job uses `allow_failure:exit_codes` and `rules:allow_failure`
# If a job uses `allow_failure:exit_codes` and `rules:allow_failure`
# we need to prevent the exit codes from being persisted because they
# we need to prevent the exit codes from being persisted because they
# would break the behavior defined by `rules:allow_failure`.
# would break the behavior defined by `rules:allow_failure`.
...
...
spec/lib/gitlab/ci/build/cache_spec.rb
0 → 100644
View file @
5192f606
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Ci
::
Build
::
Cache
do
describe
'.initialize'
do
context
'when the multiple cache feature flag is disabled'
do
before
do
stub_feature_flags
(
multiple_cache_per_job:
false
)
end
it
'instantiates a cache seed'
do
cache_config
=
{
key:
'key-a'
}
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache_seed
=
double
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
)
allow
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
receive
(
:new
).
and_return
(
cache_seed
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
expect
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
have_received
(
:new
).
with
(
pipeline
,
cache_config
)
expect
(
cache
.
instance_variable_get
(
:@cache
)).
to
eq
(
cache_seed
)
end
end
context
'when the multiple cache feature flag is enabled'
do
context
'when the cache is an array'
do
it
'instantiates an array of cache seeds'
do
cache_config
=
[{
key:
'key-a'
},
{
key:
'key-b'
}]
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache_seed_a
=
double
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
)
cache_seed_b
=
double
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
)
allow
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
receive
(
:new
).
and_return
(
cache_seed_a
,
cache_seed_b
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
expect
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
have_received
(
:new
).
with
(
pipeline
,
{
key:
'key-a'
})
expect
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
have_received
(
:new
).
with
(
pipeline
,
{
key:
'key-b'
})
expect
(
cache
.
instance_variable_get
(
:@cache
)).
to
eq
([
cache_seed_a
,
cache_seed_b
])
end
end
context
'when the cache is a hash'
do
it
'instantiates a cache seed'
do
cache_config
=
{
key:
'key-a'
}
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache_seed
=
double
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
)
allow
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
receive
(
:new
).
and_return
(
cache_seed
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
expect
(
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Build
::
Cache
).
to
have_received
(
:new
).
with
(
pipeline
,
cache_config
)
expect
(
cache
.
instance_variable_get
(
:@cache
)).
to
eq
([
cache_seed
])
end
end
end
end
describe
'#cache_attributes'
do
context
'when the multiple cache feature flag is disabled'
do
before
do
stub_feature_flags
(
multiple_cache_per_job:
false
)
end
it
"returns the cache seed's build attributes"
do
cache_config
=
{
key:
'key-a'
}
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
attributes
=
cache
.
cache_attributes
expect
(
attributes
).
to
eq
({
options:
{
cache:
{
key:
'key-a'
}
}
})
end
end
context
'when the multiple cache feature flag is enabled'
do
context
'when there are no caches'
do
it
'returns an empty hash'
do
cache_config
=
[]
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
attributes
=
cache
.
cache_attributes
expect
(
attributes
).
to
eq
({})
end
end
context
'when there are caches'
do
it
'returns the structured attributes for the caches'
do
cache_config
=
[{
key:
'key-a'
},
{
key:
'key-b'
}]
pipeline
=
double
(
::
Ci
::
Pipeline
)
cache
=
described_class
.
new
(
cache_config
,
pipeline
)
attributes
=
cache
.
cache_attributes
expect
(
attributes
).
to
eq
({
options:
{
cache:
cache_config
}
})
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