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

add FL_GIT_BRANCH_DONT_USE_ENV_VARS env var to git_branch #21597

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastlane/lib/fastlane/actions/git_branch.rb
Expand Up @@ -16,7 +16,7 @@ def self.description
end

def self.details
"If no branch could be found, this action will return an empty string. This is a wrapper for the internal action Actions.git_branch"
"If no branch could be found, this action will return an empty string. If `FL_GIT_BRANCH_DONT_USE_ENV_VARS` is `true`, it'll ignore CI ENV vars. This is a wrapper for the internal action Actions.git_branch"
Copy link
Member

Choose a reason for hiding this comment

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

Instead of just an environment variable, can this dont_use_env_vars be added as on option on the git_branch action?

The action would then pass this as an optional parameter into the git_branch method?

I'm kind of leaning towards this so that this behavior is more publicly document in the action options documentation 🤔 Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem here is that git_branch is not the only action relying on that Helper.git_branch.

That's the whole problem and why we thought about the env car as being able to impact all actions relying on that helper.

For example, ensure_git_branch action is also impacted by that helper's behavior (see PR description for details)

end

def self.available_options
Expand Down
3 changes: 3 additions & 0 deletions fastlane/lib/fastlane/helper/git_helper.rb
Expand Up @@ -121,7 +121,10 @@ def self.last_git_commit_hash(short)

# Returns the current git branch, or "HEAD" if it's not checked out to any branch
# Can be replaced using the environment variable `GIT_BRANCH`
# unless `FL_GIT_BRANCH_DONT_USE_ENV_VARS` is `true`
def self.git_branch
return self.git_branch_name_using_HEAD if FastlaneCore::Env.truthy?('FL_GIT_BRANCH_DONT_USE_ENV_VARS')

env_name = SharedValues::GIT_BRANCH_ENV_VARS.find { |env_var| FastlaneCore::Env.truthy?(env_var) }
ENV.fetch(env_name.to_s) do
self.git_branch_name_using_HEAD
Expand Down
18 changes: 18 additions & 0 deletions fastlane/spec/actions_specs/git_branch_spec.rb
Expand Up @@ -13,6 +13,24 @@
end
end

describe "CI set ENV values but FL_GIT_BRANCH_DONT_USE_ENV_VARS is true" do
Fastlane::Actions::SharedValues::GIT_BRANCH_ENV_VARS.each do |env_var|
it "gets the value from Git directly with #{env_var}" do
expect(Fastlane::Actions).to receive(:sh)
.with("git rev-parse --abbrev-ref HEAD", log: false)
.and_return("branch-name-from-git")

FastlaneSpec::Env.with_env_values(env_var => "#{env_var}-branch-name", 'FL_GIT_BRANCH_DONT_USE_ENV_VARS' => 'true') do
result = Fastlane::FastFile.new.parse("lane :test do
git_branch
end").runner.execute(:test)

expect(result).to eq("branch-name-from-git")
end
end
end
end

describe "with no CI set ENV values" do
it "gets the value from Git directly" do
expect(Fastlane::Actions).to receive(:sh)
Expand Down