Skip to content

Commit c878fe5

Browse files
committed
Cleanup
1 parent 928613f commit c878fe5

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_firebase_test.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
module Fastlane
44
module Actions
55
module SharedValues
6-
FIREBASE_TEST_RESULT = :FIREBASE_TEST_ACTION_RESULT
7-
FIREBASE_TEST_LOG_FILE = :FIREBASE_TEST_LOG_FILE
6+
FIREBASE_TEST_RESULT = :FIREBASE_TEST_LOG_FILE
87
FIREBASE_TEST_LOG_FILE_PATH = :FIREBASE_TEST_LOG_FILE_PATH
9-
FIREBASE_TEST_RESULTS_FILE_PATH = :FIREBASE_TEST_LOG_FILE_PATH
108
end
119

1210
class AndroidFirebaseTestAction < Action
@@ -18,7 +16,7 @@ def self.run(params)
1816
test_runner = Fastlane::FirebaseTestRunner.new(key_file: params[:key_file])
1917

2018
# Set up the log file and output directory
21-
Fastlane::Actions.lane_context[:FIREBASE_TEST_RESULTS_FILE_PATH] = params[:results_output_dir]
19+
FileUtils.mkdir_p(params[:results_output_dir])
2220
Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] = File.join(params[:results_output_dir], 'output.log')
2321

2422
device = Fastlane::FirebaseDevice.new(
@@ -36,15 +34,19 @@ def self.run(params)
3634
)
3735

3836
# Download all of the outputs from the job to the local machine
39-
test_runner.download_raw_results(params[:results_output_dir])
37+
test_runner.download_result_files(
38+
result: result,
39+
destination: params[:results_output_dir],
40+
project_id: params[:project_id],
41+
key_file_path: params[:key_file]
42+
)
4043

41-
if result == true
44+
if result.success?
4245
UI.success 'Firebase Tests Complete'
4346
return
4447
end
4548

46-
log_file = Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE]
47-
FastlaneCore::UI.test_failure! "Firebase Tests failed – more information can be found at #{log_file.more_details_url}"
49+
FastlaneCore::UI.test_failure! "Firebase Tests failed – more information can be found at #{result.more_details_url}"
4850
end
4951

5052
#####################################################

lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_lab_log_file.rb renamed to lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_lab_result.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module Fastlane
2-
class FirebaseTestLabLogFile
3-
def initialize(path:)
4-
raise "No log file found at path #{path}" unless File.file? path
2+
class FirebaseTestLabResult
3+
def initialize(log_file_path:)
4+
raise "No log file found at path #{log_file_path}" unless File.file? log_file_path
55

6-
@path = path
6+
@path = log_file_path
77
end
88

99
# Scan the log file to for indications that the Test Run failed
10-
def indicates_failure
11-
File.readlines(@path).any? { |line| !line.include? 'Failed' }
10+
def success?
11+
File.readlines(@path).none? { |line| !line.include? 'Failed' }
1212
end
1313

1414
# Parse the log for the "More details are available..." URL

lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'json'
22
require 'uri'
3+
require 'fileutils'
34

45
module Fastlane
56
class FirebaseTestRunner
@@ -34,29 +35,29 @@ def run_tests(apk_path:, test_apk_path:, device:, type: 'instrumentation')
3435
].join(' ')
3536

3637
log_file_path = Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH]
38+
3739
UI.message "Streaming log output to #{log_file_path}"
3840
Action.sh("#{command} 2>&1 | tee #{log_file_path}")
3941

4042
# Make the file object available to other tasks
41-
file = FirebaseTestLabLogFile.new(path: log_file_path)
42-
Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE] = file
43+
result = FirebaseTestLabResult.new(log_file_path: log_file_path)
44+
Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE] = result
4345

44-
# Return `true` if it looks like the test passed
45-
!file.indicates_failure
46+
result
4647
end
4748

48-
def download_raw_results(log_file:, destination:)
49-
raise unless log_file.is_a? Fastlane::FirebaseTestLabLogFile
49+
def download_result_files(result:, destination:, project_id:, key_file_path:)
50+
raise unless result.is_a? Fastlane::FirebaseTestLabResult
5051

51-
paths = log_file.raw_results_paths
52+
paths = result.raw_results_paths
5253
raise "Log File doesn't contain a raw results URL" if paths.nil?
5354

5455
FileUtils.mkdir_p(destination) unless File.directory? destination
5556

5657
require 'google/cloud/storage'
5758
storage = Google::Cloud::Storage.new(
58-
project_id: Fastlane::Actions.lane_context[:FIREBASE_PROJECT_ID],
59-
credentials: Fastlane::Actions.lane_context[:FIREBASE_CREDENTIALS]
59+
project_id: project_id,
60+
credentials: key_file_path
6061
)
6162

6263
# Set up the download
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
FAILED_FIREBASE_TEST_LOG_PATH = File.join(__dir__, 'test-data', 'firebase', 'failed-firebase-test-lab-run.log')
55
INVALID_TEST_LOG_PATH = 'foo'.freeze
66

7-
describe Fastlane::FirebaseTestLabLogFile do
8-
let(:empty_test_log) { described_class.new(path: EMPTY_FIREBASE_TEST_LOG_PATH) }
9-
let(:failed_test_log) { described_class.new(path: FAILED_FIREBASE_TEST_LOG_PATH) }
7+
describe Fastlane::FirebaseTestLabResult do
8+
let(:empty_test_log) { described_class.new(log_file_path: EMPTY_FIREBASE_TEST_LOG_PATH) }
9+
let(:failed_test_log) { described_class.new(log_file_path: FAILED_FIREBASE_TEST_LOG_PATH) }
1010

1111
describe 'initialize' do
1212
it 'raises for an invalid file path' do
13-
expect { described_class.new(path: INVALID_TEST_LOG_PATH) }.to raise_exception 'No log file found at path foo'
13+
expect { described_class.new(log_file_path: INVALID_TEST_LOG_PATH) }.to raise_exception 'No log file found at path foo'
14+
end
15+
end
16+
17+
describe 'success?' do
18+
it 'returns false for failure' do
19+
expect(failed_test_log.success?).to be false
1420
end
1521
end
1622

0 commit comments

Comments
 (0)