diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 97e945a..35ccb29 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -10,7 +10,6 @@ lane :sample_bump_version_update_changelog_create_pr_action do |options| github_pr_token: 'github-api-token', # This can also be obtained from ENV GITHUB_PULL_REQUEST_API_TOKEN github_token: 'github-token', github_rate_limit: 0, - branch: 'main', editor: 'vim' ) end diff --git a/lib/fastlane/plugin/revenuecat_internal/actions/bump_version_update_changelog_create_pr_action.rb b/lib/fastlane/plugin/revenuecat_internal/actions/bump_version_update_changelog_create_pr_action.rb index 5831e73..beca9ec 100644 --- a/lib/fastlane/plugin/revenuecat_internal/actions/bump_version_update_changelog_create_pr_action.rb +++ b/lib/fastlane/plugin/revenuecat_internal/actions/bump_version_update_changelog_create_pr_action.rb @@ -7,7 +7,6 @@ module Fastlane module Actions class BumpVersionUpdateChangelogCreatePrAction < Action def self.run(params) - branch = params[:branch] repo_name = params[:repo_name] github_pr_token = params[:github_pr_token] github_token = params[:github_token] @@ -20,6 +19,11 @@ def self.run(params) changelog_path = params[:changelog_path] editor = params[:editor] + current_branch = Actions.git_branch + unless UI.confirm("Current branch is #{current_branch}. Are you sure this is the base branch for your bump?") + UI.user_error!("Cancelled during branch confirmation") + end + UI.important("Current version is #{version_number}") # Ask for new version number @@ -29,7 +33,7 @@ def self.run(params) new_branch_name = "release/#{new_version_number}" - Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(branch, new_branch_name, github_pr_token) + Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(new_branch_name, github_pr_token) generated_contents = Helper::VersioningHelper.auto_generate_changelog(repo_name, github_token, rate_limit_sleep) Helper::RevenuecatInternalHelper.edit_changelog(generated_contents, changelog_latest_path, editor) @@ -102,11 +106,6 @@ def self.available_options optional: true, default_value: 0, type: Integer), - FastlaneCore::ConfigItem.new(key: :branch, - description: "Allows to execute the action from the given branch", - optional: true, - default_value: "main", - type: String), FastlaneCore::ConfigItem.new(key: :editor, env_name: "RC_INTERNAL_FASTLANE_EDITOR", description: "Allows to override editor to be used when editting the changelog", diff --git a/lib/fastlane/plugin/revenuecat_internal/actions/create_next_snapshot_version_action.rb b/lib/fastlane/plugin/revenuecat_internal/actions/create_next_snapshot_version_action.rb index 14a8c24..08d711d 100644 --- a/lib/fastlane/plugin/revenuecat_internal/actions/create_next_snapshot_version_action.rb +++ b/lib/fastlane/plugin/revenuecat_internal/actions/create_next_snapshot_version_action.rb @@ -16,7 +16,7 @@ def self.run(params) new_branch_name = "bump/#{next_version_snapshot}" label = 'next_release' - Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(nil, new_branch_name, github_pr_token) + Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(new_branch_name, github_pr_token) Helper::RevenuecatInternalHelper.create_new_branch_and_checkout(new_branch_name) diff --git a/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb b/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb index aed0a35..ea8bd2f 100644 --- a/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb +++ b/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb @@ -89,7 +89,7 @@ def self.create_pr_to_main(title, body, repo_name, head_branch, github_pr_token, ) end - def self.validate_local_config_status_for_bump(current_branch, new_branch, github_pr_token) + def self.validate_local_config_status_for_bump(new_branch, github_pr_token) # Ensure GitHub API token is set if github_pr_token.nil? || github_pr_token.empty? UI.error("A github_pr_token parameter or an environment variable GITHUB_PULL_REQUEST_API_TOKEN is required to create a pull request") @@ -97,7 +97,6 @@ def self.validate_local_config_status_for_bump(current_branch, new_branch, githu UI.user_error!("Could not find value for GITHUB_PULL_REQUEST_API_TOKEN") end ensure_new_branch_local_remote(new_branch) - Actions::EnsureGitBranchAction.run(branch: current_branch) unless current_branch.nil? Actions::EnsureGitStatusCleanAction.run({}) end diff --git a/spec/actions/bump_version_update_changelog_create_pr_action_spec.rb b/spec/actions/bump_version_update_changelog_create_pr_action_spec.rb index 3e7a2ef..df085b8 100644 --- a/spec/actions/bump_version_update_changelog_create_pr_action_spec.rb +++ b/spec/actions/bump_version_update_changelog_create_pr_action_spec.rb @@ -5,7 +5,6 @@ let(:mock_repo_name) { 'mock-repo-name' } let(:mock_changelog_latest_path) { './fake-changelog-latest-path/CHANGELOG.latest.md' } let(:mock_changelog_path) { './fake-changelog-path/CHANGELOG.md' } - let(:branch) { 'main' } let(:editor) { 'vim' } let(:auto_generated_changelog) { 'mock-auto-generated-changelog' } let(:edited_changelog) { 'mock-edited-changelog' } @@ -16,9 +15,10 @@ it 'calls all the appropriate methods with appropriate parameters' do allow(FastlaneCore::UI).to receive(:input).with('New version number: ').and_return(new_version) + allow(FastlaneCore::UI).to receive(:confirm).with(anything).and_return(true) allow(File).to receive(:read).with(mock_changelog_latest_path).and_return(edited_changelog) expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:validate_local_config_status_for_bump) - .with(branch, 'release/1.13.0', mock_github_pr_token) + .with('release/1.13.0', mock_github_pr_token) .once expect(Fastlane::Helper::VersioningHelper).to receive(:auto_generate_changelog) .with(mock_repo_name, mock_github_token, 3) @@ -53,15 +53,32 @@ github_pr_token: mock_github_pr_token, github_token: mock_github_token, github_rate_limit: 3, - branch: branch, editor: editor ) end + + it 'fails if selected no during prompt validating current branch' do + allow(FastlaneCore::UI).to receive(:confirm).with(anything).and_return(false) + expect do + Fastlane::Actions::BumpVersionUpdateChangelogCreatePrAction.run( + current_version: current_version, + changelog_latest_path: mock_changelog_latest_path, + changelog_path: mock_changelog_path, + files_to_update: ['./test_file.sh', './test_file2.rb'], + files_to_update_without_prerelease_modifiers: ['./test_file3.kt', './test_file4.swift'], + repo_name: mock_repo_name, + github_pr_token: mock_github_pr_token, + github_token: mock_github_token, + github_rate_limit: 3, + editor: editor + ) + end.to raise_exception(StandardError) + end end describe '#available_options' do it 'has correct number of options' do - expect(Fastlane::Actions::BumpVersionUpdateChangelogCreatePrAction.available_options.size).to eq(12) + expect(Fastlane::Actions::BumpVersionUpdateChangelogCreatePrAction.available_options.size).to eq(11) end end end diff --git a/spec/actions/create_next_snapshot_version_action_spec.rb b/spec/actions/create_next_snapshot_version_action_spec.rb index e31aacc..cc003cf 100644 --- a/spec/actions/create_next_snapshot_version_action_spec.rb +++ b/spec/actions/create_next_snapshot_version_action_spec.rb @@ -9,7 +9,7 @@ it 'calls all the appropriate methods with appropriate parameters' do expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:validate_local_config_status_for_bump) - .with(nil, "bump/#{next_version}", github_pr_token) + .with("bump/#{next_version}", github_pr_token) .once expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:calculate_next_snapshot_version) .with(current_version) diff --git a/spec/helper/revenuecat_internal_helper_spec.rb b/spec/helper/revenuecat_internal_helper_spec.rb index e837170..0092788 100644 --- a/spec/helper/revenuecat_internal_helper_spec.rb +++ b/spec/helper/revenuecat_internal_helper_spec.rb @@ -202,26 +202,25 @@ before(:each) do allow(Fastlane::Actions).to receive(:sh).with('git', 'branch', '--list', 'new-branch').and_return('') allow(Fastlane::Actions).to receive(:sh).with('git', 'ls-remote', '--heads', 'origin', 'new-branch').and_return('') - allow(Fastlane::Actions::EnsureGitBranchAction).to receive(:run).with(branch: 'fake-branch') allow(Fastlane::Actions::EnsureGitStatusCleanAction).to receive(:run) end it 'fails if github_pr_token is nil' do expect do - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', nil) + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', nil) end.to raise_exception(StandardError) end it 'fails if github_pr_token is empty' do expect do - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', '') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', '') end.to raise_exception(StandardError) end it 'fails if new branch exists locally' do expect(Fastlane::Actions).to receive(:sh).with('git', 'branch', '--list', 'new-branch').and_return('new-branch').once expect do - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token') end.to raise_exception(StandardError) end @@ -230,7 +229,7 @@ .with('git', 'ls-remote', '--heads', 'origin', 'new-branch') .and_return('59f7273ae446cef04eb402b9708f0772389c59c4 refs/heads/new-branch') expect do - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token') end.to raise_exception(StandardError) end @@ -238,27 +237,17 @@ 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') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('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') - end - - it 'ensures repo is in specified branch' do - expect(Fastlane::Actions::EnsureGitBranchAction).to receive(:run).with(branch: 'fake-branch').once - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token') - end - - it 'does not check repo is in specific branch if none passed' do - expect(Fastlane::Actions::EnsureGitBranchAction).not_to receive(:run) - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(nil, 'new-branch', 'fake-github-pr-token') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token') end it 'ensures repo is in a clean state' do expect(Fastlane::Actions::EnsureGitStatusCleanAction).to receive(:run).with({}).once - Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('fake-branch', 'new-branch', 'fake-github-pr-token') + Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token') end end