Skip to content

Commit

Permalink
Consolidate backmerge methods and move annotation there
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Sep 25, 2024
1 parent 3ca555b commit e103a9c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 71 deletions.
1 change: 1 addition & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ VERSION_FILE = Fastlane::Wpmreleasetoolkit::Versioning::AndroidVersionFile.new(v
import 'lanes/build.rb'
import 'lanes/localization.rb'
import 'lanes/release.rb'
import 'lib/release_helpers.rb'

platform :android do
ENV['PROJECT_ROOT_FOLDER'] = "#{File.dirname(File.expand_path(__dir__))}/"
Expand Down
39 changes: 3 additions & 36 deletions fastlane/lanes/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Lanes related to the Release Process (Code Freeze, Betas, Final Build, App Store Submission…)

require_relative '../lib/release_helpers'

platform :android do
desc 'Creates a new release branch from the current default branch'
lane :start_code_freeze do |skip_prechecks: false, skip_confirm: false|
Expand Down Expand Up @@ -110,13 +108,7 @@

trigger_beta_build(branch_to_build: release_branch_name(release_version: version))

pr_url = create_backmerge_pr!

message = <<~MESSAGE
Code freeze completed successfully. Next, review and merge the [integration PR](#{pr_url}).
MESSAGE
buildkite_annotate(context: 'code-freeze-completed', style: 'success', message: message) if is_ci
UI.success(message)
create_backmerge_prs!
end

desc 'Updates store metadata and runs the release checks'
Expand Down Expand Up @@ -155,13 +147,7 @@

build_and_upload_release(create_release: true)

pr_url = create_backmerge_pr!

message = <<~MESSAGE
Release finalized successfully. Next, review and merge the [integration PR](#{pr_url}).
MESSAGE
buildkite_annotate(context: 'finalize-release-completed', style: 'success', message: message) if is_ci
UI.success(message)
create_backmerge_prs!

UI.message('Attempting to remove release branch protection in GitHub...')

Expand Down Expand Up @@ -206,26 +192,7 @@
name: version_number
)

pr_urls = create_backmerge_prs!

# It's possible that no backmerge was created when:
#
# - there are no hotfixes in development and the next release code freeze has not been started
# - nothing changes in the current release branch since release finalization
#
# As a matter of fact, in the context of Simplenote Android, the above is the most likely scenario.
style, message = if pr_urls.empty?
['info', 'No backmerge PR was required']
else
[
'success', <<~MESSAGE
The following backmerge PR#{pr_urls.length > 1 ? '(s) were' : ' was'} created:
#{pr_urls.map { |url| "- #{url}" }}
MESSAGE
]
end
buildkite_annotate(style: style, context: 'backmerge-prs-outcome', message: message) if is_ci
UI.success(message)
create_backmerge_prs!

# At this point, an intermediate branch has been created by creating a backmerge PR to a hotfix or the next version release branch.
# This allows us to safely delete the `release/*` branch.
Expand Down
83 changes: 48 additions & 35 deletions fastlane/lib/release_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
# frozen_string_literal: true

def create_backmerge_pr!
pr_urls = create_backmerge_prs!

return pr_urls unless pr_urls.length > 1

backmerge_error_message = UI.user_error! <<~ERROR
Unexpectedly opened more than one backmerge pull request. URLs:
#{pr_urls.map { |url| "- #{url}" }.join("\n")}
ERROR
buildkite_annotate(style: 'error', context: 'error-creating-backmerge', message: backmerge_error_message) if is_ci
UI.user_error!(backmerge_error_message)
end

# Notice the plural in the name.
# The action this method calls may create multiple backmerge PRs, depending on how many release branches with version greater than the source are in the remote.
def create_backmerge_prs!
version = release_version_current

create_release_backmerge_pull_request(
repository: GITHUB_REPO,
source_branch: release_branch_name(release_version: version),
labels: ['Releases'],
milestone_title: release_version_next
)
rescue StandardError => e
error_message = <<-MESSAGE
Error creating backmerge pull request(s):
#{e.message}
If this is not the first time you are running the release task, the backmerge PR(s) for the version `#{version}` might have already been previously created.
Please close any pre-existing backmerge PR for `#{version}`, delete the previous merge branch, then run the release task again.
MESSAGE

buildkite_annotate(style: 'error', context: 'error-creating-backmerge', message: error_message) if is_ci

UI.user_error!(error_message)
def create_backmerge_prs!(
version: release_version_current,
source_branch: release_branch_name(release_version: version),
labels: ['Releases'],
milestone_title: release_version_next
)
begin
pr_urls = create_release_backmerge_pull_request(
repository: GITHUB_REPO,
source_branch: source_branch,
labels: labels,
milestone_title: milestone_title
)
rescue StandardError => e
error_message = <<~MESSAGE
Error creating backmerge pull request(s):
#{e.message}
If this is not the first time you are running the release task, the backmerge PR(s) for the version `#{version}` might have already been previously created.
Please close any pre-existing backmerge PR for `#{version}`, delete the previous merge branch, then run the release task again.
MESSAGE

buildkite_annotate(style: 'error', context: 'error-creating-backmerge', message: error_message) if is_ci

UI.user_error!(error_message)
end

# It's possible that no backmerge was created when:
#
# - there are no hotfixes in development and the next release code freeze has not been started
# - nothing changes in the current release branch since release finalization
#
# As a matter of fact, in the context of Simplenote Android, the above is the most likely scenario.
style, message = if pr_urls.empty?
['info', 'No backmerge PR was required.']
else
[
'success', <<~MESSAGE
The following backmerge PR#{pr_urls.length > 1 ? '(s) were' : ' was'} created:
#{pr_urls.map { |url| "- #{url}" }.join("\n")}
MESSAGE
]
end
buildkite_annotate(style: style, context: 'backmerge-prs-outcome', message: message) if is_ci
UI.success(message)

pr_urls
end

0 comments on commit e103a9c

Please sign in to comment.