From 918027ba922db73e3d003bf3f507a881579c7c4b Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 21 Apr 2023 16:26:21 -0400 Subject: [PATCH 1/4] Use git_branch_name_using_HEAD instead of git_branch --- .../actions/android/android_completecodefreeze_prechecks.rb | 6 +++++- .../actions/android/android_finalize_prechecks.rb | 6 +++++- .../actions/ios/ios_completecodefreeze_prechecks.rb | 6 +++++- .../wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb index c40c3fb99..b52c0bb59 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb @@ -7,7 +7,11 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' - UI.user_error!("Current branch - '#{other_action.git_branch}' - is not a release branch. Abort.") unless other_action.git_branch.start_with?('release/') + # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. + # We need to check which branch we are actually on and not the initial branch a CI build is started from. + # See https://docs.fastlane.tools/actions/git_branch/#git_branch + current_branch = Fastlane::Actions.git_branch_name_using_HEAD + UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Android::VersionHelper.get_public_version message = "Completing code freeze for: #{version}\n" diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb index 3b293fef1..9cd4d3ae7 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb @@ -11,7 +11,11 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' - UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/') + # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. + # We need to check which branch we are actually on and not the initial branch a CI build is started from. + # See https://docs.fastlane.tools/actions/git_branch/#git_branch + current_branch = Fastlane::Actions.git_branch_name_using_HEAD + UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Android::VersionHelper.get_public_version message = "Finalizing release: #{version}\n" diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb index f340a8771..584088565 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb @@ -7,7 +7,11 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' - UI.user_error!("Current branch - '#{other_action.git_branch}' - is not a release branch. Abort.") unless other_action.git_branch.start_with?('release/') + # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. + # We need to check which branch we are actually on and not the initial branch a CI build is started from. + # See https://docs.fastlane.tools/actions/git_branch/#git_branch + current_branch = Fastlane::Actions.git_branch_name_using_HEAD + UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Ios::VersionHelper.get_public_version message = "Completing code freeze for: #{version}\n" diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb index dd2de41bf..a39cf2702 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb @@ -7,7 +7,11 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' - UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/') + # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. + # We need to check which branch we are actually on and not the initial branch a CI build is started from. + # See https://docs.fastlane.tools/actions/git_branch/#git_branch + current_branch = Fastlane::Actions.git_branch_name_using_HEAD + UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Ios::VersionHelper.get_public_version message = "Finalizing release: #{version}\n" From 76696048fe0032369fad07d871336a19e4bb0e0e Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 21 Apr 2023 16:38:44 -0400 Subject: [PATCH 2/4] Add a current_git_branch GitHelper --- .../android_completecodefreeze_prechecks.rb | 6 ++---- .../android/android_finalize_prechecks.rb | 6 ++---- .../ios/ios_completecodefreeze_prechecks.rb | 6 ++---- .../actions/ios/ios_finalize_prechecks.rb | 4 +--- .../wpmreleasetoolkit/helper/git_helper.rb | 17 +++++++++++++++++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb index b52c0bb59..7fb673196 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb @@ -6,11 +6,9 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' + require_relative '../../helper/git_helper' - # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. - # We need to check which branch we are actually on and not the initial branch a CI build is started from. - # See https://docs.fastlane.tools/actions/git_branch/#git_branch - current_branch = Fastlane::Actions.git_branch_name_using_HEAD + current_branch = Fastlane::Helper::GitHelper.current_git_branch UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Android::VersionHelper.get_public_version diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb index 9cd4d3ae7..4ab3d5fc2 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb @@ -10,11 +10,9 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' + require_relative '../../helper/git_helper' - # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. - # We need to check which branch we are actually on and not the initial branch a CI build is started from. - # See https://docs.fastlane.tools/actions/git_branch/#git_branch - current_branch = Fastlane::Actions.git_branch_name_using_HEAD + current_branch = Fastlane::Helper::GitHelper.current_git_branch UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Android::VersionHelper.get_public_version diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb index 584088565..1ab8af14c 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb @@ -6,11 +6,9 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' + require_relative '../../helper/git_helper' - # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. - # We need to check which branch we are actually on and not the initial branch a CI build is started from. - # See https://docs.fastlane.tools/actions/git_branch/#git_branch - current_branch = Fastlane::Actions.git_branch_name_using_HEAD + current_branch = Fastlane::Helper::GitHelper.current_git_branch UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Ios::VersionHelper.get_public_version diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb index a39cf2702..689da10d0 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb @@ -6,10 +6,8 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' + require_relative '../../helper/git_helper' - # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. - # We need to check which branch we are actually on and not the initial branch a CI build is started from. - # See https://docs.fastlane.tools/actions/git_branch/#git_branch current_branch = Fastlane::Actions.git_branch_name_using_HEAD UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb index 8aff1820f..b5fc4e45e 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb @@ -181,6 +181,23 @@ def self.fetch_all_tags Action.sh('git', 'fetch', '--tags') end + # Returns the current git branch, or "HEAD" if it's not checked out to any branch + # Can NOT be replaced using the environment variables such as `GIT_BRANCH` or `BUILDKITE_BRANCH` + # + # `fastlane` already has a helper action for this called `git_branch`, however it's modified + # by CI environment variables. We need to check which branch we are actually on and not the + # initial branch a CI build is started from, so we are using the `git_branch_name_using_HEAD` + # helper instead. + # + # See https://docs.fastlane.tools/actions/git_branch/#git_branch + # + # @return [String] The current git branch, or "HEAD" if it's not checked out to any branch + # + def self.current_git_branch + # We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite. + Fastlane::Actions.git_branch_name_using_HEAD + end + # Checks if a branch exists locally. # # @param [String] branch_name The name of the branch to check for From 6b1eeee5d66ad458086d4b37d718ad598b7b4580 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Fri, 21 Apr 2023 16:51:13 -0400 Subject: [PATCH 3/4] Add a changelog entry about using git_branch_name_using_HEAD instead of git_branch --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2028d1317..0d0604ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ _None_ - Add "Mobile Secrets" to `configure_update` current branch message to clarify which repo it's referring to. [#455] - `buildkite_trigger_build` now prints the web URL of the newly scheduled build, to allow you to easily open it via cmd-click. [#460] - Add the branch information to the 'This is not a release branch' error that's thrown from complete code freeze lane. [#461] +- Use `git_branch_name_using_HEAD` instead of `git_branch` so that the return value is not modified by environment variables. This has no impact to our current release flow, that's why it's not in "Breaking changes" section. [#463] ## 7.0.0 From f256ae5925ebe77a372d0fa330e4ef692a5c5d6b Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 4 May 2023 22:53:41 -0400 Subject: [PATCH 4/4] Use GitHelper.current_git_branch in ios finalize prechecks --- .../wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb index 689da10d0..456336905 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb @@ -8,7 +8,7 @@ def self.run(params) require_relative '../../helper/ios/ios_git_helper' require_relative '../../helper/git_helper' - current_branch = Fastlane::Actions.git_branch_name_using_HEAD + current_branch = Fastlane::Helper::GitHelper.current_git_branch UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/') version = Fastlane::Helper::Ios::VersionHelper.get_public_version