Commit 25fee1d4 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'rs-green-anything' into 'master'

Rename GreenMaster to PassingBuild

See merge request !593
parents 88bda04c e9ca8476
......@@ -5,7 +5,6 @@ stages:
- deploy
- automation
- chatops
- green-master-build-trigger
cache: &global-cache
key: "ruby-25"
......@@ -192,18 +191,18 @@ chatops:
ee-green-master-build-trigger:
<<: *with-bundle
stage: green-master-build-trigger
stage: automation
script:
- bundle exec rake green_master:ee[true]
- bundle exec rake passing_build:ee[master, true]
only:
variables:
- $EE_GREEN_MASTER_BUILD_TRIGGER == "true"
ce-green-master-build-trigger:
<<: *with-bundle
stage: green-master-build-trigger
stage: automation
script:
- bundle exec rake green_master:ce[true]
- bundle exec rake passing_build:ce[master, true]
only:
variables:
- $CE_GREEN_MASTER_BUILD_TRIGGER == "true"
......@@ -119,55 +119,27 @@ to verify changes in a release.
Tag the specified version as a security release.
## `green_master:<ee|ce|all>[trigger_build]`
## `passing_build:<ee|ce|all>[ref, trigger_build]`
This task will show us the selected `sha` associated with the latest `master`
branch that had a successful pipeline run. When `trigger_build` is `true`, it
will send the signal to `omnibus-gitlab` to start that build.
This task will show us the SHA from `ref` that had a successful pipeline run
_and exists on dev.gitlab.org_.
When running `green_master:all`, it will run both the CE and EE builds
When `trigger_build` is `true`, it will send the signal to `omnibus-gitlab` to
start that build.
When running `passing_build:all`, it will run both the CE and EE builds
synchronously. Keep this in mind if on a time constraint.
### Examples
```sh
# Informational gathering only
% bundle exec rake green_master:ee
Found EE Green Master at 50b5b74315b8e8c440305d48cc8d26c3ef843bf4
% bundle exec rake green_master:ce
Found CE Green Master at 5ff775fdef99eeec1f25bea7baf5480fa402f714
% bundle exec rake green_master:all[true]
Found EE Green Master at 50b5b74315b8e8c440305d48cc8d26c3ef843bf4
Found CE Green Master at 5ff775fdef99eeec1f25bea7baf5480fa402f714
# Actually triggers a build (Example output)
% bundle exec rake green_master:ee[true]
Found EE Green Master at 50b5b74315b8e8c440305d48cc8d26c3ef843bf4
trigger build: 50b5b74315b8e8c440305d48cc8d26c3ef843bf4 for Project::GitlabCe
Pipeline triggered: https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/205527
...........................................
Pipeline succeeded in 43 minutes.
% bundle exec rake green_master:ce[true]
Found CE Green Master at 5ff775fdef99eeec1f25bea7baf5480fa402f714
trigger build: 5ff775fdef99eeec1f25bea7baf5480fa402f714 for Project::GitlabCe
Pipeline triggered: https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/205528
...........................................
Pipeline succeeded in 43 minutes.
% bundle exec rake green_master:all[true]
Found EE Green Master at 50b5b74315b8e8c440305d48cc8d26c3ef843bf4
trigger build: 50b5b74315b8e8c440305d48cc8d26c3ef843bf4 for Project::GitlabCe
Pipeline triggered: https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/205527
...........................................
Pipeline succeeded in 43 minutes.
Found CE Green Master at 5ff775fdef99eeec1f25bea7baf5480fa402f714
trigger build: 5ff775fdef99eeec1f25bea7baf5480fa402f714 for Project::GitlabCe
Pipeline triggered: https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/205528
...........................................
Pipeline succeeded in 43 minutes.
# Information gathering only
% bundle exec rake 'passing_build:ce'
% bundle exec rake 'passing_build:all[11-10-stable]'
# Trigger a build
% bundle exec rake 'passing_build:ee[master, true]'
% bundle exec rake 'passing_build:all[11-10-stable, true]'
```
## `publish[version]`
......
......@@ -52,7 +52,6 @@ require 'release_tools/component_versions'
require 'release_tools/gitlab_client'
require 'release_tools/gitlab_dev_client'
require 'release_tools/gitlab_ops_client'
require 'release_tools/green_master'
require 'release_tools/helm/chart_file'
require 'release_tools/helm/version_manager'
require 'release_tools/helm_chart_version'
......@@ -64,6 +63,7 @@ require 'release_tools/merge_request'
require 'release_tools/monthly_issue'
require 'release_tools/omnibus_gitlab_version'
require 'release_tools/packages/publish_service'
require 'release_tools/passing_build'
require 'release_tools/patch_issue'
require 'release_tools/pipeline'
require 'release_tools/pick_into_label'
......
......@@ -18,14 +18,14 @@ module ReleaseTools
# Find a commit with a passing build on production that also exists on dev
def latest_dev_green_build_commit
commit_list.each do |commit|
commit_list.detect do |commit|
next unless success?(commit)
begin
# Hit the dev API with the specified commit to see if it even exists
return ReleaseTools::GitlabDevClient.commit(project, ref: commit.id)
ReleaseTools::GitlabDevClient.commit(project, ref: commit.id)
rescue Gitlab::Error::Error
next
false
end
end
end
......
# frozen_string_literal: true
module ReleaseTools
class GreenMaster
attr_reader :project
class PassingBuild
attr_reader :project, :ref
def initialize(project)
def initialize(project, ref)
@project = project
@ref = ref
end
def execute(args)
commit = ReleaseTools::Commits.new(project, ref: 'master')
commit = ReleaseTools::Commits.new(project, ref: ref)
.latest_dev_green_build_commit
raise "Unable to find a passing build for `master` on dev" if commit.nil?
if commit.nil?
raise "Unable to find a passing #{project} build for `#{ref}` on dev"
end
$stdout.puts "Found #{project} green master at #{commit.id}"
$stdout.puts "Found at #{commit.id}".indent(4)
versions = ReleaseTools::ComponentVersions.get(project, commit)
versions.each do |component, version|
$stdout.puts "#{component}: #{version}".indent(2)
$stdout.puts "#{component}: #{version}".indent(6)
end
trigger_build(commit, versions) if args.trigger_build
......
# frozen_string_literal: true
namespace :green_master do
desc "Find and optionally trigger a green master build for EE"
task :ee, [:trigger_build] do |_t, args|
ReleaseTools::GreenMaster
.new(ReleaseTools::Project::GitlabEe)
.execute(args)
end
desc "Find and optionally trigger a green master build for CE"
task :ce, [:trigger_build] do |_t, args|
ReleaseTools::GreenMaster
.new(ReleaseTools::Project::GitlabCe)
.execute(args)
end
desc "Trigger a green master build for both CE and EE"
task :all, [:trigger_build] do |_t, args|
Rake::Task['green_master:ee'].invoke(args.trigger_build)
Rake::Task['green_master:ce'].invoke(args.trigger_build)
end
end
# frozen_string_literal: true
namespace :passing_build do
def passing_build(project, ref)
$stdout.print '--> '.colorize(:green)
$stdout.puts "Searching for passing build on #{project}@#{ref}..."
ReleaseTools::PassingBuild.new(project, ref)
end
desc "Find and optionally trigger a green master build for EE"
task :ee, [:ref, :trigger_build] do |_t, args|
ref = args.fetch(:ref, 'master').dup
# HACK: Allow `X-Y-stable` as an argument for both tasks, except master
ref << '-ee' unless ref == 'master'
passing_build(ReleaseTools::Project::GitlabEe, ref).execute(args)
passing_build(ReleaseTools::Project::OmnibusGitlab, ref).execute(args)
end
desc "Find and optionally trigger a green master build for CE"
task :ce, [:ref, :trigger_build] do |_t, args|
ref = args.fetch(:ref, 'master').dup
passing_build(ReleaseTools::Project::GitlabCe, ref).execute(args)
passing_build(ReleaseTools::Project::OmnibusGitlab, ref).execute(args)
end
desc "Trigger a green master build for both CE and EE"
task :all, [:ref, :trigger_build] do |_t, args|
Rake::Task['passing_build:ee'].invoke(*args)
Rake::Task['passing_build:ce'].invoke(*args)
end
end
......@@ -31,14 +31,14 @@ describe ReleaseTools::Commits do
describe '#latest_dev_green_build_commit' do
it 'handles a missing commit on dev' do
expect(ReleaseTools::GitlabDevClient)
allow(ReleaseTools::GitlabDevClient)
.to receive(:commit)
.and_raise(api_error(Gitlab::Error::NotFound, 'foo'))
instance = described_class.new(project)
VCR.use_cassette('commits/list') do
expect { instance.latest_dev_green_build_commit }.not_to raise_error
expect(instance.latest_dev_green_build_commit).to be_nil
end
end
......@@ -50,7 +50,7 @@ describe ReleaseTools::Commits do
instance = described_class.new(project)
VCR.use_cassette('commits/list') do
expect(instance.latest_dev_green_build_commit).to eq 'foo'
expect(instance.latest_dev_green_build_commit).not_to be_nil
end
end
end
......
......@@ -2,11 +2,11 @@
require 'spec_helper'
describe ReleaseTools::GreenMaster do
describe ReleaseTools::PassingBuild do
let(:project) { ReleaseTools::Project::GitlabCe }
let(:fake_commit) { double('Commit', id: '1234') }
subject(:service) { described_class.new(project) }
subject(:service) { described_class.new(project, 'master') }
describe '#execute' do
let(:fake_commits) { spy }
......@@ -20,7 +20,7 @@ describe ReleaseTools::GreenMaster do
.and_return(nil)
expect { service.execute(nil) }
.to raise_error(/Unable to find a passing build/)
.to raise_error(/Unable to find a passing/)
end
it 'fetches component versions', :silence_stdout do
......
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