-
Notifications
You must be signed in to change notification settings - Fork 9
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 create_branch
and checkout_and_pull
actions
#532
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'fastlane/action' | ||
require_relative '../../helper/git_helper' | ||
module Fastlane | ||
module Actions | ||
class CheckoutAndPullAction < Action | ||
def self.run(params) | ||
branch_name = params[:branch_name] | ||
|
||
Fastlane::Helper::GitHelper.checkout_and_pull(branch_name) | ||
end | ||
|
||
def self.description | ||
'Checkout and pull the specified branch' | ||
end | ||
|
||
def self.return_value | ||
'True if it succeeded switching and pulling, false if there was an error during the switch or pull.' | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :branch_name, | ||
env_name: 'BRANCH_NAME_TO_CHECKOUT_AND_PULL', | ||
description: 'The name of the branch to checkout and pull', | ||
optional: false, | ||
type: String), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In https://github.com/wordpress-mobile/release-toolkit/blob/c7329289f6f00a78cdf9f1988e627390efcf3c43/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb#L55C7-L57C118, the param can be either a
For this action, I just went with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed. I'm ok with removing the ability to use it with a |
||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
true | ||
end | ||
|
||
def self.authors | ||
['Automattic'] | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'fastlane/action' | ||
require_relative '../../helper/git_helper' | ||
module Fastlane | ||
module Actions | ||
class CreateBranchAction < Action | ||
def self.run(params) | ||
branch_name = params[:branch_name] | ||
from = params[:from] | ||
|
||
Fastlane::Helper::GitHelper.create_branch(branch_name, from: from) | ||
end | ||
|
||
def self.description | ||
'Create a new branch named `branch_name`, cutting it from branch/commit/tag `from`' | ||
end | ||
|
||
def self.details | ||
'If the branch with that name already exists, it will instead switch to it and pull new commits.' | ||
end | ||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior is confusing to me, especially since running Again, I feel like it's the responsibility of the apps' What I'd suggest instead would be to have a Then when one needs to cut a branch B from a branch A, they would call |
||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :branch_name, | ||
env_name: 'BRANCH_NAME_TO_CREATE', | ||
description: 'The full name of the new branch to create, e.g. "release/1.2"', | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :from, | ||
env_name: 'BRANCH_OR_COMMIT_TO_CUT_FROM', | ||
description: 'The branch/tag/commit from which to cut the branch from. If `nil`, will cut the new branch from the current commit. Otherwise, will checkout that commit/branch/tag before cutting the branch.', | ||
optional: true, | ||
type: String), | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
true | ||
end | ||
|
||
def self.authors | ||
['Automattic'] | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm a fan of having an action doing multiple things. Admittedly it's quite common to do both a
checkout
and apull
one after the other, but I think our philosophy for such things is instead to make things more atomic.Fastlane already has a
git_pull
action built-in. So maybe we should instead just create agit_checkout
(orgit_switch
orswitch_to_branch
) action, and let the callers (i.e. the apps'Fastfile
) be the ones doinggit_checkout(branch: …)
thengit_pull
one after the other?I feel like this separation also make sense because sometimes we want to switch to a branch but we already know there's no need to
git_pull
it.For example, in Tumblr:
code_freeze
, weensure_git_branch(branch: '^develop$')
thengit_pull
(as opposed to make the lane do the checkout ofdevelop
; it was a choice to let the RM do the checkout of the right branch so they know what they were doing and what they were freezing before starting the lane) at the startrelease/*
branch fromdevelop
… but without switching to it yet, because we want to bump the alpha version ondevelop
after that first and git push thatrelease/*
branch to bump the beta version and trigger a new beta. At that point, for this first beta, we don't want togit_pull
because:release/*
branch so we're guaranteed there's no remote commit to pull, and this would be pointlessgit_pull
it would fail and crash the lane, because therelease/*
branch does not exist on the remote yet. And we don't want to push it to remote until we've made the commit to bump the beta version, otherwise it would trigger an extra CI build for nothing.Hopefully this shows some scenarios where we'd want to
git checkout
without pulling (when branch is not present in remote yet), and want pulling without a checkout 🙃