Skip to content

Commit

Permalink
Fixes issues during flutter next snapshot creation (#18)
Browse files Browse the repository at this point in the history
* Fixes issues during flutter next snapshot creation

* Add additional safety check
  • Loading branch information
tonidero authored Aug 12, 2022
1 parent 3bcd993 commit b470362
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.run(params)
Helper::RevenuecatInternalHelper.commmit_changes_and_push_current_branch("Version bump for #{new_version_number}")

pr_title = "Release/#{new_version_number}"
Helper::RevenuecatInternalHelper.create_pr_to_main(pr_title, changelog, repo_name, github_pr_token)
Helper::RevenuecatInternalHelper.create_pr_to_main(pr_title, changelog, repo_name, new_branch_name, github_pr_token)
end

def self.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.run(params)

Helper::RevenuecatInternalHelper.commmit_changes_and_push_current_branch('Preparing for next version')

Helper::RevenuecatInternalHelper.create_pr_to_main("Prepare next version: #{next_version_snapshot}", nil, repo_name, github_pr_token)
Helper::RevenuecatInternalHelper.create_pr_to_main("Prepare next version: #{next_version_snapshot}", nil, repo_name, new_branch_name, github_pr_token)
end

def self.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ def self.commmit_changes_and_push_current_branch(commit_message)
Actions::PushToGitRemoteAction.run(remote: 'origin')
end

def self.create_pr_to_main(title, body, repo_name, github_pr_token)
def self.create_pr_to_main(title, body, repo_name, head_branch, github_pr_token)
Actions::CreatePullRequestAction.run(
api_token: github_pr_token,
title: title,
base: 'main',
body: body,
repo: "RevenueCat/#{repo_name}",
head: Actions.git_branch,
head: head_branch,
api_url: 'https://api.github.com'
)
end
Expand Down Expand Up @@ -228,7 +228,7 @@ def self.get_github_release_tag_names(repo_name)
end

remote_branches = Actions.sh('git', 'ls-remote', '--heads', 'origin', new_branch)
unless remote_branches.empty?
if !remote_branches.nil? && remote_branches.include?(new_branch)
UI.error("Branch '#{new_branch}' already exists in remote repository.")
UI.user_error!("Please make sure it doesn't have any unsaved changes and delete it to continue.")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:edited_changelog) { 'mock-edited-changelog' }
let(:current_version) { '1.12.0' }
let(:new_version) { '1.13.0' }
let(:new_branch_name) { 'release/1.13.0' }

it 'calls all the appropriate methods with appropriate parameters' do
allow(FastlaneCore::UI).to receive(:input).with('New version number: ').and_return(new_version)
Expand All @@ -26,7 +27,7 @@
.with(auto_generated_changelog, mock_changelog_latest_path, editor)
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:create_new_branch_and_checkout)
.with('release/1.13.0')
.with(new_branch_name)
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:replace_version_number)
.with(current_version, new_version, ['./test_file.sh', './test_file2.rb'], ['./test_file3.kt', './test_file4.swift'])
Expand All @@ -38,7 +39,7 @@
.with("Version bump for #{new_version}")
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:create_pr_to_main)
.with("Release/1.13.0", edited_changelog, mock_repo_name, mock_github_pr_token)
.with("Release/1.13.0", edited_changelog, mock_repo_name, new_branch_name, mock_github_pr_token)
.once

Fastlane::Actions::BumpVersionUpdateChangelogCreatePrAction.run(
Expand Down
5 changes: 3 additions & 2 deletions spec/actions/create_next_snapshot_version_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:repo_name) { 'fake-repo-name' }
let(:current_version) { '1.12.0' }
let(:next_version) { '1.13.0-SNAPSHOT' }
let(:new_branch_name) { 'bump/1.13.0-SNAPSHOT' }

it 'calls all the appropriate methods with appropriate parameters' do
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:validate_local_config_status_for_bump)
Expand All @@ -14,7 +15,7 @@
.and_return(next_version)
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:create_new_branch_and_checkout)
.with('bump/1.13.0-SNAPSHOT')
.with(new_branch_name)
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:replace_version_number)
.with(current_version, next_version, ['./test_file.sh', './test_file2.rb'], ['./test_file4.swift', './test_file5.kt'])
Expand All @@ -23,7 +24,7 @@
.with('Preparing for next version')
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:create_pr_to_main)
.with('Prepare next version: 1.13.0-SNAPSHOT', nil, repo_name, github_pr_token)
.with('Prepare next version: 1.13.0-SNAPSHOT', nil, repo_name, new_branch_name, github_pr_token)
.once
Fastlane::Actions::CreateNextSnapshotVersionAction.run(
current_version: current_version,
Expand Down
12 changes: 9 additions & 3 deletions spec/helper/revenuecat_internal_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,17 @@ def setup_stubs

describe '.create_pr_to_main' do
it 'creates pr' do
allow(Fastlane::Actions).to receive(:git_branch).and_return('fake-current-branch')
expect(Fastlane::Actions::CreatePullRequestAction).to receive(:run)
.with(
api_token: 'fake-github-pr-token',
title: 'fake-title',
base: 'main',
body: 'fake-changelog',
repo: 'RevenueCat/fake-repo-name',
head: 'fake-current-branch',
head: 'fake-branch',
api_url: 'https://api.github.com'
).once
Fastlane::Helper::RevenuecatInternalHelper.create_pr_to_main('fake-title', 'fake-changelog', 'fake-repo-name', 'fake-github-pr-token')
Fastlane::Helper::RevenuecatInternalHelper.create_pr_to_main('fake-title', 'fake-changelog', 'fake-repo-name', 'fake-branch', 'fake-github-pr-token')
end
end

Expand Down Expand Up @@ -403,6 +402,13 @@ def setup_stubs
end.to raise_exception(StandardError)
end

it 'works if git returns ssh warning' do
expect(Fastlane::Actions).to receive(:sh)
.with('git', 'ls-remote', '--heads', 'origin', 'new-branch')
.and_return("Warning: Permanently added the ECDSA host key for IP address 'xxx.xxx.xxx.xxx' to the list of known hosts.")
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token')
end

it 'ensures new branch does not exist remotely' do
expect(Fastlane::Actions).to receive(:sh).with('git', 'ls-remote', '--heads', 'origin', 'new-branch').once
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token')
Expand Down

0 comments on commit b470362

Please sign in to comment.