debian-mirror-gitlab/spec/support/helpers/test_env.rb

531 lines
17 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2021-09-30 23:02:18 +05:30
require 'parallel'
2022-03-02 08:16:31 +05:30
require_relative 'gitaly_setup'
2021-09-30 23:02:18 +05:30
2014-09-02 18:07:02 +05:30
module TestEnv
extend self
2018-03-17 18:26:18 +05:30
ComponentFailedToInstallError = Class.new(StandardError)
2015-04-26 12:48:37 +05:30
# When developing the seed repository, comment out the branch you will modify.
BRANCH_SHA = {
2021-12-11 22:18:48 +05:30
'signed-commits' => 'c7794c1',
2016-11-03 12:29:30 +05:30
'not-merged-branch' => 'b83d6e3',
'branch-merged' => '498214d',
2016-09-13 17:45:13 +05:30
'empty-branch' => '7efb185',
2016-09-29 09:46:39 +05:30
'ends-with.json' => '98b0d8b',
2016-09-13 17:45:13 +05:30
'flatten-dir' => 'e56497b',
'feature' => '0b4bc9a',
'feature_conflict' => 'bb5206f',
'fix' => '48f0be4',
'improve/awesome' => '5937ac0',
2018-03-17 18:26:18 +05:30
'merged-target' => '21751bf',
2016-09-13 17:45:13 +05:30
'markdown' => '0ed8c6c',
2018-03-17 18:26:18 +05:30
'lfs' => '55bc176',
2016-11-03 12:29:30 +05:30
'master' => 'b83d6e3',
'merge-test' => '5937ac0',
2016-09-13 17:45:13 +05:30
"'test'" => 'e56497b',
'orphaned-branch' => '45127a9',
'binary-encoding' => '7b1cf43',
'gitattributes' => '5a62481',
'expand-collapse-diffs' => '4842455',
2017-08-17 22:00:37 +05:30
'symlink-expand-diff' => '81e6355',
2020-07-28 23:09:34 +05:30
'diff-files-symlink-to-image' => '8cfca84',
'diff-files-image-to-symlink' => '3e94fda',
'diff-files-symlink-to-text' => '689815e',
'diff-files-text-to-symlink' => '5e2c270',
2016-09-13 17:45:13 +05:30
'expand-collapse-files' => '025db92',
'expand-collapse-lines' => '238e82d',
2018-12-13 13:39:08 +05:30
'pages-deploy' => '7897d5b',
'pages-deploy-target' => '7975be0',
2019-12-21 20:55:43 +05:30
'audio' => 'c3c21fd',
2016-09-13 17:45:13 +05:30
'video' => '8879059',
'crlf-diff' => '5938907',
2016-11-03 12:29:30 +05:30
'conflict-start' => '824be60',
2016-09-13 17:45:13 +05:30
'conflict-resolvable' => '1450cd6',
'conflict-binary-file' => '259a6fb',
2016-11-03 12:29:30 +05:30
'conflict-contains-conflict-markers' => '78a3086',
2016-09-13 17:45:13 +05:30
'conflict-missing-side' => 'eb227b3',
'conflict-non-utf8' => 'd0a293c',
'conflict-too-large' => '39fa04f',
2017-08-17 22:00:37 +05:30
'deleted-image-test' => '6c17798',
'wip' => 'b9238ee',
'csv' => '3dd0896',
'v1.1.0' => 'b83d6e3',
2022-05-07 20:08:51 +05:30
'add-ipython-files' => 'a867a602',
2017-09-10 17:25:29 +05:30
'add-pdf-file' => 'e774ebd',
2018-11-08 19:23:39 +05:30
'squash-large-files' => '54cec52',
2018-03-17 18:26:18 +05:30
'add-pdf-text-binary' => '79faa7b',
2018-11-08 19:23:39 +05:30
'add_images_and_changes' => '010d106',
'update-gitlab-shell-v-6-0-1' => '2f61d70',
2018-11-18 11:00:15 +05:30
'update-gitlab-shell-v-6-0-3' => 'de78448',
2019-02-15 15:39:39 +05:30
'merge-commit-analyze-before' => '1adbdef',
'merge-commit-analyze-side-branch' => '8a99451',
'merge-commit-analyze-after' => '646ece5',
2020-04-22 19:07:51 +05:30
'snippet/single-file' => '43e4080aaa14fc7d4b77ee1f5c9d067d5a7df10e',
2020-05-24 23:13:21 +05:30
'snippet/multiple-files' => '40232f7eb98b3f221886432def6e8bab2432add9',
2020-04-22 19:07:51 +05:30
'snippet/rename-and-edit-file' => '220a1e4b4dff37feea0625a7947a4c60fbe78365',
'snippet/edit-file' => 'c2f074f4f26929c92795a75775af79a6ed6d8430',
'snippet/no-files' => '671aaa842a4875e5f30082d1ab6feda345fdb94d',
2018-11-20 20:47:30 +05:30
'2-mb-file' => 'bf12d25',
2018-12-13 13:39:08 +05:30
'before-create-delete-modify-move' => '845009f',
'between-create-delete-modify-move' => '3f5f443',
'after-create-delete-modify-move' => 'ba3faa7',
'with-codeowners' => '219560e',
2019-02-15 15:39:39 +05:30
'submodule_inside_folder' => 'b491b92',
2019-07-07 11:18:12 +05:30
'png-lfs' => 'fe42f41',
2019-09-30 21:07:59 +05:30
'sha-starting-with-large-number' => '8426165',
2020-04-22 19:07:51 +05:30
'invalid-utf8-diff-paths' => '99e4853',
2020-10-24 23:57:45 +05:30
'compare-with-merge-head-source' => 'f20a03d',
2021-04-17 20:07:23 +05:30
'compare-with-merge-head-target' => '2f1e176',
2022-05-07 20:08:51 +05:30
'trailers' => 'f0a5ed6',
2022-06-21 17:19:12 +05:30
'add_commit_with_5mb_subject' => '8cf8e80',
'blame-on-renamed' => '32c33da',
'with-executables' => '6b8dc4a'
2017-08-17 22:00:37 +05:30
}.freeze
2015-09-11 14:41:01 +05:30
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
# need to keep all the branches in sync.
# We currently only need a subset of the branches
FORKED_BRANCH_SHA = {
2016-09-29 09:46:39 +05:30
'add-submodule-version-bump' => '3f547c0',
'master' => '5937ac0',
'remove-submodule' => '2a33e0c',
'conflict-resolvable-fork' => '404fa3f'
2017-08-17 22:00:37 +05:30
}.freeze
2015-04-26 12:48:37 +05:30
2020-04-22 19:07:51 +05:30
TMP_TEST_PATH = Rails.root.join('tmp', 'tests').freeze
2020-04-08 14:13:33 +05:30
SECOND_STORAGE_PATH = Rails.root.join('tmp', 'tests', 'second_storage')
2021-09-30 23:02:18 +05:30
SETUP_METHODS = %i[setup_gitaly setup_gitlab_shell setup_workhorse setup_factory_repo setup_forked_repo].freeze
# Can be overriden
def setup_methods
SETUP_METHODS
end
2017-09-10 17:25:29 +05:30
2014-09-02 18:07:02 +05:30
# Test environment
#
# See gitlab.yml.example test section for paths
#
2021-09-30 23:02:18 +05:30
def init
2018-03-17 18:26:18 +05:30
unless Rails.env.test?
puts "\nTestEnv.init can only be run if `RAILS_ENV` is set to 'test' not '#{Rails.env}'!\n"
exit 1
end
2021-09-30 23:02:18 +05:30
start = Time.now
2014-09-02 18:07:02 +05:30
# Disable mailer for spinach tests
2015-04-26 12:48:37 +05:30
clean_test_path
2014-09-02 18:07:02 +05:30
2021-09-30 23:02:18 +05:30
# Install components in parallel as most of the setup is I/O.
Parallel.each(setup_methods) do |method|
public_send(method)
2019-09-30 21:07:59 +05:30
end
2021-09-30 23:02:18 +05:30
post_init
puts "\nTest environment set up in #{Time.now - start} seconds"
2014-09-02 18:07:02 +05:30
end
2021-09-30 23:02:18 +05:30
# Can be overriden
def post_init
2022-03-02 08:16:31 +05:30
start_gitaly
2015-04-26 12:48:37 +05:30
end
# Clean /tmp/tests
#
# Keeps gitlab-shell and gitlab-test
def clean_test_path
2020-04-22 19:07:51 +05:30
Dir[File.join(TMP_TEST_PATH, '**')].each do |entry|
2019-10-12 21:52:04 +05:30
unless test_dirs.include?(File.basename(entry))
2015-04-26 12:48:37 +05:30
FileUtils.rm_rf(entry)
end
end
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
FileUtils.mkdir_p(
2022-03-02 08:16:31 +05:30
Gitlab::GitalyClient::StorageSettings.allow_disk_access { GitalySetup.repos_path }
2021-03-11 19:13:27 +05:30
)
2020-04-08 14:13:33 +05:30
FileUtils.mkdir_p(SECOND_STORAGE_PATH)
2017-08-17 22:00:37 +05:30
FileUtils.mkdir_p(backup_path)
FileUtils.mkdir_p(pages_path)
2018-03-17 18:26:18 +05:30
FileUtils.mkdir_p(artifacts_path)
2022-03-02 08:16:31 +05:30
FileUtils.mkdir_p(lfs_path)
FileUtils.mkdir_p(terraform_state_path)
FileUtils.mkdir_p(packages_path)
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
def setup_gitlab_shell
2019-12-21 20:55:43 +05:30
FileUtils.mkdir_p(Gitlab.config.gitlab_shell.path)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
def setup_gitaly
2018-03-17 18:26:18 +05:30
component_timed_setup('Gitaly',
2022-03-02 08:16:31 +05:30
install_dir: GitalySetup.gitaly_dir,
2018-03-17 18:26:18 +05:30
version: Gitlab::GitalyClient.expected_server_version,
2022-03-02 08:16:31 +05:30
task: "gitlab:gitaly:clone",
fresh_install: ENV.key?('FORCE_GITALY_INSTALL'),
task_args: [GitalySetup.gitaly_dir, GitalySetup.repos_path, gitaly_url].compact) do
GitalySetup.setup_gitaly
end
2019-12-26 22:10:19 +05:30
end
2022-03-02 08:16:31 +05:30
def start_gitaly
2019-12-26 22:10:19 +05:30
if ci?
2017-09-10 17:25:29 +05:30
# Gitaly has been spawned outside this process already
return
end
2022-03-02 08:16:31 +05:30
GitalySetup.spawn_gitaly
2020-04-22 19:07:51 +05:30
end
def gitaly_url
ENV.fetch('GITALY_REPO_URL', nil)
end
2021-09-30 23:02:18 +05:30
# Feature specs are run through Workhorse
2020-04-08 14:13:33 +05:30
def setup_workhorse
2021-10-27 15:23:28 +05:30
# Always rebuild the config file
if skip_compile_workhorse?
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil, force: true)
return
end
2021-02-22 17:27:13 +05:30
start = Time.now
FileUtils.rm_rf(workhorse_dir)
Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir)
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
File.write(workhorse_tree_file, workhorse_tree) if workhorse_source_clean?
2021-09-30 23:02:18 +05:30
puts "==> GitLab Workhorse set up in #{Time.now - start} seconds...\n"
2021-02-22 17:27:13 +05:30
end
def skip_compile_workhorse?
File.directory?(workhorse_dir) &&
workhorse_source_clean? &&
File.exist?(workhorse_tree_file) &&
workhorse_tree == File.read(workhorse_tree_file)
end
def workhorse_source_clean?
out = IO.popen(%w[git status --porcelain workhorse], &:read)
$?.success? && out.empty?
end
def workhorse_tree
IO.popen(%w[git rev-parse HEAD:workhorse], &:read)
end
def workhorse_tree_file
File.join(workhorse_dir, 'WORKHORSE_TREE')
2020-04-08 14:13:33 +05:30
end
def workhorse_dir
@workhorse_path ||= File.join('tmp', 'tests', 'gitlab-workhorse')
end
2021-03-08 18:12:59 +05:30
def with_workhorse(host, port, upstream, &blk)
2020-04-08 14:13:33 +05:30
host = "[#{host}]" if host.include?(':')
listen_addr = [host, port].join(':')
2021-02-22 17:27:13 +05:30
config_path = Gitlab::SetupHelper::Workhorse.get_config_path(workhorse_dir, {})
2020-11-24 15:15:51 +05:30
2020-04-08 14:13:33 +05:30
workhorse_pid = spawn(
2020-11-24 15:15:51 +05:30
{ 'PATH' => "#{ENV['PATH']}:#{workhorse_dir}" },
2020-04-08 14:13:33 +05:30
File.join(workhorse_dir, 'gitlab-workhorse'),
'-authSocket', upstream,
'-documentRoot', Rails.root.join('public').to_s,
'-listenAddr', listen_addr,
'-secretPath', Gitlab::Workhorse.secret_path.to_s,
2020-11-24 15:15:51 +05:30
'-config', config_path,
2020-04-08 14:13:33 +05:30
'-logFile', 'log/workhorse-test.log',
'-logFormat', 'structured',
'-developmentMode' # to serve assets and rich error messages
)
begin
yield
ensure
Process.kill('TERM', workhorse_pid)
Process.wait(workhorse_pid)
end
end
def workhorse_url
ENV.fetch('GITLAB_WORKHORSE_URL', nil)
end
2021-09-30 23:02:18 +05:30
# Create repository for FactoryBot.create(:project)
2014-09-02 18:07:02 +05:30
def setup_factory_repo
2020-05-24 23:13:21 +05:30
setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name, BRANCH_SHA)
2015-09-11 14:41:01 +05:30
end
2021-09-30 23:02:18 +05:30
# Create repository for FactoryBot.create(:forked_project_with_submodules)
2015-09-11 14:41:01 +05:30
# This repo has a submodule commit that is not present in the main test
# repository.
def setup_forked_repo
2020-05-24 23:13:21 +05:30
setup_repo(forked_repo_path, forked_repo_path_bare, forked_repo_name, FORKED_BRANCH_SHA)
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
2017-09-10 17:25:29 +05:30
def setup_repo(repo_path, repo_path_bare, repo_name, refs)
2015-09-11 14:41:01 +05:30
clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git"
unless File.directory?(repo_path)
2020-05-24 23:13:21 +05:30
start = Time.now
system(*%W(#{Gitlab.config.git.bin_path} clone --quiet -- #{clone_url} #{repo_path}))
2021-09-30 23:02:18 +05:30
puts "==> #{repo_path} set up in #{Time.now - start} seconds...\n"
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
set_repo_refs(repo_path, refs)
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
unless File.directory?(repo_path_bare)
2020-05-24 23:13:21 +05:30
start = Time.now
2017-08-17 22:00:37 +05:30
# We must copy bare repositories because we will push to them.
2020-05-24 23:13:21 +05:30
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --quiet --bare -- #{repo_path} #{repo_path_bare}))
2021-09-30 23:02:18 +05:30
puts "==> #{repo_path_bare} set up in #{Time.now - start} seconds...\n"
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
2020-03-13 15:44:24 +05:30
def copy_repo(subject, bare_repo:, refs:)
target_repo_path = File.expand_path(repos_path + "/#{subject.disk_path}.git")
2018-10-15 14:42:47 +05:30
2014-09-02 18:07:02 +05:30
FileUtils.mkdir_p(target_repo_path)
2017-09-10 17:25:29 +05:30
FileUtils.cp_r("#{File.expand_path(bare_repo)}/.", target_repo_path)
2014-09-02 18:07:02 +05:30
FileUtils.chmod_R 0755, target_repo_path
end
2019-12-26 22:10:19 +05:30
def rm_storage_dir(storage, dir)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
2022-03-02 08:16:31 +05:30
target_repo_refs_path = File.join(GitalySetup.repos_path(storage), dir)
2019-12-26 22:10:19 +05:30
FileUtils.remove_dir(target_repo_refs_path)
end
rescue Errno::ENOENT
end
def storage_dir_exists?(storage, dir)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
2022-03-02 08:16:31 +05:30
File.exist?(File.join(GitalySetup.repos_path(storage), dir))
2019-12-26 22:10:19 +05:30
end
end
2018-11-18 11:00:15 +05:30
def create_bare_repository(path)
FileUtils.mkdir_p(path)
system(git_env, *%W(#{Gitlab.config.git.bin_path} -C #{path} init --bare),
out: '/dev/null',
err: '/dev/null')
end
2014-09-02 18:07:02 +05:30
def repos_path
2022-03-02 08:16:31 +05:30
@repos_path ||= GitalySetup.repos_path
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
def backup_path
Gitlab.config.backup.path
end
2017-08-17 22:00:37 +05:30
def pages_path
Gitlab.config.pages.path
end
2018-03-17 18:26:18 +05:30
def artifacts_path
Gitlab.config.artifacts.storage_path
end
2022-03-02 08:16:31 +05:30
def lfs_path
Gitlab.config.lfs.storage_path
end
def terraform_state_path
Gitlab.config.terraform_state.storage_path
end
def packages_path
Gitlab.config.packages.storage_path
end
2016-04-02 18:10:28 +05:30
# When no cached assets exist, manually hit the root path to create them
#
# Otherwise they'd be created by the first test, often timing out and
# causing a transient test failure
2017-08-17 22:00:37 +05:30
def eager_load_driver_server
2016-04-02 18:10:28 +05:30
return unless defined?(Capybara)
2017-08-17 22:00:37 +05:30
puts "Starting the Capybara driver server..."
Capybara.current_session.visit '/'
2016-04-02 18:10:28 +05:30
end
2017-09-10 17:25:29 +05:30
def factory_repo_path_bare
"#{factory_repo_path}_bare"
end
def forked_repo_path_bare
"#{forked_repo_path}_bare"
end
def with_empty_bare_repository(name = nil)
path = Rails.root.join('tmp/tests', name || 'empty-bare-repository').to_s
yield(Rugged::Repository.init_at(path, :bare))
ensure
FileUtils.rm_rf(path)
end
2021-11-11 11:23:49 +05:30
def seed_db
2022-07-16 23:28:13 +05:30
Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.upsert_types
2021-11-11 11:23:49 +05:30
end
2015-04-26 12:48:37 +05:30
private
2019-09-04 21:01:54 +05:30
# These are directories that should be preserved at cleanup time
def test_dirs
@test_dirs ||= %w[
2019-10-12 21:52:04 +05:30
frontend
2019-09-04 21:01:54 +05:30
gitaly
gitlab-shell
gitlab-test
gitlab-test_bare
gitlab-test-fork
gitlab-test-fork_bare
2020-04-08 14:13:33 +05:30
gitlab-workhorse
gitlab_workhorse_secret
2019-09-04 21:01:54 +05:30
]
end
2015-04-26 12:48:37 +05:30
def factory_repo_path
@factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name)
end
def factory_repo_name
'gitlab-test'
end
2015-09-11 14:41:01 +05:30
def forked_repo_path
@forked_repo_path ||= Rails.root.join('tmp', 'tests', forked_repo_name)
end
def forked_repo_name
'gitlab-test-fork'
end
2015-04-26 12:48:37 +05:30
# Prevent developer git configurations from being persisted to test
# repositories
def git_env
2015-09-11 14:41:01 +05:30
{ 'GIT_TEMPLATE_DIR' => '' }
2015-04-26 12:48:37 +05:30
end
2016-09-29 09:46:39 +05:30
def set_repo_refs(repo_path, branch_sha)
2017-09-10 17:25:29 +05:30
instructions = branch_sha.map { |branch, sha| "update refs/heads/#{branch}\x00#{sha}\x00" }.join("\x00") << "\x00"
2017-08-17 22:00:37 +05:30
update_refs = %W(#{Gitlab.config.git.bin_path} update-ref --stdin -z)
reset = proc do
2017-09-10 17:25:29 +05:30
Dir.chdir(repo_path) do
IO.popen(update_refs, "w") { |io| io.write(instructions) }
$?.success?
end
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
# Try to reset without fetching to avoid using the network.
unless reset.call
raise 'Could not fetch test seed repository.' unless system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} fetch origin))
2019-10-12 21:52:04 +05:30
raise "Could not update test seed repository, please delete #{repo_path} and try again" unless reset.call
2018-03-17 18:26:18 +05:30
end
end
2022-03-02 08:16:31 +05:30
def component_timed_setup(component, install_dir:, version:, task:, fresh_install: true, task_args: [])
2018-03-17 18:26:18 +05:30
start = Time.now
ensure_component_dir_name_is_correct!(component, install_dir)
# On CI, once installed, components never need update
2019-12-26 22:10:19 +05:30
return if File.exist?(install_dir) && ci?
2018-03-17 18:26:18 +05:30
if component_needs_update?(install_dir, version)
# Cleanup the component entirely to ensure we start fresh
2022-03-02 08:16:31 +05:30
FileUtils.rm_rf(install_dir) if fresh_install
2018-03-17 18:26:18 +05:30
2021-09-30 23:02:18 +05:30
if ENV['SKIP_RAILS_ENV_IN_RAKE']
# When we run `scripts/setup-test-env`, we take care of loading the necessary dependencies
# so we can run the rake task programmatically.
Rake::Task[task].invoke(*task_args)
else
# In other cases, we run the task via `rake` so that the environment
# and dependencies are automatically loaded.
raise ComponentFailedToInstallError unless system('rake', "#{task}[#{task_args.join(',')}]")
2018-03-17 18:26:18 +05:30
end
2020-07-28 23:09:34 +05:30
yield if block_given?
2018-03-17 18:26:18 +05:30
2021-09-30 23:02:18 +05:30
puts "==> #{component} set up in #{Time.now - start} seconds...\n"
2020-07-28 23:09:34 +05:30
end
2018-03-17 18:26:18 +05:30
rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"
FileUtils.rm_rf(install_dir)
exit 1
end
2019-12-26 22:10:19 +05:30
def ci?
ENV['CI'].present?
end
2018-03-17 18:26:18 +05:30
def ensure_component_dir_name_is_correct!(component, path)
actual_component_dir_name = File.basename(path)
expected_component_dir_name = component.parameterize
unless actual_component_dir_name == expected_component_dir_name
puts " #{component} install dir should be named '#{expected_component_dir_name}', not '#{actual_component_dir_name}' (full install path given was '#{path}')!\n"
exit 1
2016-09-29 09:46:39 +05:30
end
end
2017-09-10 17:25:29 +05:30
def component_needs_update?(component_folder, expected_version)
2018-03-17 18:26:18 +05:30
# Allow local overrides of the component for tests during development
return false if Rails.env.test? && File.symlink?(component_folder)
2020-07-28 23:09:34 +05:30
return false if component_matches_git_sha?(component_folder, expected_version)
2021-01-29 00:20:46 +05:30
return false if component_ahead_of_target?(component_folder, expected_version)
2017-09-10 17:25:29 +05:30
version = File.read(File.join(component_folder, 'VERSION')).strip
# Notice that this will always yield true when using branch versions
# (`=branch_name`), but that actually makes sure the server is always based
# on the latest branch revision.
version != expected_version
rescue Errno::ENOENT
true
end
2020-07-28 23:09:34 +05:30
2021-01-29 00:20:46 +05:30
def component_ahead_of_target?(component_folder, expected_version)
# The HEAD of the component_folder will be used as heuristic for the version
# of the binaries, allowing to use Git to determine if HEAD is later than
# the expected version. Note: Git considers HEAD to be an anchestor of HEAD.
_out, exit_status = Gitlab::Popen.popen(%W[
#{Gitlab.config.git.bin_path}
-C #{component_folder}
merge-base --is-ancestor
#{expected_version} HEAD
])
exit_status == 0
end
2020-07-28 23:09:34 +05:30
def component_matches_git_sha?(component_folder, expected_version)
# Not a git SHA, so return early
2020-10-24 23:57:45 +05:30
return false unless expected_version =~ ::Gitlab::Git::COMMIT_ID
2020-07-28 23:09:34 +05:30
2022-01-26 12:08:38 +05:30
return false unless Dir.exist?(component_folder)
2020-07-28 23:09:34 +05:30
sha, exit_status = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} rev-parse HEAD), component_folder)
return false if exit_status != 0
expected_version == sha.chomp
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
require_relative('../../../ee/spec/support/helpers/ee/test_env') if Gitlab.ee?
2021-06-08 01:23:25 +05:30
::TestEnv.prepend_mod_with('TestEnv')
::TestEnv.extend_mod_with('TestEnv')