Rakefile 5.72 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

8

9
def deprecate_as(new_task, old_task, args)
10 11 12
  warn "This task has been deprecated in favor of " \
    "`#{new_task.colorize(:green)}` and will soon be removed."

13 14 15 16 17 18
  Raven.capture_message(
    "Use of deprecated task #{old_task.name}",
    extra: args,
    level: 'info'
  )

19 20 21
  Rake::Task[new_task].invoke(*args)
end

John Jarvis's avatar
John Jarvis committed
22
namespace :auto_deploy do
John Jarvis's avatar
John Jarvis committed
23 24
  desc "Prepare for auto-deploy by creating branches from the latest green commit on gitlab-ee and omnibus-gitlab"
  task :prepare do
John Jarvis's avatar
John Jarvis committed
25 26
    pipeline_id = ENV['CI_PIPELINE_IID']
    abort('CI_PIPELINE_IID must be set for this rake task'.colorize(:red)) unless pipeline_id
27 28 29 30
    ReleaseTools::Services::AutoDeployBranchService.new(pipeline_id).create_auto_deploy_branches!
  end
end

31 32
task :tag, [:version] do |t, args|
  deprecate_as 'release:tag', t, args
33
end
34

35 36
task :tag_security, [:version] do |t, args|
  deprecate_as 'security:tag', t, args
37 38
end

39 40
desc "Sync master branch in remotes"
task :sync do
41
  if skip?('ee')
42
    $stdout.puts 'Skipping sync for EE'.colorize(:yellow)
43
  else
44
    ReleaseTools::Sync.new(ReleaseTools::Project::GitlabEe.remotes).execute
45
  end
46

47
  if skip?('ce')
48
    $stdout.puts 'Skipping sync for CE'.colorize(:yellow)
49
  else
50
    ReleaseTools::Sync.new(ReleaseTools::Project::GitlabCe.remotes).execute
51 52
  end

53
  if skip?('og')
54
    $stdout.puts 'Skipping sync for Omnibus Gitlab'.colorize(:yellow)
55
  else
56
    ReleaseTools::Sync.new(ReleaseTools::Project::OmnibusGitlab.remotes).execute
57 58 59
  end
end

60 61
task :monthly_issue, [:version] do |t, args|
  deprecate_as 'release:issue', t, args
62 63
end

64 65
task :patch_issue, [:version] do |t, args|
  deprecate_as 'release:issue', t, args
66
end
67

68 69
task :qa_issue, [:from, :to, :version] do |t, args|
  deprecate_as 'release:qa', t, args
70 71
end

72 73
task :security_qa_issue, [:from, :to, :version] do |t, args|
  deprecate_as 'security:qa', t, args
74 75
end

76
# Undocumented; executed via CI schedule
77
task :close_expired_qa_issues do
78
  ReleaseTools::Qa::IssueCloser.new.execute
79 80
end

81 82
task :patch_merge_request, [:version] do |t, args|
  deprecate_as 'release:prepare', t, args
83 84
end

85 86
task :cherry_pick, [:version] do |t, args|
  deprecate_as 'release:merge', t, args
87 88
end

89 90
task :security_cherry_pick, [:version] do |t, args|
  deprecate_as 'security:merge', t, args
91 92
end

93 94
task :security_patch_issue, [:version] do |t, args|
  deprecate_as 'security:issue', t, args
95
end
96

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

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

132 133
namespace :helm do
  desc "Create a chart release by passing in chart_version,gitlab_version"
DJ Mountney's avatar
DJ Mountney committed
134
  task :tag_chart, [:version, :gitlab_version] do |_t, args|
135 136
    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
137 138 139

    # 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?)
140 141 142 143 144
      $stdout.puts "Version number must be in the following format: X.Y.Z".colorize(:red)
      exit 1
    end

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

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

153
  ReleaseTools::Packages::PublishService
154 155
    .new(version)
    .execute
156 157

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

165
# Undocumented; executed via CI schedule
166 167 168 169 170 171 172 173 174
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
175
    <!channel>
176

177 178 179 180 181 182 183
    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