Commit 304eb1d1 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '300581-remove-yaml_variables' into 'master'

Remove yaml_variables from CI config

See merge request gitlab-org/gitlab!67616
parents 45badbe3 44ad62b9
......@@ -47,7 +47,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do
ignore: false,
stage: 'test',
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage)
......@@ -70,7 +69,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do
ignore: false,
stage: 'test',
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :dag)
......
......@@ -28,7 +28,6 @@ RSpec.describe Gitlab::Ci::YamlProcessor do
},
when: "on_success",
allow_failure: false,
yaml_variables: [],
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
......@@ -43,7 +42,6 @@ RSpec.describe Gitlab::Ci::YamlProcessor do
},
when: "on_success",
allow_failure: false,
yaml_variables: [],
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
......@@ -66,7 +64,6 @@ RSpec.describe Gitlab::Ci::YamlProcessor do
},
when: "on_success",
allow_failure: false,
yaml_variables: [],
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
......@@ -84,7 +81,6 @@ RSpec.describe Gitlab::Ci::YamlProcessor do
],
when: "on_success",
allow_failure: false,
yaml_variables: [],
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
......@@ -160,7 +156,6 @@ RSpec.describe Gitlab::Ci::YamlProcessor do
only: { refs: %w[branches tags] },
when: 'on_success',
allow_failure: false,
yaml_variables: [],
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :dag
......
......@@ -88,9 +88,6 @@ module Gitlab
validate_against_warnings
end
# inherit root variables
@root_variables_value = deps&.variables_value # rubocop:disable Gitlab/ModuleWithInstanceVariables
yield if block_given?
end
end
......@@ -123,27 +120,13 @@ module Gitlab
stage: stage_value,
extends: extends,
rules: rules_value,
variables: root_and_job_variables_value, # https://gitlab.com/gitlab-org/gitlab/-/issues/300581
job_variables: job_variables,
job_variables: variables_value.to_h,
root_variables_inheritance: root_variables_inheritance,
only: only_value,
except: except_value,
resource_group: resource_group }.compact
end
def root_and_job_variables_value
root_variables = @root_variables_value.to_h # rubocop:disable Gitlab/ModuleWithInstanceVariables
root_variables = root_variables.select do |key, _|
inherit_entry&.variables_entry&.inherit?(key)
end
root_variables.merge(variables_value.to_h)
end
def job_variables
variables_value.to_h
end
def root_variables_inheritance
inherit_entry&.variables_entry&.value
end
......
......@@ -43,7 +43,6 @@ module Gitlab
{
name: name,
instance: instance,
variables: variables, # https://gitlab.com/gitlab-org/gitlab/-/issues/300581
job_variables: variables,
parallel: { total: total }
}.compact
......
......@@ -39,7 +39,7 @@ module Gitlab
@cache = Gitlab::Ci::Build::Cache
.new(attributes.delete(:cache), @pipeline)
recalculate_yaml_variables!
calculate_yaml_variables!
end
def name
......@@ -232,7 +232,7 @@ module Gitlab
{ options: { allow_failure_criteria: nil } }
end
def recalculate_yaml_variables!
def calculate_yaml_variables!
@seed_attributes[:yaml_variables] = Gitlab::Ci::Variables::Helpers.inherit_yaml_variables(
from: @context.root_variables, to: @job_variables, inheritance: @root_variables_inheritance
)
......
......@@ -69,7 +69,7 @@ module Gitlab
when: job[:when] || 'on_success',
environment: job[:environment_name],
coverage_regex: job[:coverage],
yaml_variables: transform_to_yaml_variables(job[:variables]), # https://gitlab.com/gitlab-org/gitlab/-/issues/300581
# yaml_variables is calculated with using job_variables in Seed::Build
job_variables: transform_to_yaml_variables(job[:job_variables]),
root_variables_inheritance: job[:root_variables_inheritance],
needs_attributes: job.dig(:needs, :job),
......
......@@ -54,7 +54,6 @@ module Gitlab
def to_hash
{
tag_list: tags || [],
yaml_variables: yaml_variables, # https://gitlab.com/gitlab-org/gitlab/-/issues/300581
job_variables: yaml_variables,
options: {
image: image_value,
......
......@@ -106,7 +106,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do
ignore: false,
stage: 'test',
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage)
......@@ -131,7 +130,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do
ignore: false,
stage: 'test',
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage)
......@@ -287,7 +285,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Bridge do
only: { refs: %w[branches tags] },
parallel: { matrix: [{ 'PROVIDER' => ['aws'], 'STACK' => %w(monitoring app1) },
{ 'PROVIDER' => ['gcp'], 'STACK' => %w(data) }] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage
......
......@@ -626,7 +626,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do
ignore: false,
after_script: %w[cleanup],
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage)
......
......@@ -99,7 +99,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Jobs do
only: { refs: %w[branches tags] },
stage: 'test',
trigger: { project: 'my/project' },
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage
......@@ -110,7 +109,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Jobs do
only: { refs: %w[branches tags] },
script: ['something'],
stage: 'test',
variables: {},
job_variables: {},
root_variables_inheritance: true,
scheduling_type: :stage
......
......@@ -362,76 +362,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Processable do
end
context 'with inheritance' do
context 'of variables' do
let(:config) do
{ variables: { A: 'job', B: 'job' } }
end
before do
entry.compose!(deps)
end
context 'with only job variables' do
it 'does return defined variables' do
expect(entry.value).to include(
variables: { 'A' => 'job', 'B' => 'job' },
job_variables: { 'A' => 'job', 'B' => 'job' },
root_variables_inheritance: true
)
end
end
context 'when root yaml variables are used' do
let(:variables) do
Gitlab::Ci::Config::Entry::Variables.new(
{ A: 'root', C: 'root', D: 'root' }
).value
end
it 'does return job and root variables' do
expect(entry.value).to include(
variables: { 'A' => 'job', 'B' => 'job', 'C' => 'root', 'D' => 'root' },
job_variables: { 'A' => 'job', 'B' => 'job' },
root_variables_inheritance: true
)
end
context 'when inherit of defaults is disabled' do
let(:config) do
{
variables: { A: 'job', B: 'job' },
inherit: { variables: false }
}
end
it 'does return job and root variables' do
expect(entry.value).to include(
variables: { 'A' => 'job', 'B' => 'job' },
job_variables: { 'A' => 'job', 'B' => 'job' },
root_variables_inheritance: false
)
end
end
context 'when inherit of only specific variable is enabled' do
let(:config) do
{
variables: { A: 'job', B: 'job' },
inherit: { variables: ['D'] }
}
end
it 'does return job and root variables' do
expect(entry.value).to include(
variables: { 'A' => 'job', 'B' => 'job', 'D' => 'root' },
job_variables: { 'A' => 'job', 'B' => 'job' },
root_variables_inheritance: ['D']
)
end
end
end
end
context 'of default:tags' do
using RSpec::Parameterized::TableSyntax
......@@ -493,7 +423,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Processable do
name: :rspec,
stage: 'test',
only: { refs: %w[branches tags] },
variables: {},
job_variables: {},
root_variables_inheritance: true
)
......
......@@ -132,7 +132,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
stage: 'test',
cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }],
variables: { 'VAR' => 'root', 'VAR2' => 'val 2' },
job_variables: {},
root_variables_inheritance: true,
ignore: false,
......@@ -148,7 +147,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
stage: 'test',
cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }],
variables: { 'VAR' => 'root', 'VAR2' => 'val 2' },
job_variables: {},
root_variables_inheritance: true,
ignore: false,
......@@ -166,7 +164,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
services: [{ name: "postgres:9.1" }, { name: "mysql:5.5" }],
cache: [{ key: "k", untracked: true, paths: ["public/"], policy: "pull-push", when: 'on_success' }],
only: { refs: %w(branches tags) },
variables: { 'VAR' => 'job', 'VAR2' => 'val 2' },
job_variables: { 'VAR' => 'job' },
root_variables_inheritance: true,
after_script: [],
......@@ -214,7 +211,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
stage: 'test',
cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }],
variables: { 'VAR' => 'root' },
job_variables: {},
root_variables_inheritance: true,
ignore: false,
......@@ -228,7 +224,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
services: [{ name: 'postgres:9.1' }, { name: 'mysql:5.5' }],
stage: 'test',
cache: [{ key: 'k', untracked: true, paths: ['public/'], policy: 'pull-push', when: 'on_success' }],
variables: { 'VAR' => 'job' },
job_variables: { 'VAR' => 'job' },
root_variables_inheritance: true,
ignore: false,
......
......@@ -50,10 +50,6 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
name: 'test: [aws, app1]',
instance: 1,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
},
job_variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
......@@ -63,10 +59,6 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
name: 'test: [aws, app2]',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
},
job_variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
......@@ -76,10 +68,6 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
name: 'test: [ovh, app]',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
},
job_variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
......@@ -89,10 +77,6 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
name: 'test: [gcp, app]',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
},
job_variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
......
......@@ -4,7 +4,7 @@ require 'fast_spec_helper'
RSpec.describe Gitlab::Ci::Config::Normalizer do
let(:job_name) { :rspec }
let(:job_config) { { script: 'rspec', parallel: parallel_config, name: 'rspec', variables: variables_config } }
let(:job_config) { { script: 'rspec', parallel: parallel_config, name: 'rspec', job_variables: variables_config } }
let(:config) { { job_name => job_config } }
describe '.normalize_jobs' do
......@@ -202,21 +202,21 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do
it 'sets job variables', :aggregate_failures do
expect(subject.values[0]).to match(
a_hash_including(variables: { VAR_1: 'A', VAR_2: 'B', USER_VARIABLE: 'user value' })
a_hash_including(job_variables: { VAR_1: 'A', VAR_2: 'B', USER_VARIABLE: 'user value' })
)
expect(subject.values[1]).to match(
a_hash_including(variables: { VAR_1: 'A', VAR_2: 'C', USER_VARIABLE: 'user value' })
a_hash_including(job_variables: { VAR_1: 'A', VAR_2: 'C', USER_VARIABLE: 'user value' })
)
end
it 'parallelizes jobs with original config' do
configs = subject.values.map do |config|
config.except(:name, :instance, :variables)
config.except(:name, :instance, :job_variables)
end
original_config = config[job_name]
.except(:name, :variables)
.except(:name, :job_variables)
.deep_merge(parallel: { total: 2 })
expect(configs).to all(match(a_hash_including(original_config)))
......
This diff is collapsed.
......@@ -82,7 +82,6 @@ RSpec.describe Gitlab::WebIde::Config::Entry::Global do
it 'returns correct script' do
expect(global.terminal_value).to eq({
tag_list: [],
yaml_variables: [],
job_variables: [],
options: {
before_script: ['ls'],
......
......@@ -141,7 +141,6 @@ RSpec.describe Gitlab::WebIde::Config::Entry::Terminal do
expect(entry.value)
.to eq(
tag_list: ['webide'],
yaml_variables: [{ key: 'KEY', value: 'value', public: true }],
job_variables: [{ key: 'KEY', value: 'value', public: true }],
options: {
image: { name: "ruby:3.0" },
......
......@@ -47,7 +47,6 @@ RSpec.describe Ide::TerminalConfigService do
status: :success,
terminal: {
tag_list: [],
yaml_variables: [],
job_variables: [],
options: { script: ["sleep 60"] }
})
......@@ -62,7 +61,6 @@ RSpec.describe Ide::TerminalConfigService do
status: :success,
terminal: {
tag_list: [],
yaml_variables: [],
job_variables: [],
options: { before_script: ["ls"], script: ["sleep 60"] }
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment