From a748da6a247d3c63af3314ae743b1673c4e73fd9 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 08:53:31 +0100 Subject: [PATCH 1/2] Remove custom check for CI in favor of using Fastlane's one --- .../plugin/wpmreleasetoolkit/models/file_reference.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb b/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb index 243517c33..ed23e3ffd 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb @@ -10,10 +10,7 @@ def initialize(params = {}) end def source_contents - # TODO: This works only on CircleCI. I chose this variable because it's the one checked by Fastlane::is_ci. - # Fastlane::is_ci doesn't work here, so reimplementing the code has been necessary. - # (This should be updated if we change CI or if fastlane is updated.) - return File.read(secrets_repository_file_path) unless self.encrypt || ENV.key?('CIRCLECI') + return File.read(secrets_repository_file_path) unless self.encrypt || FastlaneCore::Helper.is_ci? return nil unless File.file?(encrypted_file_path) encrypted = File.read(encrypted_file_path) From 1f5754239f27b800237296a2e05ec032a5f1d6fd Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 10:24:23 +0100 Subject: [PATCH 2/2] Account for `FastlaneCore::Helper:is_ci?` usage in tests --- spec/file_reference_spec.rb | 14 ++++++-------- spec/spec_helper.rb | 18 ------------------ 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/spec/file_reference_spec.rb b/spec/file_reference_spec.rb index 92eb9793b..357f97325 100644 --- a/spec/file_reference_spec.rb +++ b/spec/file_reference_spec.rb @@ -69,19 +69,17 @@ describe '#source_contents' do it 'gets the contents from the secrets repo' do - set_circle_env(false) do - allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') - expect(subject.source_contents).to eq('source contents') - end + allow(FastlaneCore::Helper).to receive(:is_ci?).and_return(false) + allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') + expect(subject.source_contents).to eq('source contents') end end describe '#source_contents on ci' do it 'gets the contents from the secrets repo' do - set_circle_env(true) do - allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') - expect(subject.source_contents).to eq(nil) - end + allow(FastlaneCore::Helper).to receive(:is_ci?).and_return(true) + allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') + expect(subject.source_contents).to eq(nil) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8bc4ad62d..10b24d2b4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,24 +25,6 @@ module SpecHelper config.filter_run_when_matching :focus end -def set_circle_env(define_ci) - is_ci = ENV.key?('CIRCLECI') - orig_circle_ci = ENV['CIRCLECI'] - if define_ci - ENV['CIRCLECI'] = 'true' - else - ENV.delete 'CIRCLECI' - end - - yield -ensure - if is_ci - ENV['CIRCLECI'] = orig_circle_ci - else - ENV.delete 'CIRCLECI' - end -end - # Allows Action.sh to be executed even when running in a test environment (where Fastlane's code disables it by default) # def allow_fastlane_action_sh