Skip to content
Snippets Groups Projects
Commit 3cdd0143 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Add rake task for finding the correct package repository.

parent d2a2c512
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -11,6 +11,7 @@ gem 'package_cloud'
gem 'thor', '0.18.1' # This specific version is required by package_cloud
gem 'json'
gem 'rspec'
gem 'rake'
 
group :test do
gem 'byebug'
Loading
Loading
Loading
Loading
@@ -138,6 +138,7 @@ GEM
proxifier (1.0.3)
rack (1.6.4)
rainbow (2.1.0)
rake (10.4.2)
rest-client (1.6.9)
mime-types (~> 1.16)
rspec (3.5.0)
Loading
Loading
@@ -188,5 +189,6 @@ DEPENDENCIES
omnibus!
omnibus-software!
package_cloud
rake
rspec
thor (= 0.18.1)
# All tasks in files placed in lib/gitlab/tasks ending in .rake will be loaded
# automatically
Rake.add_rakelib 'lib/gitlab/tasks'
class PackageRepository
def target
return puts ENV['PACKAGECLOUD_REPO'] if ENV['PACKAGECLOUD_REPO'] && !ENV['PACKAGECLOUD_REPO'].empty?
return puts ENV['RASPBERRY_REPO'] if ENV['RASPBERRY_REPO'] && !ENV['RASPBERRY_REPO'].empty?
return puts ENV['NIGHTLY_REPO'] if ENV['NIGHTLY_REPO'] && !ENV['NIGHTLY_REPO'].empty?
rc = is_rc?
if rc
puts rc
else
puts fetch_from_version
end
end
def is_rc?
if system('git describe | grep -q -e rc')
"unstable"
end
end
def fetch_from_version
is_ee = system('grep -q -E "\-ee" VERSION')
if ENV['EE'] || is_ee
"gitlab-ee"
else
"gitlab-ce"
end
end
end
require_relative '../package_repository.rb'
desc 'Package repository where the package will be stored'
namespace :repository do
task :target do
PackageRepository.new.target
end
task :is_rc do
PackageRepository.new.is_rc?
end
task :is_ee do
PackageRepository.new.fetch_from_version
end
end
require_relative '../../lib/gitlab/package_repository.rb'
require 'chef_helper'
describe PackageRepository do
let(:repo) { PackageRepository.new }
describe :is_rc? do
context 'on master' do
# Example:
# on non stable branch: 8.1.0+rc1.ce.0-1685-gd2a2c51
# on tag: 8.12.0+rc1.ee.0
before do
allow(repo).to receive(:system).with('git describe | grep -q -e rc').and_return(true)
end
it { expect(repo.is_rc?).to eq true }
end
context 'on stable branch' do
# Example:
# on non stable branch: 8.12.8+ce.0-1-gdac92d4
# on tag: 8.12.8+ce.0
before do
allow(repo).to receive(:system).with('git describe | grep -q -e rc').and_return(false)
end
it { expect(repo.is_rc?).to eq false }
end
end
describe :fetch_from_version do
context 'when EE' do
before do
allow(repo).to receive(:system).with('grep -q -E "\-ee" VERSION').and_return(true)
end
it { expect(repo.fetch_from_version).to eq 'gitlab-ee' }
end
context 'when CE' do
before do
allow(repo).to receive(:system).with('grep -q -E "\-ee" VERSION').and_return(false)
end
it { expect(repo.fetch_from_version).to eq 'gitlab-ce' }
end
end
describe :target do
shared_examples 'with an override repository' do
context 'with repository override' do
before do
set_all_env_variables
end
it 'uses the override repository' do
expect(STDOUT).to receive(:puts).with('super-stable-1234')
repo.target
end
end
end
shared_examples 'with a nightly repository' do
context 'with nightly repo' do
before do
set_nightly_env_variable
end
it 'uses the nightly repository' do
expect(STDOUT).to receive(:puts).with('nightly-builds')
repo.target
end
end
end
shared_examples 'with raspberry pi repo' do
context 'with raspberry pi repo' do
before do
set_raspi_env_variable
end
it 'uses the raspberry pi repository' do
expect(STDOUT).to receive(:puts).with('raspi')
repo.target
end
end
end
context 'on non-stable branch' do
before do
allow(repo).to receive(:system).with('git describe | grep -q -e rc').and_return(true)
end
it 'prints unstable' do
expect(STDOUT).to receive(:puts).with('unstable')
repo.target
end
it_behaves_like 'with an override repository'
it_behaves_like 'with a nightly repository'
it_behaves_like 'with raspberry pi repo'
end
context 'on a stable branch' do
before do
allow(repo).to receive(:system).with('git describe | grep -q -e rc').and_return(false)
end
context 'when EE' do
before do
allow(repo).to receive(:system).with('grep -q -E "\-ee" VERSION').and_return(true)
end
it 'prints gitlab-ee' do
expect(STDOUT).to receive(:puts).with('gitlab-ee')
repo.target
end
it_behaves_like 'with an override repository'
it_behaves_like 'with a nightly repository'
it_behaves_like 'with raspberry pi repo'
end
context 'when CE' do
before do
allow(repo).to receive(:system).with('grep -q -E "\-ee" VERSION').and_return(false)
end
it 'prints gitlab-ce' do
expect(STDOUT).to receive(:puts).with('gitlab-ce')
repo.target
end
it_behaves_like 'with an override repository'
it_behaves_like 'with a nightly repository'
it_behaves_like 'with raspberry pi repo'
end
end
end
def set_all_env_variables
stub_env_var("PACKAGECLOUD_REPO", "super-stable-1234")
stub_env_var("NIGHTLY_REPO", "nightly-builds")
stub_env_var("RASPBERRY_REPO", "raspi")
end
def set_nightly_env_variable
stub_env_var("PACKAGECLOUD_REPO", "")
stub_env_var("NIGHTLY_REPO", "nightly-builds")
stub_env_var("RASPBERRY_REPO", "")
end
def set_raspi_env_variable
stub_env_var("PACKAGECLOUD_REPO", "")
stub_env_var("NIGHTLY_REPO", "nightly-builds")
stub_env_var("RASPBERRY_REPO", "raspi")
end
end
Loading
Loading
@@ -11,5 +11,9 @@ module GitlabSpec
allow(File).to receive(:symlink?).with("/opt/gitlab/service/#{service}").and_return(value)
allow(OmnibusHelper).to receive(:success?).with("/opt/gitlab/embedded/bin/sv status #{service}").and_return(value)
end
def stub_env_var(var, value)
allow(ENV).to receive(:[]).with(var).and_return(value)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment