Skip to content

Commit

Permalink
Don't ensure Git status clean when running on CI (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro authored May 19, 2023
1 parent fe45299 commit 13773d2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'fastlane/actions/ensure_git_branch'
require 'fastlane/actions/ensure_git_status_clean'
require 'fastlane/actions/set_github_release'
require 'fastlane/actions/reset_git_repo'
require_relative 'versioning_helper'

module Fastlane
Expand Down Expand Up @@ -105,7 +106,19 @@ def self.validate_local_config_status_for_bump(new_branch, github_pr_token)
UI.user_error!("Could not find value for GITHUB_PULL_REQUEST_API_TOKEN")
end
ensure_new_branch_local_remote(new_branch)
Actions::EnsureGitStatusCleanAction.run({})
if UI.interactive?
Actions::EnsureGitStatusCleanAction.run(
show_diff: true
)
else
command = "git status --porcelain"
git_status = Actions.sh(command, log: true, error_callback: ->(_) {})
dirty_repo = git_status.lines.length > 0
if dirty_repo
UI.message("Git status is not clean. Resetting all files.")
Actions::ResetGitRepoAction.run(force: true)
end
end
end

def self.calculate_next_snapshot_version(current_version)
Expand Down
28 changes: 26 additions & 2 deletions spec/helper/revenuecat_internal_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@
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).to receive(:sh).with('git status --porcelain', { error_callback: anything, log: true }).and_return('')
allow(Fastlane::Actions::EnsureGitStatusCleanAction).to receive(:run)
allow(Fastlane::Actions::ResetGitRepoAction).to receive(:run).with(true)
allow(FastlaneCore::UI).to receive(:interactive?).and_return(false)
end

it 'fails if github_pr_token is nil' do
Expand Down Expand Up @@ -340,8 +343,29 @@
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
it 'ensures repo is in a clean state when running on local' do
allow(FastlaneCore::UI).to receive(:interactive?).and_return(true)
expect(Fastlane::Actions::EnsureGitStatusCleanAction).to receive(:run).with({ show_diff: true }).once
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token')
end

it 'doesnt ensure repo is clean when running on CI' do
allow(FastlaneCore::UI).to receive(:interactive?).and_return(false)
expect(Fastlane::Actions::EnsureGitStatusCleanAction).to receive(:run).with({ show_diff: true }).never
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token')
end

it 'resets repo when running on CI and there are changes' do
allow(FastlaneCore::UI).to receive(:interactive?).and_return(false)
allow(Fastlane::Actions).to receive(:sh).with('git status --porcelain', { error_callback: anything, log: true })
.and_return('M lib/fastlane/plugin/revenuecat_internal/actions/create_next_snapshot_version_action.rb')
expect(Fastlane::Actions::ResetGitRepoAction).to receive(:run).with({ force: true }).once
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token')
end

it 'doesnt reset repo when running on CI and there are no changes' do
allow(FastlaneCore::UI).to receive(:interactive?).and_return(false)
expect(Fastlane::Actions::ResetGitRepoAction).to receive(:run).with({ force: true }).never
Fastlane::Helper::RevenuecatInternalHelper.validate_local_config_status_for_bump('new-branch', 'fake-github-pr-token')
end
end
Expand Down

0 comments on commit 13773d2

Please sign in to comment.