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

[Tooling/Cleanup] Cleanup git helpers #206

Merged
merged 21 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.run(params)
require_relative '../../helper/android/android_git_helper.rb'

# Checkout develop and update
Fastlane::Helper::Android::GitHelper::git_checkout_and_pull("develop")
Fastlane::Helper::GitHelper::checkout_and_pull("develop")

# Check versions
release_version = Fastlane::Helper::Android::VersionHelper::get_release_version
Expand All @@ -19,7 +19,7 @@ def self.run(params)

# Check branch
app_version = Fastlane::Helper::Android::VersionHelper::get_public_version
UI.user_error!("#{message}Release branch for version #{app_version} doesn't exist. Abort.") unless (!params[:base_version].nil? || Fastlane::Helper::Android::GitHelper::git_checkout_and_pull_release_branch_for(app_version))
UI.user_error!("#{message}Release branch for version #{app_version} doesn't exist. Abort.") unless (!params[:base_version].nil? || Fastlane::Helper::GitHelper::checkout_and_pull(release: app_version))

# Check user overwrite
if (!params[:base_version].nil?)
Expand Down Expand Up @@ -50,7 +50,7 @@ def self.run(params)
end

def self.get_user_build_version(version, message)
UI.user_error!("Release branch for version #{version} doesn't exist. Abort.") unless Fastlane::Helper::Android::GitHelper::git_checkout_and_pull_release_branch_for(version)
UI.user_error!("Release branch for version #{version} doesn't exist. Abort.") unless Fastlane::Helper::GitHelper::checkout_and_pull(release: version)
release_version = Fastlane::Helper::Android::VersionHelper::get_release_version
message << "Looking at branch release/#{version} as requested by user. Detected version: #{release_version[Fastlane::Helper::Android::VersionHelper::VERSION_NAME]}.\n"
alpha_release_version = Fastlane::Helper::Android::VersionHelper::get_alpha_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.run(params)
require_relative '../../helper/android/android_git_helper.rb'

# Checkout develop and update
Fastlane::Helper::Android::GitHelper.git_checkout_and_pull("develop")
Fastlane::Helper::GitHelper.checkout_and_pull("develop")

# Create versions
current_version = Fastlane::Helper::Android::VersionHelper.get_release_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def self.run(params)
require_relative '../../helper/ios/ios_git_helper.rb'

# Checkout develop and update
Fastlane::Helper::Ios::GitHelper::git_checkout_and_pull("develop")
Fastlane::Helper::GitHelper::checkout_and_pull("develop")

# Check versions
build_version = Fastlane::Helper::Ios::VersionHelper::get_build_version
message = "The following current version has been detected: #{build_version}\n"

# Check branch
app_version = Fastlane::Helper::Ios::VersionHelper::get_public_version
UI.user_error!("#{message}Release branch for version #{app_version} doesn't exist. Abort.") unless (!params[:base_version].nil? || Fastlane::Helper::Ios::GitHelper::git_checkout_and_pull_release_branch_for(app_version))
UI.user_error!("#{message}Release branch for version #{app_version} doesn't exist. Abort.") unless (!params[:base_version].nil? || Fastlane::Helper::GitHelper::checkout_and_pull(release: app_version))

# Check user overwrite
build_version = get_user_build_version(params[:base_version], message) unless params[:base_version].nil?
Expand All @@ -41,7 +41,7 @@ def self.run(params)
end

def self.get_user_build_version(version, message)
UI.user_error!("Release branch for version #{version} doesn't exist. Abort.") unless Fastlane::Helper::Ios::GitHelper::git_checkout_and_pull_release_branch_for(version)
UI.user_error!("Release branch for version #{version} doesn't exist. Abort.") unless Fastlane::Helper::GitHelper::checkout_and_pull(release: version)
build_version = Fastlane::Helper::Ios::VersionHelper::get_build_version
message << "Looking at branch release/#{version} as requested by user. Detected version: #{build_version}.\n"
build_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.run(params)
show_config()

# Update local develop and branch
Fastlane::Helper::Ios::GitHelper.git_checkout_and_pull("develop")
Fastlane::Helper::GitHelper.checkout_and_pull("develop")
Fastlane::Helper::Ios::GitHelper.do_release_branch(@new_release_branch)
UI.message "Done!"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.run(params)
require_relative '../../helper/ios/ios_git_helper.rb'

# Checkout develop and update
Fastlane::Helper::Ios::GitHelper.git_checkout_and_pull("develop")
Fastlane::Helper::GitHelper.checkout_and_pull("develop")

# Create versions
current_version = Fastlane::Helper::Ios::VersionHelper.get_public_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ module Fastlane
module Helper
module Android
module GitHelper
def self.git_checkout_and_pull(branch)
Action.sh("git checkout #{branch}")
Action.sh("git pull")
end

def self.git_checkout_and_pull_release_branch_for(version)
branch_name = "release/#{version}"
Action.sh("git pull")
begin
Action.sh("git checkout #{branch_name}")
Action.sh("git pull origin #{branch_name}")
return true
rescue
return false
end
end

def self.do_release_branch(branch_name)
if (check_branch_exists(branch_name) == true) then
UI.message("Branch #{branch_name} already exists. Skipping creation.")
Expand Down
17 changes: 17 additions & 0 deletions lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ def self.has_git_lfs
`git config --get-regex lfs`.length > 0
end

# Switch to the given branch and pull its latest commits.
#
# @param [String,Hash] branch Name of the branch to pull.
# If you provide a Hash with a single key=>value pair, it will build the branch name as `"#{key}/#{value}"`,
# i.e. `checkout_and_pull(release: version)` is equivalent to `checkout_and_pull("release/#{version}")`.
#
# @return [Bool] True if it succeeded switching and pulling, false if there was an error during the switch or pull.
#
def self.checkout_and_pull(branch)
AliSoftware marked this conversation as resolved.
Show resolved Hide resolved
branch = branch.first.join('/') if branch.is_a?(Hash)
Action.sh("git", "checkout", branch)
Action.sh("git", "pull")
return true
rescue
return false
end

# `git add` the specified files (if any provided) then commit them using the provided message.
# Optionally, push the commit to the remote too.
#
Expand Down
17 changes: 0 additions & 17 deletions lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ module Fastlane
module Helper
module Ios
module GitHelper
def self.git_checkout_and_pull(branch)
Action.sh("git checkout #{branch}")
Action.sh("git pull")
end

def self.git_checkout_and_pull_release_branch_for(version)
branch_name = "release/#{version}"
Action.sh("git pull")
begin
Action.sh("git checkout #{branch_name}")
Action.sh("git pull origin #{branch_name}")
return true
rescue
return false
end
end

def self.branch_for_hotfix(tag_version, new_version)
Action.sh("git checkout #{tag_version}")
Action.sh("git checkout -b release/#{new_version}")
Expand Down