|
| 1 | +require 'fastlane/action' |
| 2 | +require 'open3' |
| 3 | +require 'shellwords' |
| 4 | +require 'googleauth' |
| 5 | +require_relative '../helper/firebase_app_distribution_helper' |
| 6 | +require_relative '../helper/firebase_app_distribution_error_message' |
| 7 | +require_relative '../client/firebase_app_distribution_api_client' |
| 8 | +require_relative '../helper/firebase_app_distribution_auth_client' |
| 9 | + |
| 10 | +module Fastlane |
| 11 | + module Actions |
| 12 | + class FirebaseAppDistributionGetUdidsAction < Action |
| 13 | + extend Auth::FirebaseAppDistributionAuthClient |
| 14 | + extend Helper::FirebaseAppDistributionHelper |
| 15 | + |
| 16 | + def self.run(params) |
| 17 | + auth_token = fetch_auth_token(params[:service_credentials_file], params[:firebase_cli_token]) |
| 18 | + fad_api_client = Client::FirebaseAppDistributionApiClient.new(auth_token, params[:debug]) |
| 19 | + |
| 20 | + app_id = params[:app] |
| 21 | + udids = fad_api_client.get_udids(app_id) |
| 22 | + |
| 23 | + if udids.empty? |
| 24 | + UI.important("App Distribution fetched 0 tester UDIDs. Nothing written to output file.") |
| 25 | + else |
| 26 | + write_udids_to_file(udids, params[:output_file]) |
| 27 | + UI.success("🎉 App Distribution tester UDIDs written to: #{params[:output_file]}") |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + def self.write_udids_to_file(udids, output_file) |
| 32 | + File.open(output_file, 'w') do |f| |
| 33 | + f.write("Device ID\tDevice Name\tDevice Platform\n") |
| 34 | + udids.each do |tester_udid| |
| 35 | + f.write("#{tester_udid[:udid]}\t#{tester_udid[:name]}\t#{tester_udid[:platform]}\n") |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + def self.description |
| 41 | + "Download the UDIDs of your Firebase App Distribution testers" |
| 42 | + end |
| 43 | + |
| 44 | + def self.authors |
| 45 | + ["Lee Kellogg"] |
| 46 | + end |
| 47 | + |
| 48 | + # supports markdown. |
| 49 | + def self.details |
| 50 | + "Export your testers' device identifiers in a CSV file, so you can add them your provisioning profile. This file can be imported into your Apple developer account using the Register Multiple Devices option. See the [App Distribution docs](https://firebase.google.com/docs/app-distribution/ios/distribute-console#register-tester-devices) for more info." |
| 51 | + end |
| 52 | + |
| 53 | + def self.available_options |
| 54 | + [ |
| 55 | + FastlaneCore::ConfigItem.new(key: :app, |
| 56 | + env_name: "FIREBASEAPPDISTRO_APP", |
| 57 | + description: "Your app's Firebase App ID. You can find the App ID in the Firebase console, on the General Settings page", |
| 58 | + optional: false, |
| 59 | + type: String), |
| 60 | + FastlaneCore::ConfigItem.new(key: :output_file, |
| 61 | + env_name: "FIREBASEAPPDISTRO_OUTPUT_FILE", |
| 62 | + description: "The path to the file where the tester UDIDs will be written", |
| 63 | + optional: false, |
| 64 | + type: String), |
| 65 | + FastlaneCore::ConfigItem.new(key: :firebase_cli_token, |
| 66 | + description: "Auth token for firebase cli", |
| 67 | + optional: true, |
| 68 | + type: String), |
| 69 | + FastlaneCore::ConfigItem.new(key: :service_credentials_file, |
| 70 | + description: "Path to Google service account json", |
| 71 | + optional: true, |
| 72 | + type: String), |
| 73 | + FastlaneCore::ConfigItem.new(key: :debug, |
| 74 | + description: "Print verbose debug output", |
| 75 | + optional: true, |
| 76 | + default_value: false, |
| 77 | + is_string: false) |
| 78 | + ] |
| 79 | + end |
| 80 | + |
| 81 | + def self.is_supported?(platform) |
| 82 | + [:ios].include?(platform) |
| 83 | + end |
| 84 | + |
| 85 | + def self.example_code |
| 86 | + [ |
| 87 | + <<-CODE |
| 88 | + firebase_app_distribution_get_udids( |
| 89 | + app: "1:1234567890:ios:0a1b2c3d4e5f67890", |
| 90 | + output_file: "tester_udids.txt", |
| 91 | + ) |
| 92 | + CODE |
| 93 | + ] |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | +end |
0 commit comments