Commit 3de90595 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ac-versions-like-omnibus' into 'master'

Align component version processing with omnibus

Closes #34873

See merge request gitlab-org/gitlab!19151
parents 3556a1df 5d1867cb
......@@ -166,12 +166,11 @@ end
Normally, GitLab CE/EE tests use a local clone of Gitaly in
`tmp/tests/gitaly` pinned at the version specified in
`GITALY_SERVER_VERSION`. The `GITALY_SERVER_VERSION` file supports
`=my-branch` syntax to use a custom branch in <https://gitlab.com/gitlab-org/gitaly>. If
`GITALY_SERVER_VERSION`. The `GITALY_SERVER_VERSION` file supports also
branches and SHA to use a custom commit in <https://gitlab.com/gitlab-org/gitaly>. If
you want to run tests locally against a modified version of Gitaly you
can replace `tmp/tests/gitaly` with a symlink. This is much faster
because the `=my-branch` syntax forces a Gitaly re-install each time
you run `rspec`.
because if will avoid a Gitaly re-install each time you run `rspec`.
```shell
rm -rf tmp/tests/gitaly
......
......@@ -158,15 +158,17 @@ module Gitlab
end
def checkout_or_clone_version(version:, repo:, target_dir:)
version =
if version.starts_with?("=")
version.sub(/\A=/, '') # tag or branch
else
"v#{version}" # tag
end
clone_repo(repo, target_dir) unless Dir.exist?(target_dir)
checkout_version(version, target_dir)
checkout_version(get_version(version), target_dir)
end
# this function implements the same logic we have in omnibus for dealing with components version
def get_version(component_version)
# If not a valid version string following SemVer it is probably a branch name or a SHA
# commit of one of our own component so it doesn't need `v` prepended
return component_version unless /^\d+\.\d+\.\d+(-rc\d+)?$/.match?(component_version)
"v#{component_version}"
end
def clone_repo(repo, target_dir)
......
......@@ -20,22 +20,12 @@ describe Gitlab::TaskHelpers do
end
it 'checkout the version and reset to it' do
expect(subject).to receive(:get_version).with(version).and_call_original
expect(subject).to receive(:checkout_version).with(tag, clone_path)
subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end
context 'with a branch version' do
let(:version) { '=branch_name' }
let(:branch) { 'branch_name' }
it 'checkout the version and reset to it with a branch name' do
expect(subject).to receive(:checkout_version).with(branch, clone_path)
subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end
end
context "target_dir doesn't exist" do
it 'clones the repo' do
expect(subject).to receive(:clone_repo).with(repo, clone_path)
......@@ -96,4 +86,19 @@ describe Gitlab::TaskHelpers do
expect { subject.run_command!(['bash', '-c', 'exit 1']) }.to raise_error Gitlab::TaskFailedError
end
end
describe '#get_version' do
using RSpec::Parameterized::TableSyntax
where(:version, :result) do
'1.1.1' | 'v1.1.1'
'master' | 'master'
'12.4.0-rc7' | 'v12.4.0-rc7'
'594c3ea3e0e5540e5915bd1c49713a0381459dd6' | '594c3ea3e0e5540e5915bd1c49713a0381459dd6'
end
with_them do
it { expect(subject.get_version(version)).to eq(result) }
end
end
end
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