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

[Tooling] Automate Release Publishing #21239

Open
wants to merge 3 commits into
base: iangmaia/release-on-ci-improvements
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .buildkite/code-freeze.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
---


steps:
- label: "Code Freeze"
plugins: [$CI_TOOLKIT]
Expand Down
3 changes: 1 addition & 2 deletions .buildkite/commands/checkout-release-branch.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash -eu

# RELEASE_VERSION is passed as an environment variable from fastlane to Buildkite
#
# RELEASE_VERSION is passed as an environment variable passed to Buildkite by ReleasesV2.
if [[ -z "${RELEASE_VERSION}" ]]; then
Comment on lines +3 to 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adopted the same approach in Simplenote Android. But I plan to follow it up with a dedicated PR to remove the env read here and make the pipeline pass it when they call the script.

I'm not arguing for it to happen here at this time, but keen to hear what you think of the approach: https://github.com/Automattic/simplenote-android/pull/1695/files#r1766347252

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also make the implementation consistent with the recent changes accessing RELEASE_VERSION in the pipeline command that we made in some iOS projects.

I think this is a good idea. It's an area where we lack some standardization.
Besides, having these scripts relying less on environment variables and having those explicit in the pipelines make things clearer and easier to follow.

echo "RELEASE_VERSION is not set."
exit 1
Expand Down
1 change: 0 additions & 1 deletion .buildkite/complete-code-freeze.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
---


steps:
- label: "Complete Code Freeze"
plugins: [$CI_TOOLKIT]
Expand Down
1 change: 0 additions & 1 deletion .buildkite/finalize-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
---


steps:
- label: "Finalize release"
plugins: [$CI_TOOLKIT]
Expand Down
1 change: 0 additions & 1 deletion .buildkite/new-beta-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
---


steps:
- label: "New Beta Release"
plugins: [$CI_TOOLKIT]
Expand Down
24 changes: 24 additions & 0 deletions .buildkite/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
---

steps:
- label: Publish Release
plugins: [$CI_TOOLKIT]
command: |
echo '--- :robot_face: Use bot for git operations'
source use-bot-for-git

echo '--- :git: Checkout Release Branch'
.buildkite/commands/checkout-release-branch.sh

echo '--- :ruby: Setup Ruby tools'
install_gems

echo '--- :package: Publish Release'
bundle exec fastlane publish_release skip_confirm:true
agents:
queue: tumblr-metal
retry:
manual:
# If those jobs fail, one should always prefer re-triggering a new build from ReleaseV2 rather than retrying the individual job from Buildkite
allowed: false
50 changes: 49 additions & 1 deletion fastlane/lanes/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# @param [Boolean] skip_confirm Whether to skip the confirmation prompt
#
# @example
# bundle exec fastlane code_freeze
# bundle exec fastlane code_freeze skip_confirm:true
#
lane :code_freeze do |skip_confirm: false|
Expand Down Expand Up @@ -344,6 +343,47 @@
end
end

# This lane publishes a release on GitHub and creates a PR to backmerge the current release branch into the next release/ branch
#
# @param [Boolean] skip_confirm (default: false) If set, will skip the confirmation prompt before running the rest of the lane
#
# @example Running the lane
# bundle exec fastlane publish_release skip_confirm:true
#
lane :publish_release do |skip_confirm: false|
ensure_git_status_clean
ensure_git_branch(branch: '^release/')

version_number = current_release_version

current_branch = "release/#{version_number}"
next_release_branch = "release/#{next_release_version}"

UI.important <<~PROMPT
Publish the #{version_number} release. This will:
- Publish the existing draft `#{version_number}` release on GitHub
- Which will also have GitHub create the associated git tag, pointing to the tip of the branch
- If the release branch for the next version `#{next_release_branch}` already exists, backmerge `#{current_branch}` into it
- If needed, backmerge `#{current_branch}` back into `#{DEFAULT_BRANCH}`
- Delete the `#{current_branch}` branch
PROMPT
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')

UI.important "Publishing release #{version_number} on GitHub"

publish_github_release(
repository: GITHUB_REPO,
name: version_number
)

create_backmerge_pr

# 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.
# Note that if a hotfix or new release branches haven't been created, the backmerge PR won't be created as well.
delete_remote_git_branch!(current_branch)
end

lane :check_translations_coverage do |options|
UI.message('Checking WordPress app strings translation status...')
check_translation_progress(
Expand Down Expand Up @@ -570,6 +610,14 @@ def ensure_branch_does_not_exist!(branch_name)
UI.user_error!(error_message)
end

# Delete a branch remotely, after having removed any GitHub branch protection
#
def delete_remote_git_branch!(branch_name)
remove_branch_protection(repository: GITHUB_REPO, branch: branch_name)

Git.open(Dir.pwd).push('origin', branch_name, delete: true)
end

def report_milestone_error(error_title:)
error_message = <<-MESSAGE
#{error_title}
Expand Down
Loading