Rakefile 6.03 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require_relative 'lib/release_tools'
require_relative 'lib/release_tools/support/tasks_helper'
5

6
Dir.glob('lib/tasks/*.rake').each { |task| import(task) }
7

John Jarvis's avatar
John Jarvis committed
8
namespace :auto_deploy do
John Jarvis's avatar
John Jarvis committed
9 10
  desc "Prepare for auto-deploy by creating branches from the latest green commit on gitlab-ee and omnibus-gitlab"
  task :prepare do
11 12 13
    ReleaseTools::Services::AutoDeployBranchService
      .new(ReleaseTools::AutoDeploy::Naming.branch)
      .create_branches!
14
  end
John Skarbek's avatar
John Skarbek committed
15 16 17

  desc 'Pick commits into the auto deploy branches'
  task :pick do
John Skarbek's avatar
John Skarbek committed
18 19
    icon = ->(result) { result.success? ? "✓" : "✗" }

20 21 22
    auto_deploy_branch = ENV.fetch('AUTO_DEPLOY_BRANCH') do |name|
      abort("`#{name}` must be set for this rake task".colorize(:red))
    end
23

24 25
    version = auto_deploy_branch.sub(/\A(\d+)-(\d+)-auto-deploy.*/, '\1.\2')
    version = ReleaseTools::Version.new(version).to_ee
26

John Skarbek's avatar
John Skarbek committed
27
    target_branch = ReleaseTools::AutoDeployBranch.new(version, auto_deploy_branch)
28 29

    $stdout.puts "--> Picking for #{version}..."
John Skarbek's avatar
John Skarbek committed
30
    ee_results = ReleaseTools::CherryPick::Service
John Skarbek's avatar
John Skarbek committed
31
      .new(ReleaseTools::Project::GitlabEe, version, target_branch)
John Skarbek's avatar
John Skarbek committed
32
      .execute
John Skarbek's avatar
John Skarbek committed
33

John Skarbek's avatar
John Skarbek committed
34
    ee_results.each do |result|
35
      $stdout.puts "#{icon.call(result)} #{result.url}".indent(4)
John Skarbek's avatar
John Skarbek committed
36
    end
John Skarbek's avatar
John Skarbek committed
37

38 39
    version = version.to_ce
    $stdout.puts "--> Picking for #{version}..."
John Skarbek's avatar
John Skarbek committed
40
    ce_results = ReleaseTools::CherryPick::Service
John Skarbek's avatar
John Skarbek committed
41
      .new(ReleaseTools::Project::GitlabCe, version, target_branch)
John Skarbek's avatar
John Skarbek committed
42
      .execute
John Skarbek's avatar
John Skarbek committed
43

44
    ce_results.each do |result|
45
      $stdout.puts "#{icon.call(result)} #{result.url}".indent(4)
John Skarbek's avatar
John Skarbek committed
46
    end
47

48 49 50
    return if ReleaseTools::SharedStatus.dry_run?

    if ee_results.any?(&:success?) || ce_results.any?(&:success?)
51 52 53
      $stdout.puts "--> Triggering merge train for `#{auto_deploy_branch}`"

      pipeline = ReleaseTools::GitlabOpsClient.run_trigger(
54 55 56 57 58 59 60 61 62
        ReleaseTools::Project::MergeTrain,
        ENV.fetch('MERGE_TRAIN_TRIGGER_TOKEN'),
        'master',
        {
          CE_BRANCH: auto_deploy_branch,
          EE_BRANCH: auto_deploy_branch,
          MERGE_MANUAL: '1'
        }
      )
63 64

      $stdout.puts pipeline.web_url.indent(4)
John Skarbek's avatar
John Skarbek committed
65
    end
John Skarbek's avatar
John Skarbek committed
66
  end
67 68
end

69 70
desc "Sync master branch in remotes"
task :sync do
71
  if skip?('ee')
72
    $stdout.puts 'Skipping sync for EE'.colorize(:yellow)
73
  else
74
    ReleaseTools::Sync.new(ReleaseTools::Project::GitlabEe.remotes).execute
75
  end
76

77
  if skip?('ce')
78
    $stdout.puts 'Skipping sync for CE'.colorize(:yellow)
79
  else
80
    ReleaseTools::Sync.new(ReleaseTools::Project::GitlabCe.remotes).execute
81 82
  end

83
  if skip?('og')
84
    $stdout.puts 'Skipping sync for Omnibus Gitlab'.colorize(:yellow)
85
  else
86
    ReleaseTools::Sync.new(ReleaseTools::Project::OmnibusGitlab.remotes).execute
87 88 89
  end
end

90
# Undocumented; executed via CI schedule
91
task :close_expired_qa_issues do
92
  ReleaseTools::Qa::IssueCloser.new.execute
93 94
end

95
# Undocumented; executed via CI schedule
96
task :upstream_merge do
97
  result = ReleaseTools::Services::UpstreamMergeService
98 99
    .new(dry_run: dry_run?, mention_people: !no_mention?, force: force?)
    .perform
100 101 102

  if result.success?
    upstream_mr = result.payload[:upstream_mr]
103 104 105 106 107
    if upstream_mr.exists?
      $stdout.puts <<~SUCCESS_MESSAGE.colorize(:green)
        --> Merge request "#{upstream_mr.title}" created.
            #{upstream_mr.url}
      SUCCESS_MESSAGE
108
      ReleaseTools::Slack::UpstreamMergeNotification.new_merge_request(upstream_mr) unless dry_run?
109 110 111 112
    else
      $stdout.puts <<~SUCCESS_MESSAGE.colorize(:yellow)
        --> Merge request "#{upstream_mr.title}" not created.
      SUCCESS_MESSAGE
113
      ReleaseTools::Slack::UpstreamMergeNotification.missing_merge_request unless dry_run?
114
    end
115 116
  elsif result.payload[:in_progress_mr]
    in_progress_mr = result.payload[:in_progress_mr]
117 118
    $stdout.puts <<~ERROR_MESSAGE.colorize(:red)
    --> An upstream merge request already exists.
119
        #{in_progress_mr.url}
120
    ERROR_MESSAGE
121
    ReleaseTools::Slack::UpstreamMergeNotification.existing_merge_request(in_progress_mr) unless dry_run?
122 123 124 125
  elsif result.payload[:already_up_to_date]
    $stdout.puts <<~ERROR_MESSAGE.colorize(:green)
    --> EE is already up-to-date with CE. No merge request was created.
    ERROR_MESSAGE
126
    ReleaseTools::Slack::UpstreamMergeNotification.downstream_is_up_to_date unless dry_run?
127 128
  end
end
129

130 131
namespace :helm do
  desc "Create a chart release by passing in chart_version,gitlab_version"
DJ Mountney's avatar
DJ Mountney committed
132
  task :tag_chart, [:version, :gitlab_version] do |_t, args|
133 134
    version = ReleaseTools::HelmChartVersion.new(args[:version]) if args[:version] && !args[:version].empty?
    gitlab_version = ReleaseTools::HelmGitlabVersion.new(args[:gitlab_version]) if args[:gitlab_version] && !args[:gitlab_version].empty?
DJ Mountney's avatar
DJ Mountney committed
135 136 137

    # At least one of the versions must be provided in order to tag
    if (!version && !gitlab_version) || (version && !version.valid?) || (gitlab_version && !gitlab_version.valid?)
138 139 140 141 142
      $stdout.puts "Version number must be in the following format: X.Y.Z".colorize(:red)
      exit 1
    end

    $stdout.puts 'Chart release'.colorize(:blue)
143
    ReleaseTools::Release::HelmGitlabRelease.new(version, gitlab_version).execute
144 145
  end
end
146 147 148 149 150

desc "Publish packages for a specified version"
task :publish, [:version] do |_t, args|
  version = get_version(args)

151
  ReleaseTools::Packages::PublishService
152 153
    .new(version)
    .execute
154 155

  # Tag the Helm chart
156 157 158
  begin
    Rake::Task['helm:tag_chart'].invoke(nil, version.to_ce)
  rescue StandardError => ex
159
    Raven.capture_exception(ex)
160
  end
161
end
162

163
# Undocumented; executed via CI schedule
164 165 166 167 168 169 170 171 172
task :freeze do
  require 'httparty'
  require 'json'

  webhook_url = ENV.fetch('FEATURE_FREEZE_WEBHOOK_URL')

  # We don't wrap this string so the sentences appear on a single line in Slack,
  # instead of being spread across separate lines.
  message = <<~MESSAGE.strip
173
    <!channel>
174

175 176 177 178 179 180 181
    The feature freeze is now active. This means that no new features will be merged into the stable branches for this month's release.

    For more information, refer to <https://gitlab.com/gitlab-org/gitlab-ce/blob/master/PROCESS.md#after-the-7th|"After the 7th">.
  MESSAGE

  HTTParty.post(webhook_url, body: { payload: JSON.dump(text: message) })
end