Class: Homebrew::DevCmd::Release Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/release.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/release.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Release::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/release.rbi', line 10

def args; end

#runvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'dev-cmd/release.rb', line 30

def run
  safe_system "git", "-C", HOMEBREW_REPOSITORY, "fetch", "origin" if Homebrew::EnvConfig.no_auto_update?

  require "utils/github"

  begin
    latest_release = GitHub.get_latest_release "Homebrew", "brew"
  rescue GitHub::API::HTTPNotFoundError
    odie "No existing releases found!"
  end
  latest_version = Version.new latest_release["tag_name"]

  if args.major? || args.minor?
    one_month_ago = Date.today << 1
    latest_major_minor_release = begin
      GitHub.get_release "Homebrew", "brew", "#{latest_version.major_minor}.0"
    rescue GitHub::API::HTTPNotFoundError
      nil
    end

    if latest_major_minor_release.blank?
      opoo "Unable to determine the release date of the latest major/minor release."
    elsif Date.parse(latest_major_minor_release["published_at"]) > one_month_ago
      odie "The latest major/minor release was less than one month ago."
    end
  end

  new_version = if args.major?
    Version.new "#{latest_version.major.to_i + 1}.0.0"
  elsif args.minor?
    Version.new "#{latest_version.major}.#{latest_version.minor.to_i + 1}.0"
  else
    Version.new "#{latest_version.major}.#{latest_version.minor}.#{latest_version.patch.to_i + 1}"
  end.to_s

  if args.major? || args.minor?
    latest_major_minor_version = "#{latest_version.major}.#{latest_version.minor.to_i}.0"
    ohai "Release notes since #{latest_major_minor_version} for #{new_version} blog post:"
    # release notes without usernames, new contributors, or extra lines
    blog_post_notes = GitHub.generate_release_notes("Homebrew", "brew", new_version,
                                                    previous_tag: latest_major_minor_version)["body"]
    blog_post_notes = blog_post_notes.lines.filter_map do |line|
      next unless (match = line.match(/^\* (.*) by @[\w-]+ in (.*)$/))

      "- [#{match[1]}](#{match[2]})"
    end.sort
    puts blog_post_notes
  end

  ohai "Creating draft release for version #{new_version}"

  release_notes = if args.major? || args.minor?
    "Release notes for this release can be found on the [Homebrew blog](https://brew.sh/blog/#{new_version}).\n"
  else
    ""
  end
  release_notes += GitHub.generate_release_notes("Homebrew", "brew", new_version,
                                                 previous_tag: latest_version)["body"]

  begin
    release = GitHub.create_or_update_release "Homebrew", "brew", new_version, body: release_notes, draft: true
  rescue *GitHub::API::ERRORS => e
    odie "Unable to create release: #{e.message}!"
  end

  puts release["html_url"]
  exec_browser release["html_url"]
end