From 13773d2ca53d371633088198b827a3699fe90df3 Mon Sep 17 00:00:00 2001 From: Cesar de la Vega Date: Fri, 19 May 2023 08:40:29 -0700 Subject: [PATCH] Don't ensure Git status clean when running on CI (#51) --- .../helper/revenuecat_internal_helper.rb | 15 +++++++++- .../helper/revenuecat_internal_helper_spec.rb | 28 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) 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 5d8ab7c..fe99499 100644 --- a/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb +++ b/lib/fastlane/plugin/revenuecat_internal/helper/revenuecat_internal_helper.rb @@ -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 @@ -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) diff --git a/spec/helper/revenuecat_internal_helper_spec.rb b/spec/helper/revenuecat_internal_helper_spec.rb index ef20746..83a7b8a 100644 --- a/spec/helper/revenuecat_internal_helper_spec.rb +++ b/spec/helper/revenuecat_internal_helper_spec.rb @@ -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 @@ -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