Commit 33c2f715 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'jv-ci-refspec' into 'master'

Fetch pipeline refs by name in CI runner

See merge request gitlab-org/gitlab!81989
parents 4128780b 80c7702e
...@@ -105,10 +105,7 @@ module Ci ...@@ -105,10 +105,7 @@ module Ci
end end
def refspec_for_persistent_ref def refspec_for_persistent_ref
# Use persistent_ref.sha because it sometimes causes 'git fetch' to do "+#{pipeline.persistent_ref.path}:#{pipeline.persistent_ref.path}"
# less work. See
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/746.
"+#{pipeline.persistent_ref.sha}:#{pipeline.persistent_ref.path}"
end end
def persistent_ref_exist? def persistent_ref_exist?
......
...@@ -173,11 +173,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -173,11 +173,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}", is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}",
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
it 'uses a SHA in the persistent refspec' do
expect(subject[0]).to match(%r{^\+[0-9a-f]{40}:refs/pipelines/[0-9]+$})
end end
context 'when ref is tag' do context 'when ref is tag' do
...@@ -185,7 +181,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -185,7 +181,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}", is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}",
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
context 'when GIT_DEPTH is zero' do context 'when GIT_DEPTH is zero' do
...@@ -196,7 +192,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -196,7 +192,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly('+refs/tags/*:refs/tags/*', is_expected.to contain_exactly('+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*', '+refs/heads/*:refs/remotes/origin/*',
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
end end
end end
...@@ -212,7 +208,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -212,7 +208,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
context 'when GIT_DEPTH is zero' do context 'when GIT_DEPTH is zero' do
...@@ -222,7 +218,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -222,7 +218,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/heads/*:refs/remotes/origin/*', '+refs/heads/*:refs/remotes/origin/*',
'+refs/tags/*:refs/tags/*') '+refs/tags/*:refs/tags/*')
end end
...@@ -232,7 +228,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -232,7 +228,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) } let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) }
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end end
end end
...@@ -250,7 +246,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -250,7 +246,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'exposes the persistent pipeline ref' do it 'exposes the persistent pipeline ref' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end end
end end
......
...@@ -156,7 +156,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -156,7 +156,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
'sha' => job.sha, 'sha' => job.sha,
'before_sha' => job.before_sha, 'before_sha' => job.before_sha,
'ref_type' => 'branch', 'ref_type' => 'branch',
'refspecs' => ["+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", 'refspecs' => ["+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"], "+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"],
'depth' => project.ci_default_git_depth } 'depth' => project.ci_default_git_depth }
end end
...@@ -291,7 +291,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -291,7 +291,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(json_response['git_info']['refspecs']) expect(json_response['git_info']['refspecs'])
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/tags/*:refs/tags/*', '+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*') '+refs/heads/*:refs/remotes/origin/*')
end end
...@@ -359,7 +359,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -359,7 +359,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(json_response['git_info']['refspecs']) expect(json_response['git_info']['refspecs'])
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/tags/*:refs/tags/*', '+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*') '+refs/heads/*:refs/remotes/origin/*')
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