# HG changeset patch # User Balasankar 'Balu' C <balasankar@gitlab.com> # Date 1677610426 0 # Tue Feb 28 18:53:46 2023 +0000 # Node ID d588f06f5661ba4a799a8165b2d2bc6e6414dccf # Parent 5937d2232bb3002930c69b92b9e1ccae4d3d3ea1 Add method to check for non-auto-deploy tags Signed-off-by: Balasankar "Balu" C <balasankar@gitlab.com> diff --git a/config/software/ruby.rb b/config/software/ruby.rb --- a/config/software/ruby.rb +++ b/config/software/ruby.rb @@ -22,9 +22,15 @@ skip_transitive_dependency_licensing true -if Gitlab::Util.get_env('RUBY2_BUILD') == 'true' || Build::Check.on_tag? || Build::Check.on_stable_branch? - # Follow the Ruby upgrade guidelines when changing the ruby version - # link: https://docs.gitlab.com/ee/development/ruby_upgrade.html +# Follow the Ruby upgrade guidewhen changing the ruby version +# link: https://docs.gitlab.com/ee/development/ruby_upgrade.html +# Bundle Ruby 2 if either (or multiple) of the following conditions are met: +# 1. `RUBY2_BUILD` variable is set to true +# 2. Running on stable branch +# 3. Running on regular (non-auto-deploy) tag +# 4. Running on auto-deploy tag, but variable `USE_NEXT_RUBY_VERSION_IN_AUTODEPLOY` is not set to true +# In all other scenarios, bundle Ruby 3 +if Gitlab::Util.get_env('RUBY2_BUILD') == 'true' || Build::Check.on_stable_branch? || Build::Check.on_regular_tag? || (Build::Check.is_auto_deploy_tag? && Gitlab::Util.get_env('USE_NEXT_RUBY_VERSION_IN_AUTODEPLOY') != "true") default_version '2.7.7' else default_version Gitlab::Util.get_env('NEXT_RUBY_VERSION') || '3.0.5' diff --git a/lib/gitlab/build/check.rb b/lib/gitlab/build/check.rb --- a/lib/gitlab/build/check.rb +++ b/lib/gitlab/build/check.rb @@ -76,6 +76,10 @@ system('git describe --exact-match > /dev/null 2>&1') end + def on_regular_tag? + on_tag? && !is_auto_deploy_tag? + end + def on_stable_branch? Build::Info.branch_name&.match?(/^\d+-\d+-stable$/) end diff --git a/spec/lib/gitlab/build/check_spec.rb b/spec/lib/gitlab/build/check_spec.rb --- a/spec/lib/gitlab/build/check_spec.rb +++ b/spec/lib/gitlab/build/check_spec.rb @@ -200,4 +200,65 @@ end end end + + describe 'on_regular_tag?' do + context 'when on a regular branch' do + before do + stub_env_var('CI_COMMIT_BRANCH', 'my-feature-branch') + allow(described_class).to receive(:system).with(/git describe --exact-match/).and_return(false) + end + + it 'returns false' do + expect(described_class.on_regular_tag?).to be_falsey + end + end + + context 'when on a stable branch' do + before do + stub_env_var('CI_COMMIT_BRANCH', '15-6-stable') + allow(described_class).to receive(:system).with(/git describe --exact-match/).and_return(false) + end + + it 'returns false' do + expect(described_class.on_regular_tag?).to be_falsey + end + end + + context 'when on RC tag' do + before do + stub_env_var('CI_COMMIT_BRANCH', '') + stub_env_var('CI_COMMIT_TAG', '15.8.0+rc42.ce.0') + allow(described_class).to receive(:system).with(/git describe --exact-match/).and_return(true) + end + + it 'returns true' do + expect(described_class.on_regular_tag?).to be_truthy + end + end + + context 'when on stable tag' do + before do + stub_env_var('CI_COMMIT_BRANCH', '') + stub_env_var('CI_COMMIT_TAG', '15.8.0+ce.0') + allow(described_class).to receive(:system).with(/git describe --exact-match/).and_return(true) + end + + it 'returns true' do + expect(described_class.on_regular_tag?).to be_truthy + end + end + + context 'when on auto-deploy tag' do + before do + stub_env_var('CI_COMMIT_BRANCH', '') + stub_env_var('CI_COMMIT_TAG', '15.8.202301050320+b251a9da107.0e5d6807f3a') + allow(Build::Info).to receive(:current_git_tag).and_return('15.8.202301050320+b251a9da107.0e5d6807f3a') + allow(described_class).to receive(:system).with(/git describe --exact-match/).and_return(true) + end + + it 'returns false' do + expect(described_class.on_regular_tag?).to be_falsey + end + end + end end