diff --git a/CHANGELOG.md b/CHANGELOG.md index 3647bda05..c717c246c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ _None_ - Replace `rspec-buildkite-analytics` with `buildkite-test_collector` (Buildkite renamed the gem) and update it to `2.2.0`. This is another internal-only change and is not a breaking change for clients. [#465] - Adds `ignore_pipeline_branch_filters=true` parameter to the API call triggering a Buildkite build [#468] - Replace all instances of `is_string` with `type` [#469] +- 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 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 8217d8183..bfdeed586 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb @@ -6,8 +6,10 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' + require_relative '../../helper/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/') + 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 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 da3619bc9..3d67342f2 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb @@ -10,8 +10,10 @@ def self.run(params) require_relative '../../helper/android/android_version_helper' require_relative '../../helper/android/android_git_helper' + require_relative '../../helper/git_helper' - UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/') + 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 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 701bcaed0..cefefc1cd 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb @@ -6,8 +6,10 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' + require_relative '../../helper/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/') + 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 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 3ceac70ac..5309b8254 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb @@ -6,8 +6,10 @@ def self.run(params) require_relative '../../helper/ios/ios_version_helper' require_relative '../../helper/ios/ios_git_helper' + require_relative '../../helper/git_helper' - UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/') + 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 message = "Finalizing release: #{version}\n" 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