Skip to content

Commit

Permalink
Merge pull request #12 from RevenueCat/not-check-current-branch-when-…
Browse files Browse the repository at this point in the history
…preparing-next-release

Not validate current branch when creating next snapshot
  • Loading branch information
tonidero authored Aug 9, 2022
2 parents 6f4d8e1 + 05f714e commit a271972
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ def self.run(params)
github_pr_token = params[:github_pr_token]
files_to_update = params[:files_to_update]
files_to_update_without_prerelease_modifiers = params[:files_to_update_without_prerelease_modifiers]
branch = params[:branch]

next_version_snapshot = Helper::RevenuecatInternalHelper.calculate_next_snapshot_version(previous_version_number)
new_branch_name = "bump/#{next_version_snapshot}"

Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(branch, new_branch_name, github_pr_token)
Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump(nil, new_branch_name, github_pr_token)

Helper::RevenuecatInternalHelper.create_new_branch_and_checkout(new_branch_name)

Expand Down Expand Up @@ -64,12 +63,7 @@ def self.available_options
description: "Files that contain the version number without release modifiers and need to have it updated",
optional: true,
default_value: [],
type: Array),
FastlaneCore::ConfigItem.new(key: :branch,
description: "Allows to execute the action from the given branch",
optional: true,
default_value: "main",
type: String)
type: Array)
]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def self.create_pr_to_main(title, body, repo_name, github_pr_token)
)
end

def self.validate_local_config_status_for_bump(branch, new_branch, github_pr_token)
def self.validate_local_config_status_for_bump(current_branch, 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")
UI.error("Please make a fastlane/.env file from the fastlane/.env.SAMPLE template")
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: branch)
Actions::EnsureGitBranchAction.run(branch: current_branch) unless current_branch.nil?
Actions::EnsureGitStatusCleanAction.run({})
end

Expand Down
8 changes: 3 additions & 5 deletions spec/actions/create_next_snapshot_version_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
describe '#run' do
let(:github_pr_token) { 'fake-github-pr-token' }
let(:repo_name) { 'fake-repo-name' }
let(:branch) { 'branch' }
let(:current_version) { '1.12.0' }
let(:next_version) { '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)
.with(branch, "bump/#{next_version}", github_pr_token)
.with(nil, "bump/#{next_version}", github_pr_token)
.once
expect(Fastlane::Helper::RevenuecatInternalHelper).to receive(:calculate_next_snapshot_version)
.with(current_version)
Expand All @@ -31,15 +30,14 @@
repo_name: repo_name,
github_pr_token: github_pr_token,
files_to_update: ['./test_file.sh', './test_file2.rb'],
files_to_update_without_prerelease_modifiers: ['./test_file4.swift', './test_file5.kt'],
branch: branch
files_to_update_without_prerelease_modifiers: ['./test_file4.swift', './test_file5.kt']
)
end
end

describe '#available_options' do
it 'has correct number of options' do
expect(Fastlane::Actions::CreateNextSnapshotVersionAction.available_options.size).to eq(6)
expect(Fastlane::Actions::CreateNextSnapshotVersionAction.available_options.size).to eq(5)
end
end
end
5 changes: 5 additions & 0 deletions spec/helper/revenuecat_internal_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ def setup_stubs
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')
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')
Expand Down

0 comments on commit a271972

Please sign in to comment.