Welcome to mirror list, hosted at ThFree Co, Russian Federation.

release.rake « tasks « lib - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6424b1c642238abe2fa730e373a496900910d4fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require './lib/tasks/task_helpers'
require 'fileutils'

task_helpers = TaskHelpers.new

namespace :release do
  desc 'Creates a single release archive'
  task :single, :version do |t, args|
    require "highline/import"
    version = args.version.to_s

    # Disable lefthook because it was causing some PATH errors
    # https://docs.gitlab.com/ee/development/contributing/style_guides.html#disable-lefthook-temporarily
    ENV['LEFTHOOK'] = '0'

    raise 'You need to specify a version, like 10.1' unless version.match?(%r{\A\d+\.\d+\z})

    # Check if local branch exists
    abort("\n#{TaskHelpers::COLOR_CODE_RED}ERROR: Rake aborted! The branch already exists. Delete it with `git branch -D #{version}` and rerun the task.#{TaskHelpers::COLOR_CODE_RESET}") \
      if task_helpers.local_branch_exist?(version)

    # Stash modified and untracked files so we have "clean" environment
    # without accidentally deleting data
    puts "\n#{TaskHelpers::COLOR_CODE_GREEN}INFO: Stashing changes..#{TaskHelpers::COLOR_CODE_RESET}"
    `git stash -u` if task_helpers.git_workdir_dirty?

    # Sync with upstream default branch
    `git checkout #{ENV.fetch('CI_DEFAULT_BRANCH', nil)}`
    `git pull origin #{ENV.fetch('CI_DEFAULT_BRANCH', nil)}`

    # Create branch
    `git checkout -b #{version}`

    # Set version variable in X.Y.Dockerfile
    dockerfile = "#{version}.Dockerfile"

    if File.exist?(dockerfile)
      abort('rake aborted!') if ask("#{dockerfile} already exists. Do you want to overwrite?", %w[y n]) == 'n'
    end

    content = File.read('dockerfiles/single.Dockerfile')
    content.gsub!('ARG VER', "ARG VER=#{version}")

    File.open(dockerfile, 'w') do |post|
      post.puts content
    end

    # Add and commit
    `git add #{version}.Dockerfile`
    `git commit -m 'Release cut #{version}'`

    puts "\n#{TaskHelpers::COLOR_CODE_GREEN}INFO: Created new Dockerfile:#{TaskHelpers::COLOR_CODE_RESET} #{dockerfile}."
    puts "#{TaskHelpers::COLOR_CODE_GREEN}INFO: Pushing the new branch. Don't create a merge request!#{TaskHelpers::COLOR_CODE_RESET}"

    `git push origin #{version}`
  end
end