-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10370 from Rylan12/brew-release
Add brew release command
- Loading branch information
Showing
13 changed files
with
242 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "cli/parser" | ||
require "release_notes" | ||
|
||
module Homebrew | ||
extend T::Sig | ||
|
||
module_function | ||
|
||
sig { returns(CLI::Parser) } | ||
def release_args | ||
Homebrew::CLI::Parser.new do | ||
description <<~EOS | ||
Create a new draft Homebrew/brew release with the appropriate version number and release notes. | ||
By default, `brew release` will bump the patch version number. Pass | ||
`--major` or `--minor` to bump the major or minor version numbers, respectively. | ||
The command will fail if the previous major or minor release was made less than | ||
one month ago. | ||
Requires write access to the Homebrew/brew repository. | ||
EOS | ||
switch "--major", | ||
description: "Create a major release." | ||
switch "--minor", | ||
description: "Create a minor release." | ||
conflicts "--major", "--minor" | ||
|
||
named_args :none | ||
end | ||
end | ||
|
||
def release | ||
args = release_args.parse | ||
|
||
safe_system "git", "-C", HOMEBREW_REPOSITORY, "fetch", "origin" if Homebrew::EnvConfig.no_auto_update? | ||
|
||
begin | ||
latest_release = GitHub.get_latest_release "Homebrew", "brew" | ||
rescue GitHub::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::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 | ||
|
||
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 += ReleaseNotes.generate_release_notes latest_version, "origin/HEAD", markdown: true | ||
|
||
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 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
# Helper functions for generating release notes. | ||
# | ||
# @api private | ||
module ReleaseNotes | ||
extend T::Sig | ||
|
||
module_function | ||
|
||
sig { | ||
params(start_ref: T.any(String, Version), end_ref: T.any(String, Version), markdown: T.nilable(T::Boolean)) | ||
.returns(String) | ||
} | ||
def generate_release_notes(start_ref, end_ref, markdown: false) | ||
log_output = Utils.popen_read( | ||
"git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{start_ref}..#{end_ref}" | ||
).lines.grep(/Merge pull request/) | ||
|
||
log_output.map! do |s| | ||
s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*}, | ||
"https://github.com/Homebrew/brew/pull/\\1 (@\\2)") | ||
end | ||
|
||
if markdown | ||
log_output.map! do |s| | ||
/(.*\d)+ \(@(.+)\) - (.*)/ =~ s | ||
"- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})\n" | ||
end | ||
end | ||
|
||
log_output.join | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "cmd/shared_examples/args_parse" | ||
|
||
describe "Homebrew.release_args" do | ||
it_behaves_like "parseable arguments" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "release_notes" | ||
|
||
describe ReleaseNotes do | ||
before do | ||
HOMEBREW_REPOSITORY.cd do | ||
system "git", "init" | ||
system "git", "commit", "--allow-empty", "-m", "Initial commit" | ||
system "git", "tag", "release-notes-testing" | ||
system "git", "commit", "--allow-empty", "-m", "Merge pull request #1 from Homebrew/fix", "-m", "Do something" | ||
system "git", "commit", "--allow-empty", "-m", "make a change" | ||
system "git", "commit", "--allow-empty", "-m", "Merge pull request #2 from User/fix", "-m", "Do something else" | ||
end | ||
end | ||
|
||
describe ".generate_release_notes" do | ||
it "generates release notes" do | ||
expect(described_class.generate_release_notes("release-notes-testing", "HEAD")).to eq <<~NOTES | ||
https://github.com/Homebrew/brew/pull/2 (@User) - Do something else | ||
https://github.com/Homebrew/brew/pull/1 (@Homebrew) - Do something | ||
NOTES | ||
end | ||
|
||
it "generates markdown release notes" do | ||
expect(described_class.generate_release_notes("release-notes-testing", "HEAD", markdown: true)).to eq <<~NOTES | ||
- [Do something else](https://github.com/Homebrew/brew/pull/2) (@User) | ||
- [Do something](https://github.com/Homebrew/brew/pull/1) (@Homebrew) | ||
NOTES | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ pr-upload | |
prof | ||
readall | ||
reinstall | ||
release | ||
release-notes | ||
remove | ||
rm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters