Skip to content

Commit e74576a

Browse files
authored
Merge pull request #472 from wordpress-mobile/remove/git-push-actions
Remove git push commands after creating a new commit or branch
2 parents d09d8c6 + e26197f commit e74576a

File tree

10 files changed

+30
-42
lines changed

10 files changed

+30
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Breaking Changes
88

9-
_None_
9+
- Remove git push commands after creating a new commit or branch. [#472] See `MIGRATION.md` for instructions.
1010

1111
### New Features
1212

MIGRATION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Migration Instructions for Major Releases
2+
3+
### From `7.0.0` to `8.0.0`
4+
5+
We are no longer pushing to remote after creating a new commit or a branch. That means, developers need to manually push the changes or add push commands in the project's `Fastfile`. Most importantly, we can no longer immediately trigger beta/final builds after creating a new commit because the changes will not be in remote yet. If you want to keep the existing behavior, you'll need to add a push command before these triggers.
6+
7+
For example, in [WordPress-Android's `new_beta_release` lane](https://github.com/wordpress-mobile/WordPress-Android/blob/0c64cb84c256e004473e97d72b4ac6682ebc140b/fastlane/lanes/release.rb#L86), we download translations, bump the beta version and then trigger a new build in CI. After migrating to `8.0.0` of `release-toolkit`, we'll need to add [`push_to_git_remote`](https://docs.fastlane.tools/actions/push_to_git_remote/) command before this trigger to keep the existing behavior.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def self.run(params)
2626
Action.sh('./gradlew', params[:lint_task])
2727
end
2828

29-
Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: res_dir, push: true) unless params[:skip_commit]
29+
Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: res_dir) unless params[:skip_commit]
3030
end
3131

3232
#####################################################
@@ -38,7 +38,7 @@ def self.description
3838
end
3939

4040
def self.details
41-
'Download translations from GlotPress, update local strings.xml files accordingly, lint, commit the changes, and push to the remote'
41+
'Download translations from GlotPress, update local strings.xml files accordingly, lint, commit the changes'
4242
end
4343

4444
def self.available_options
@@ -90,7 +90,7 @@ def self.available_options
9090
FastlaneCore::ConfigItem.new(
9191
key: :skip_commit,
9292
env_name: 'FL_DOWNLOAD_TRANSLATIONS_SKIP_COMMIT',
93-
description: 'If set to true, will skip the commit/push step. Otherwise, it will commit the changes and push them (the default)',
93+
description: 'If set to true, will skip the commit step',
9494
type: Boolean,
9595
default_value: false
9696
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def self.run(params)
1212
next_version = Fastlane::Helper::Android::VersionHelper.calc_next_release_short_version(params[:new_version])
1313

1414
Fastlane::Helper::ReleaseNotesHelper.add_new_section(path: path, section_title: next_version)
15-
Fastlane::Helper::GitHelper.commit(message: "Release Notes: add new section for next version (#{next_version})", files: path, push: true)
15+
Fastlane::Helper::GitHelper.commit(message: "Release Notes: add new section for next version (#{next_version})", files: path)
1616

1717
UI.message 'Done.'
1818
end

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def self.run(params)
1818
repo_clean = repo_status.empty?
1919
unless repo_clean
2020
Action.sh('git commit -m "Update metadata strings"')
21-
Action.sh('git push')
2221
end
2322
end
2423

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def self.run(params)
1212
next_version = Fastlane::Helper::Ios::VersionHelper.calc_next_release_version(params[:new_version])
1313

1414
Fastlane::Helper::ReleaseNotesHelper.add_new_section(path: path, section_title: next_version)
15-
Fastlane::Helper::GitHelper.commit(message: "Release Notes: add new section for next version (#{next_version})", files: path, push: true)
15+
Fastlane::Helper::GitHelper.commit(message: "Release Notes: add new section for next version (#{next_version})", files: path)
1616

1717
UI.message 'Done.'
1818
end

lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_git_helper.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ module Android
44
# Helper methods to execute git-related operations that are specific to Android projects
55
#
66
module GitHelper
7-
# Commit and push the files that are modified when we bump version numbers on an iOS project
7+
# Commit the files that are modified when we bump version numbers on an Android project
88
#
9-
# This typically commits and pushes the `build.gradle` file inside the project subfolder.
9+
# This typically commits the `version.properties` inside root folder or `build.gradle` file
10+
# inside the project subfolder.
1011
#
1112
# @env PROJECT_ROOT_FOLDER The path to the git root of the project
1213
# @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file)
@@ -16,14 +17,12 @@ def self.commit_version_bump
1617
if File.exist?(Fastlane::Helper::Android::VersionHelper.version_properties_file)
1718
Fastlane::Helper::GitHelper.commit(
1819
message: 'Bump version number',
19-
files: File.join(ENV['PROJECT_ROOT_FOLDER'], 'version.properties'),
20-
push: true
20+
files: File.join(ENV['PROJECT_ROOT_FOLDER'], 'version.properties')
2121
)
2222
else
2323
Fastlane::Helper::GitHelper.commit(
2424
message: 'Bump version number',
25-
files: File.join(ENV['PROJECT_ROOT_FOLDER'], ENV['PROJECT_NAME'], 'build.gradle'),
26-
push: true
25+
files: File.join(ENV['PROJECT_ROOT_FOLDER'], ENV['PROJECT_NAME'], 'build.gradle')
2726
)
2827
end
2928
end

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,35 @@ def self.update_submodules
7373
Action.sh('git', 'submodule', 'update', '--init', '--recursive')
7474
end
7575

76-
# Create a new branch named `branch_name`, cutting it from branch/commit/tag `from`, and push it
76+
# Create a new branch named `branch_name`, cutting it from branch/commit/tag `from`
7777
#
7878
# If the branch with that name already exists, it will instead switch to it and pull new commits.
7979
#
8080
# @param [String] branch_name The full name of the new branch to create, e.g "release/1.2"
8181
# @param [String?] from The branch or tag from which to cut the branch from.
8282
# If `nil`, will cut the new branch from the current commit. Otherwise, will checkout that commit/branch/tag before cutting the branch.
83-
# @param [Bool] push If true, will also push the branch to `origin`, tracking the upstream branch with the local one.
8483
#
85-
def self.create_branch(branch_name, from: nil, push: true)
84+
def self.create_branch(branch_name, from: nil)
8685
if branch_exists?(branch_name)
8786
UI.message("Branch #{branch_name} already exists. Skipping creation.")
8887
Action.sh('git', 'checkout', branch_name)
8988
Action.sh('git', 'pull', 'origin', branch_name)
9089
else
9190
Action.sh('git', 'checkout', from) unless from.nil?
9291
Action.sh('git', 'checkout', '-b', branch_name)
93-
Action.sh('git', 'push', '-u', 'origin', branch_name) if push
9492
end
9593
end
9694

9795
# `git add` the specified files (if any provided) then commit them using the provided message.
98-
# Optionally, push the commit to the remote too.
9996
#
10097
# @param [String] message The commit message to use
10198
# @param [String|Array<String>] files A file or array of files to git-add before creating the commit.
10299
# Use `nil` or `[]` if you already added the files in a separate step and don't wan't this method to add any new file before commit.
103100
# Also accepts the special symbol `:all` to add all the files (`git commit -a -m …`).
104-
# @param [Bool] push If true, will `git push` to `origin` after the commit has been created. Defaults to `false`.
105101
#
106-
# @return [Bool] True if commit and push were successful, false if there was an issue during commit & push (most likely being "nothing to commit").
102+
# @return [Bool] True if commit was successful, false if there was an issue (most likely being "nothing to commit").
107103
#
108-
def self.commit(message:, files: nil, push: false)
104+
def self.commit(message:, files: nil)
109105
files = [files] if files.is_a?(String)
110106
args = []
111107
if files == :all
@@ -115,7 +111,6 @@ def self.commit(message:, files: nil, push: false)
115111
end
116112
begin
117113
Action.sh('git', 'commit', *args, '-m', message)
118-
Action.sh('git', 'push', 'origin', 'HEAD') if push
119114
return true
120115
rescue
121116
return false

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Ios
44
# Helper methods to execute git-related operations that are specific to iOS projects
55
#
66
module GitHelper
7-
# Commit and push the files that are modified when we bump version numbers on an iOS project
7+
# Commit the files that are modified when we bump version numbers on an iOS project
88
#
9-
# This typically commits and pushes:
9+
# This typically commits:
1010
# - The files in `./config/*` – especially `Version.*.xcconfig` files
1111
# - The `fastlane/Deliverfile` file (which contains the `app_version` line)
1212
# - The `<ProjectRoot>/<ProjectName>/Resources/AppStoreStrings.pot` file, containing a key for that version's release notes
@@ -25,10 +25,10 @@ def self.commit_version_bump(include_deliverfile: true, include_metadata: true)
2525
files_list.append File.join(ENV['PROJECT_ROOT_FOLDER'], ENV['PROJECT_NAME'], 'Resources', ENV['APP_STORE_STRINGS_FILE_NAME'])
2626
end
2727

28-
Fastlane::Helper::GitHelper.commit(message: 'Bump version number', files: files_list, push: true)
28+
Fastlane::Helper::GitHelper.commit(message: 'Bump version number', files: files_list)
2929
end
3030

31-
# Calls the `Scripts/localize.py` script in the project root folder and push the `*.strings` files
31+
# Calls the `Scripts/localize.py` script in the project root folder and commit the `*.strings` files
3232
#
3333
# That script updates the `.strings` files with translations from GlotPress.
3434
#
@@ -42,7 +42,7 @@ def self.commit_version_bump(include_deliverfile: true, include_metadata: true)
4242
def self.localize_project
4343
Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/localize.py")
4444

45-
Fastlane::Helper::GitHelper.commit(message: 'Update strings for localization', files: strings_files, push: true) || UI.message('No new strings, skipping commit')
45+
Fastlane::Helper::GitHelper.commit(message: 'Update strings for localization', files: strings_files) || UI.message('No new strings, skipping commit')
4646
end
4747

4848
# Call the `Scripts/update-translations.rb` then the `fastlane/download_metadata` Scripts from the host project folder
@@ -56,11 +56,11 @@ def self.localize_project
5656
def self.update_metadata
5757
Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/update-translations.rb")
5858

59-
Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: strings_files, push: false)
59+
Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: strings_files)
6060

6161
Action.sh('cd fastlane && ./download_metadata.swift')
6262

63-
Fastlane::Helper::GitHelper.commit(message: 'Update metadata translations', files: './fastlane/metadata/', push: true)
63+
Fastlane::Helper::GitHelper.commit(message: 'Update metadata translations', files: './fastlane/metadata/')
6464
end
6565

6666
def self.strings_files

spec/git_helper_spec.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
expect(Fastlane::Helper::GitHelper.has_git_lfs?).to be false
6767
end
6868

69-
context('commit(message:, files:, push:)') do
69+
context('commit(message:, files:)') do
7070
before(:each) do
7171
allow_fastlane_action_sh()
7272
@message = 'Some commit message with spaces'
@@ -108,18 +108,6 @@
108108
expect_shell_command('git', 'commit', '-a', '-m', @message)
109109
Fastlane::Helper::GitHelper.commit(message: @message, files: :all)
110110
end
111-
112-
it 'does not push to origin if not asked' do
113-
expect_shell_command('git', 'commit', '-m', @message)
114-
expect_shell_command('git', 'push', any_args).never
115-
Fastlane::Helper::GitHelper.commit(message: @message)
116-
end
117-
118-
it 'does push to origin if asked' do
119-
expect_shell_command('git', 'commit', '-m', @message)
120-
expect_shell_command('git', 'push', 'origin', 'HEAD').once
121-
Fastlane::Helper::GitHelper.commit(message: @message, push: true)
122-
end
123111
end
124112

125113
describe '#is_ignored?' do

0 commit comments

Comments
 (0)