Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve release scripts #6999

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 40 additions & 21 deletions tool/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,15 @@ def prepare!
system("git", "push", "origin", @stable_branch, exception: true)
end

system("git", "checkout", "-b", @release_branch, @stable_branch, exception: true)
create_if_not_exist_and_switch_to(@release_branch, from: @stable_branch)

begin
@bundler.set_relevant_pull_requests_from(unreleased_pull_requests)
@rubygems.set_relevant_pull_requests_from(unreleased_pull_requests)

cherry_pick_pull_requests if @level == :patch

@bundler.cut_changelog!
system("git", "commit", "-am", "Changelog for Bundler version #{@bundler.version}", exception: true)
bundler_changelog = `git show --no-patch --pretty=format:%h`

@bundler.bump_versions!
system("rake", "update_locked_bundler", exception: true)
system("git", "commit", "-am", "Bump Bundler version to #{@bundler.version}", exception: true)

@rubygems.cut_changelog!
system("git", "commit", "-am", "Changelog for Rubygems version #{@rubygems.version}", exception: true)
rubygems_changelog = `git show --no-patch --pretty=format:%h`

@rubygems.bump_versions!
system("git", "commit", "-am", "Bump Rubygems version to #{@rubygems.version}", exception: true)
bundler_changelog, rubygems_changelog = cut_changelogs_and_bump_versions

system("git", "push", exception: true)

Expand All @@ -204,14 +191,13 @@ def prepare!
"It's release day!"
)

system("git", "checkout", "-b", "cherry_pick_changelogs", "master", exception: true)
create_if_not_exist_and_switch_to("cherry_pick_changelogs", from: "master")

begin
system("git", "cherry-pick", bundler_changelog, rubygems_changelog, exception: true)
system("git", "push", exception: true)
rescue StandardError
system("git", "cherry-pick", "--abort")
system("git", "branch", "-D", "cherry_pick_changelogs")
else
gh_client.create_pull_request(
"rubygems/rubygems",
Expand All @@ -223,21 +209,29 @@ def prepare!
end
rescue StandardError
system("git", "checkout", initial_branch)
system("git", "branch", "-D", @release_branch)
raise
end
end

def create_if_not_exist_and_switch_to(branch, from:)
system("git", "checkout", branch, exception: true, err: IO::NULL)
rescue StandardError
system("git", "checkout", "-b", branch, from, exception: true)
end

def cherry_pick_pull_requests
prs = relevant_unreleased_pull_requests
raise "No unreleased PRs were found. Make sure to tag them with appropriate labels so that they are selected for backport." unless prs.any?

puts "The following unreleased prs were found:\n#{prs.map {|pr| "* #{pr.url}" }.join("\n")}"

if prs.any? && !system("git", "cherry-pick", "-x", "-m", "1", *prs.map(&:merge_commit_sha))
unless system("git", "cherry-pick", "-x", "-m", "1", *prs.map(&:merge_commit_sha))
warn <<~MSG

Opening a new shell to fix the cherry-pick errors manually. You can do the following now:

* Find the PR that caused the merge conflict.
* If you'd like to include that PR in the release, tag it with an appropriate label. Then type `Ctrl-D` and rerun the task so that the PR is cherry-picked before and the conflict is fixed.
* If you'd like to include that PR in the release, tag it with an appropriate label. Then type `exit 1` and rerun the task so that the PR is cherry-picked before and the conflict is fixed.
* If you don't want to include that PR in the release, fix conflicts manually, run `git add . && git cherry-pick --continue` once done, and if it succeeds, run `exit 0` to resume the release preparation.

MSG
Expand All @@ -249,6 +243,31 @@ def cherry_pick_pull_requests
end
end

def cut_changelogs_and_bump_versions
system("git", "branch", "#{@release_branch}-bkp")

@bundler.cut_changelog!
system("git", "commit", "-am", "Changelog for Bundler version #{@bundler.version}", exception: true)
bundler_changelog = `git show --no-patch --pretty=format:%h`

@bundler.bump_versions!
system("rake", "update_locked_bundler", exception: true)
system("git", "commit", "-am", "Bump Bundler version to #{@bundler.version}", exception: true)

@rubygems.cut_changelog!
system("git", "commit", "-am", "Changelog for Rubygems version #{@rubygems.version}", exception: true)
rubygems_changelog = `git show --no-patch --pretty=format:%h`

@rubygems.bump_versions!
system("git", "commit", "-am", "Bump Rubygems version to #{@rubygems.version}", exception: true)

[bundler_changelog, rubygems_changelog]
rescue StandardError
system("git", "reset", "--hard", "#{@release_branch}-bkp")
ensure
system("git", "branch", "-D", "#{@release_branch}-bkp")
end

def cut_changelog!
@current_library.cut_changelog_for!(unreleased_pull_requests)
end
Expand All @@ -260,7 +279,7 @@ def create_for_github!
private

def relevant_unreleased_pull_requests
(@bundler.relevant_pull_requests + @rubygems.relevant_pull_requests).sort_by(&:merged_at)
(@bundler.relevant_pull_requests + @rubygems.relevant_pull_requests).uniq.sort_by(&:merged_at)
end

def unreleased_pull_requests
Expand Down