Skip to content

Commit e2f781e

Browse files
committed
Support test_case_ids and test_case_ids_file
Bump version to 0.10.0
1 parent 7113e92 commit e2f781e

File tree

4 files changed

+123
-27
lines changed

4 files changed

+123
-27
lines changed

lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ def self.run(params)
8888
test_devices =
8989
get_value_from_value_or_file(params[:test_devices], params[:test_devices_file])
9090
if present?(test_devices)
91-
UI.message("🤖 Starting automated tests. Note: This feature is in beta.")
91+
test_cases =
92+
string_to_array(get_value_from_value_or_file(params[:test_case_ids], params[:test_case_ids_file]))&.map { |id| "#{app_name}/testCases/#{id}" }
9293
test_password = test_password_from_params(params)
93-
release_test = test_release(alpha_client, release, test_devices, params[:test_username], test_password, params[:test_username_resource], params[:test_password_resource])
94+
release_tests = test_release(alpha_client, release, test_devices, test_cases, params[:test_username], test_password, params[:test_username_resource], params[:test_password_resource])
9495
unless params[:test_non_blocking]
95-
poll_test_finished(alpha_client, release_test.name)
96+
poll_test_finished(alpha_client, release_tests)
9697
end
9798
end
9899

@@ -359,7 +360,10 @@ def self.distribute_release(client, release, request)
359360
end
360361
end
361362

362-
def self.test_release(alpha_client, release, test_devices, username = nil, password = nil, username_resource = nil, password_resource = nil)
363+
def self.test_release(alpha_client, release, test_devices, test_cases, username = nil, password = nil, username_resource = nil, password_resource = nil)
364+
if present?(test_cases) && (!username_resource.nil? || !password_resource.nil?)
365+
UI.user_error!("Password and username resource names are not supported for the AI testing agent.")
366+
end
363367
if username_resource.nil? ^ password_resource.nil?
364368
UI.user_error!("Username and password resource names for automated tests need to be specified together.")
365369
end
@@ -401,37 +405,60 @@ def self.test_release(alpha_client, release, test_devices, username = nil, passw
401405
)
402406
end
403407

404-
release_test =
405-
Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaReleaseTest.new(
406-
login_credential: login_credential,
407-
device_executions: device_executions
408-
)
409-
alpha_client.create_project_app_release_test(release.name, release_test)
408+
UI.message("🤖 Starting automated tests. Note: This feature is in beta.")
409+
release_tests = []
410+
if present?(test_cases)
411+
test_cases.each do |tc|
412+
release_test =
413+
Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaReleaseTest.new(
414+
login_credential: login_credential,
415+
device_executions: device_executions,
416+
test_case: tc
417+
)
418+
release_tests.push(alpha_client.create_project_app_release_test(release.name, release_test))
419+
end
420+
else
421+
release_test =
422+
Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaReleaseTest.new(
423+
login_credential: login_credential,
424+
device_executions: device_executions
425+
)
426+
release_tests.push(alpha_client.create_project_app_release_test(release.name, release_test))
427+
end
428+
release_tests
410429
rescue Google::Apis::Error => err
411430
UI.crash!(err)
412431
end
413432

414-
def self.poll_test_finished(alpha_client, release_test_name)
433+
def self.poll_test_finished(alpha_client, release_tests)
434+
release_test_names = release_tests.map(&:name)
415435
TEST_MAX_POLLING_RETRIES.times do
416-
UI.message("⏳ The automated test results are pending.")
436+
UI.message("⏳ #{release_test_names.size} automated test results are pending.")
417437
sleep(TEST_POLLING_INTERVAL_SECONDS)
418-
release_test = alpha_client.get_project_app_release_test(release_test_name)
419-
if release_test.device_executions.all? { |e| e.state == 'PASSED' }
420-
UI.success("✅ Passed automated test(s).")
421-
return
422-
end
423-
release_test.device_executions.each do |de|
424-
case de.state
425-
when 'PASSED', 'IN_PROGRESS'
426-
next
427-
when 'FAILED'
428-
UI.test_failure!("Automated test failed for #{device_to_s(de.device)}: #{de.failed_reason}.")
429-
when 'INCONCLUSIVE'
430-
UI.test_failure!("Automated test inconclusive for #{device_to_s(de.device)}: #{de.inconclusive_reason}.")
438+
release_test_names.delete_if do |release_test_name|
439+
release_test = alpha_client.get_project_app_release_test(release_test_name)
440+
if release_test.device_executions.all? { |e| e.state == 'PASSED' }
441+
true
431442
else
432-
UI.test_failure!("Unsupported automated test state for #{device_to_s(de.device)}: #{de.state}.")
443+
release_test.device_executions.each do |de|
444+
case de.state
445+
when 'PASSED', 'IN_PROGRESS'
446+
next
447+
when 'FAILED'
448+
UI.test_failure!("Automated test failed for #{device_to_s(de.device)}: #{de.failed_reason}.")
449+
when 'INCONCLUSIVE'
450+
UI.test_failure!("Automated test inconclusive for #{device_to_s(de.device)}: #{de.inconclusive_reason}.")
451+
else
452+
UI.test_failure!("Unsupported automated test state for #{device_to_s(de.device)}: #{de.state}.")
453+
end
454+
end
455+
false
433456
end
434457
end
458+
if release_test_names.empty?
459+
UI.success("✅ Passed automated test(s).")
460+
return
461+
end
435462
end
436463
UI.test_failure!("It took longer than expected to process your test, please try again.")
437464
end
@@ -580,6 +607,16 @@ def self.available_options
580607
optional: false,
581608
default_value: false,
582609
type: Boolean),
610+
FastlaneCore::ConfigItem.new(key: :test_case_ids,
611+
env_name: "FIREBASEAPPDISTRO_TEST_CASE_IDS",
612+
description: "Test Case IDs, separated by commas. Note: This feature is in beta",
613+
optional: true,
614+
type: String),
615+
FastlaneCore::ConfigItem.new(key: :test_case_ids_file,
616+
env_name: "FIREBASEAPPDISTRO_TEST_CASE_IDS_FILE",
617+
description: "Path to file with containing Test Case IDs, separated by commas or newlines. Note: This feature is in beta",
618+
optional: true,
619+
type: String),
583620

584621
# Auth
585622
FastlaneCore::ConfigItem.new(key: :firebase_cli_token,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
require 'google/apis/firebaseappdistribution_v1'
22
require 'google/apis/firebaseappdistribution_v1alpha'
3+
4+
# This is partially copied from google/apis/firebaseappdistribution_v1alpha v0.9.0 (2024-12-08) based discovery document revision 20241204.
5+
# We can't depend on that version directly as long as fastlane locks google-cloud-env < 2.0.0 (to support Ruby 2.6).
6+
# Newer versions of the API clients depend on google-apis-core >= 0.15.0 which depends on googleauth ~> 1.9 which depends on google-cloud-env ~> 2.1.
7+
# See also https://github.com/fastlane/fastlane/pull/21685#pullrequestreview-2490037163
8+
module Google
9+
module Apis
10+
module FirebaseappdistributionV1alpha
11+
class GoogleFirebaseAppdistroV1alphaReleaseTest
12+
include Google::Apis::Core::Hashable
13+
14+
attr_accessor :create_time
15+
attr_accessor :device_executions
16+
attr_accessor :display_name
17+
attr_accessor :login_credential
18+
attr_accessor :name
19+
attr_accessor :test_case
20+
attr_accessor :test_state
21+
22+
def initialize(**args)
23+
update!(**args)
24+
end
25+
26+
def update!(**args)
27+
@create_time = args[:create_time] if args.key?(:create_time)
28+
@device_executions = args[:device_executions] if args.key?(:device_executions)
29+
@display_name = args[:display_name] if args.key?(:display_name)
30+
@login_credential = args[:login_credential] if args.key?(:login_credential)
31+
@name = args[:name] if args.key?(:name)
32+
@test_case = args[:test_case] if args.key?(:test_case)
33+
@test_state = args[:test_state] if args.key?(:test_state)
34+
end
35+
36+
class Representation < Google::Apis::Core::JsonRepresentation
37+
property :create_time, as: 'createTime'
38+
collection :device_executions, as: 'deviceExecutions', class: Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaDeviceExecution, decorator: Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaDeviceExecution::Representation
39+
property :display_name, as: 'displayName'
40+
property :login_credential, as: 'loginCredential', class: Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaLoginCredential, decorator: Google::Apis::FirebaseappdistributionV1alpha::GoogleFirebaseAppdistroV1alphaLoginCredential::Representation
41+
property :name, as: 'name'
42+
property :test_case, as: 'testCase'
43+
property :test_state, as: 'testState'
44+
end
45+
end
46+
end
47+
end
48+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Fastlane
22
module FirebaseAppDistribution
3-
VERSION = "0.9.1"
3+
VERSION = "0.10.0"
44
end
55
end

spec/firebase_app_distribution_action_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,19 @@ def stub_get_aab_info(integration_state = 'INTEGRATED')
631631
test_non_blocking: true
632632
})
633633
end
634+
635+
it 'passes test_case ID' do
636+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1alpha::FirebaseAppDistributionService).to receive(:create_project_app_release_test) do |_, release_name, request|
637+
expect(["#{android_app_name}/testCases/foo", "#{android_app_name}/testCases/bar", "#{android_app_name}/testCases/baz"]).to include(request.test_case)
638+
end
639+
action.run({
640+
app: android_app_id,
641+
android_artifact_path: 'path/to.apk',
642+
test_devices: 'model=model1,version=version1,locale=locale1,orientation=orientation1',
643+
test_case_ids: ['foo', 'bar', 'baz'],
644+
test_non_blocking: true
645+
})
646+
end
634647
end
635648
end
636649
end

0 commit comments

Comments
 (0)