Commit 749b02fa authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'rs-cleanup-rakefile' into 'master'

Remove the LocalRepository ready check from Rakefile

See merge request !604
parents 33595eb3 ef384c7f
......@@ -5,23 +5,6 @@ require_relative 'lib/release_tools/support/tasks_helper'
Dir.glob('lib/tasks/*.rake').each { |task| import(task) }
unless ENV['CI'] || Rake.application.top_level_tasks.include?('default') || ReleaseTools::LocalRepository.ready?
abort('Please use the master branch and make sure you are up to date.'.colorize(:red))
end
def deprecate_as(new_task, old_task, args)
warn "This task has been deprecated in favor of " \
"`#{new_task.colorize(:green)}` and will soon be removed."
Raven.capture_message(
"Use of deprecated task #{old_task.name}",
extra: args,
level: 'info'
)
Rake::Task[new_task].invoke(*args)
end
namespace :auto_deploy do
desc "Prepare for auto-deploy by creating branches from the latest green commit on gitlab-ee and omnibus-gitlab"
task :prepare do
......@@ -31,14 +14,6 @@ namespace :auto_deploy do
end
end
task :tag, [:version] do |t, args|
deprecate_as 'release:tag', t, args
end
task :tag_security, [:version] do |t, args|
deprecate_as 'security:tag', t, args
end
desc "Sync master branch in remotes"
task :sync do
if skip?('ee')
......@@ -60,43 +35,11 @@ task :sync do
end
end
task :monthly_issue, [:version] do |t, args|
deprecate_as 'release:issue', t, args
end
task :patch_issue, [:version] do |t, args|
deprecate_as 'release:issue', t, args
end
task :qa_issue, [:from, :to, :version] do |t, args|
deprecate_as 'release:qa', t, args
end
task :security_qa_issue, [:from, :to, :version] do |t, args|
deprecate_as 'security:qa', t, args
end
# Undocumented; executed via CI schedule
task :close_expired_qa_issues do
ReleaseTools::Qa::IssueCloser.new.execute
end
task :patch_merge_request, [:version] do |t, args|
deprecate_as 'release:prepare', t, args
end
task :cherry_pick, [:version] do |t, args|
deprecate_as 'release:merge', t, args
end
task :security_cherry_pick, [:version] do |t, args|
deprecate_as 'security:merge', t, args
end
task :security_patch_issue, [:version] do |t, args|
deprecate_as 'security:issue', t, args
end
# Undocumented; executed via CI schedule
task :upstream_merge do
result = ReleaseTools::Services::UpstreamMergeService
......
......@@ -59,7 +59,6 @@ require 'release_tools/helm_chart_version'
require 'release_tools/helm_gitlab_version'
require 'release_tools/issuable'
require 'release_tools/issue'
require 'release_tools/local_repository'
require 'release_tools/merge_request'
require 'release_tools/monthly_issue'
require 'release_tools/omnibus_gitlab_version'
......
# frozen_string_literal: true
module ReleaseTools
class LocalRepository
def self.ready?
new.ready?
end
def ready?
master_branch? && up_to_date?
end
private
def master_branch?
run_git('rev-parse --abbrev-ref HEAD').chomp == 'master'
end
def up_to_date?
!run_git('pull --ff-only').nil?
end
def run_git(command)
out, err, st = Open3.capture3('git ' + command)
raise ScriptError.new(err) unless st.success?
out
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ReleaseTools::LocalRepository, :silence_stdout do
let(:fixture) { LocalRepositoryFixture.new }
let(:repo_path) { File.join('/tmp', fixture.class.repository_name) }
let(:repo_url) { "file://#{fixture.fixture_path}" }
let(:repo) { ReleaseTools::RemoteRepository.get(origin: repo_url) }
before do
fixture.rebuild_fixture!
end
context 'up to date repository' do
context 'master branch' do
it 'returns true' do
ensure_branch_exists('master')
in_repo_path do
expect(described_class.ready?).to be true
end
end
end
context 'different branch' do
it 'returns false' do
ensure_branch_exists('new-branch')
in_repo_path do
expect(described_class.ready?).to be false
end
end
end
end
context 'outdated repository' do
before do
ensure_branch_exists('master')
in_repo_path do
repo.write_file('test', 'test')
repo.commit('test', message: 'test commit')
end
end
context 'master branch' do
it 'returns true if fast-forward' do
in_repo_path do
expect(described_class.ready?).to be true
end
end
end
context 'master branch' do
it 'returns false if non fast-forward' do
st = double('st', success?: false)
expect(Open3).to receive(:capture3).with('git rev-parse --abbrev-ref HEAD').and_call_original
expect(Open3).to receive(:capture3).with('git pull --ff-only').and_return(['', 'error', st])
in_repo_path do
expect { described_class.ready? }.to raise_error(ScriptError)
end
end
end
context 'different branch' do
it 'returns false' do
ensure_branch_exists('new-branch')
in_repo_path do
expect(described_class.ready?).to be false
end
end
end
end
def ensure_branch_exists(branch)
repo.ensure_branch_exists(branch)
end
def in_repo_path
Dir.chdir(repo_path) do
yield
end
end
end
# frozen_string_literal: true
require 'fileutils'
require 'rugged'
require_relative 'repository_fixture'
class LocalRepositoryFixture
include RepositoryFixture
def self.repository_name
'repo'
end
def build_fixture(options = {})
commit_blob(
path: 'README.md',
content: 'Sample README.md',
message: 'Add empty README.md'
)
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