Class: Fastlane::Actions::AnnaiUploadToFirebaseAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::AnnaiUploadToFirebaseAction
- Defined in:
- lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb
Overview
This class name dictates the action name ‘ann_upload_to_firebase’
Class Method Summary collapse
-
.available_options ⇒ Object
—————————————————- Define Parameters —————————————————-.
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
Class Method Details
.available_options ⇒ Object
Define Parameters
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb', line 136 def self. [ FastlaneCore::ConfigItem.new(key: :flavor, description: "The specific flavor(s) to deploy (comma-separated). If nil, all Web flavors are deployed", optional: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :spec_file, description: "Path to the annai spec configuration file (relative to flutter root). Defaults to standard discovery", optional: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :clean, description: "If true, runs annai_clean_build before deploying (and compiling if not skipped)", type: Boolean, default_value: false), # --- Web / Firebase Specific Parameters --- FastlaneCore::ConfigItem.new(key: :firebase_token, description: "Firebase CLI CI token for authentication (generated via 'firebase login:ci')", optional: true, env_name: "FIREBASE_TOKEN", type: String), FastlaneCore::ConfigItem.new(key: :firebase_project, description: "The Firebase Project ID to deploy to. This value overrides the 'project_id' in the annai spec file", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :main_file, description: "Path to the main dart file (used if compilation is required)", default_value: "lib/main.dart"), FastlaneCore::ConfigItem.new(key: :build_config, description: "The Flutter build configuration ('release', 'profile', or 'debug')", optional: true, default_value: "release"), FastlaneCore::ConfigItem.new(key: :skip_compile, description: "If true, skips the compilation step ('flutter build web') and assumes artifacts already exist", type: Boolean, default_value: false), FastlaneCore::ConfigItem.new(key: :skip_sound_null_safety, description: "Skips sound null safety checks during compilation (if skip_compile is false)", type: Boolean, default_value: false), ].compact end |
.description ⇒ Object
181 182 183 |
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb', line 181 def self.description "Handles compilation (optional) and deployment of one or all Web flavors to Firebase Hosting" end |
.example_code ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb', line 189 def self.example_code 'ann_upload_to_firebase( flavor: "staging,production", firebase_project: "my-custom-staging-project", # Overrides spec file build_config: "release", skip_compile: false )' end |
.is_supported?(platform) ⇒ Boolean
185 186 187 |
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb', line 185 def self.is_supported?(platform) platform == :web end |
.run(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_upload_to_firebase_action.rb', line 10 def self.run(params) platform = :web # Hardcoded platform for web hosting action_name = "ann_upload_to_firebase" requested_flavor = params[:flavor] requested_clean_build = params[:clean] spec_file = params[:spec_file] # 1. Initialize AnnaiLanes annai_lanes = FastlaneFlutterFlavor::AnnaiLanes.new( lane: self, platform: platform, # Pass platform symbol directly spec_file: spec_file # Pass optional spec_file ) status_manager = annai_lanes.instance_variable_get(:@statusManager) spec_loader = annai_lanes.instance_variable_get(:@specLoader) UI.user_error!("Internal Error: AnnaiLanes failed to initialize specLoader") unless spec_loader any_upload_failed = false # 2. Perform clean build if requested if requested_clean_build UI.header("🧹 Cleaning builds as requested...") begin annai_lanes.clean_build rescue => e UI.error("Failed to perform clean build: #{e.}. Attempting to proceed with upload") # Note: Using 'annai_clean_build' as the action name for the failure log status_manager.logError("All", "annai_clean_build", platform, "Clean build failed: #{e.}") end end # 3. Get the list of all flavors defined for the platform flavors_hash = spec_loader.get_platform_flavors(platform) if flavors_hash.empty? UI.important("No flavors found for Web in the Annai spec. Nothing to upload") annai_lanes.finalize return end all_flavor_names = flavors_hash.keys # 4. Determine which flavors to upload if requested_flavor && !requested_flavor.to_s.empty? requested_flavors = requested_flavor.to_s.split(',').map(&:strip).reject(&:empty?) # Validate all requested flavors invalid_flavors = requested_flavors.reject { |f| all_flavor_names.include?(f) } if invalid_flavors.any? UI.user_error!("The following requested flavor(s) are not found in the Annai spec for Web: #{invalid_flavors.join(', ')}. Available flavors: #{all_flavor_names.join(', ')}") end flavors_to_upload = requested_flavors else flavors_to_upload = all_flavor_names end UI.header("Starting Firebase Hosting upload. Flavors to process: #{flavors_to_upload.join(', ')}") # 5. Loop through each flavor and upload flavors_to_upload.each do |flavor_key| flavor = flavor_key.to_s # Get values from spec, falling back to parameters # Note: firebase_project is intentionally NOT loaded from spec here, # as it's passed directly to AnnaiLanes which handles the prioritization # (CLI param > Spec file). final_main_file = spec_loader.get_main_file(platform, flavor) || params[:main_file] UI.("🚀 Preparing **#{flavor}** flavor...") # Use 'upload_to_firebase' as the consistent action name for flavor-specific failures flavor_action_name = "upload_to_firebase" begin # Web Upload Logic (upload_to_firebase) success = annai_lanes.upload_to_firebase( flavor: flavor, main_file: final_main_file, build_config: params[:build_config], skip_compile: params[:skip_compile], skip_sound_null_safety: params[:skip_sound_null_safety], firebase_project: params[:firebase_project], firebase_token: params[:firebase_token] || ENV["FIREBASE_TOKEN"], ) if success UI.success("✅ Successfully deployed flavor: #{flavor}") else # If upload_to_firebase returns false, flag the overall failure. if !status_manager.instance_variable_get(:@status).key?([flavor, flavor_action_name, platform.to_s]) raise "Deployment failed for flavor '#{flavor}'" else raise "Deployment failed for flavor '#{flavor}' (error logged previously)" end end rescue => e # Failure handling: Log the error and continue if !status_manager.instance_variable_get(:@status).key?([flavor, flavor_action_name, platform.to_s]) status_manager.logError(flavor, flavor_action_name, platform, e.) end UI.error("❌ Failed to deploy flavor: #{flavor}. Continuing to next flavor...") any_upload_failed = true # Continue to the next flavor end end # 6. Final Reporting and Status Check annai_lanes.finalize if any_upload_failed UI.user_error!("Deployment failed for one or more flavors. See the Annai Fastlane summary above") else UI.success("🎉 Successfully deployed all #{flavors_to_upload.count} requested flavor(s) to Firebase Hosting!") end end |