Skip to content

Commit 869614f

Browse files
authored
Merge pull request #463 from wordpress-mobile/add/current-git-branch
Use `git_branch_name_using_HEAD` instead of `git_branch`
2 parents 3ee6cd7 + 7b9d0df commit 869614f

6 files changed

Lines changed: 30 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ _None_
2727
- 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]
2828
- Adds `ignore_pipeline_branch_filters=true` parameter to the API call triggering a Buildkite build [#468]
2929
- Replace all instances of `is_string` with `type` [#469]
30+
- 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]
3031

3132
## 7.0.0
3233

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_completecodefreeze_prechecks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ def self.run(params)
66

77
require_relative '../../helper/android/android_version_helper'
88
require_relative '../../helper/android/android_git_helper'
9+
require_relative '../../helper/git_helper'
910

10-
UI.user_error!("Current branch - '#{other_action.git_branch}' - is not a release branch. Abort.") unless other_action.git_branch.start_with?('release/')
11+
current_branch = Fastlane::Helper::GitHelper.current_git_branch
12+
UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/')
1113

1214
version = Fastlane::Helper::Android::VersionHelper.get_public_version
1315
message = "Completing code freeze for: #{version}\n"

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_finalize_prechecks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ def self.run(params)
1010

1111
require_relative '../../helper/android/android_version_helper'
1212
require_relative '../../helper/android/android_git_helper'
13+
require_relative '../../helper/git_helper'
1314

14-
UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/')
15+
current_branch = Fastlane::Helper::GitHelper.current_git_branch
16+
UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/')
1517

1618
version = Fastlane::Helper::Android::VersionHelper.get_public_version
1719
message = "Finalizing release: #{version}\n"

lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_completecodefreeze_prechecks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ def self.run(params)
66

77
require_relative '../../helper/ios/ios_version_helper'
88
require_relative '../../helper/ios/ios_git_helper'
9+
require_relative '../../helper/git_helper'
910

10-
UI.user_error!("Current branch - '#{other_action.git_branch}' - is not a release branch. Abort.") unless other_action.git_branch.start_with?('release/')
11+
current_branch = Fastlane::Helper::GitHelper.current_git_branch
12+
UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/')
1113

1214
version = Fastlane::Helper::Ios::VersionHelper.get_public_version
1315
message = "Completing code freeze for: #{version}\n"

lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_finalize_prechecks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ def self.run(params)
66

77
require_relative '../../helper/ios/ios_version_helper'
88
require_relative '../../helper/ios/ios_git_helper'
9+
require_relative '../../helper/git_helper'
910

10-
UI.user_error!('This is not a release branch. Abort.') unless other_action.git_branch.start_with?('release/')
11+
current_branch = Fastlane::Helper::GitHelper.current_git_branch
12+
UI.user_error!("Current branch - '#{current_branch}' - is not a release branch. Abort.") unless current_branch.start_with?('release/')
1113

1214
version = Fastlane::Helper::Ios::VersionHelper.get_public_version
1315
message = "Finalizing release: #{version}\n"

lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ def self.fetch_all_tags
181181
Action.sh('git', 'fetch', '--tags')
182182
end
183183

184+
# Returns the current git branch, or "HEAD" if it's not checked out to any branch
185+
# Can NOT be replaced using the environment variables such as `GIT_BRANCH` or `BUILDKITE_BRANCH`
186+
#
187+
# `fastlane` already has a helper action for this called `git_branch`, however it's modified
188+
# by CI environment variables. We need to check which branch we are actually on and not the
189+
# initial branch a CI build is started from, so we are using the `git_branch_name_using_HEAD`
190+
# helper instead.
191+
#
192+
# See https://docs.fastlane.tools/actions/git_branch/#git_branch
193+
#
194+
# @return [String] The current git branch, or "HEAD" if it's not checked out to any branch
195+
#
196+
def self.current_git_branch
197+
# We can't use `other_action.git_branch`, because it is modified by environment variables in Buildkite.
198+
Fastlane::Actions.git_branch_name_using_HEAD
199+
end
200+
184201
# Checks if a branch exists locally.
185202
#
186203
# @param [String] branch_name The name of the branch to check for

0 commit comments

Comments
 (0)