Class: Fastlane::Actions::AnnaiUploadToCloudflareAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb

Class Method Summary collapse

Class Method Details

.available_optionsObject



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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb', line 101

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :flavor,
                                 description: "Flavor(s) to deploy (comma-separated). Defaults to all Web flavors",
                                 optional: true,
                                 default_value: nil),
    FastlaneCore::ConfigItem.new(key: :spec_file,
                                 description: "Path to annspec.yaml (relative to Flutter root). Defaults to standard discovery",
                                 optional: true,
                                 default_value: nil),
    FastlaneCore::ConfigItem.new(key: :clean,
                                 description: "Run clean build before deploying",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :main_file,
                                 description: "Path to the main Dart file",
                                 default_value: "lib/main.dart"),
    FastlaneCore::ConfigItem.new(key: :build_config,
                                 description: "Flutter build configuration ('release', 'profile', 'debug')",
                                 optional: true,
                                 default_value: "release"),
    FastlaneCore::ConfigItem.new(key: :skip_compile,
                                 description: "Skip compilation step",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :skip_sound_null_safety,
                                 description: "Skip sound null safety during compilation",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :project_name,
                                 description: "Cloudflare Pages project name (overrides annspec.yaml)",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :account_id,
                                 description: "Cloudflare account ID (overrides annspec.yaml and CLOUDFLARE_ACCOUNT_ID env var)",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :branch,
                                 description: "Cloudflare Pages branch (overrides annspec.yaml, default: 'main')",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :mode,
                                 description: "Deployment mode: 'pages' or 'workers' (overrides annspec.yaml, default: 'pages')",
                                 optional: true,
                                 type: String),
  ].compact
end

.descriptionObject



149
150
151
# File 'lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb', line 149

def self.description
  "Deploy one or all Web flavors to Cloudflare Pages or Cloudflare Workers"
end

.example_codeObject



157
158
159
160
161
162
163
# File 'lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb', line 157

def self.example_code
  'ann_upload_to_cloudflare(
    flavor: "ledger_in,ledger_us",
    build_config: "release",
    skip_compile: false
  )'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb', line 153

def self.is_supported?(platform)
  platform == :web
end

.run(params) ⇒ Object



9
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
# File 'lib/fastlane/plugin/ann_flavor_flutter/actions/ann_upload_to_cloudflare_action.rb', line 9

def self.run(params)
  platform = :web
  spec_file = params[:spec_file]

  annai_lanes = FastlaneFlutterFlavor::AnnaiLanes.new(
    lane: self,
    platform: platform,
    spec_file: 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

  if params[:clean]
    UI.header("๐Ÿงน Cleaning builds as requested...")
    begin
      annai_lanes.clean_build
    rescue => e
      UI.error("Failed to perform clean build: #{e.message}")
      status_manager.logError("All", "annai_clean_build", platform, e.message)
    end
  end

  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 deploy")
    annai_lanes.finalize
    return
  end

  all_flavor_names = flavors_hash.keys

  requested_flavor = params[:flavor]
  if requested_flavor && !requested_flavor.to_s.empty?
    requested_flavors = requested_flavor.to_s.split(',').map(&:strip).reject(&:empty?)
    invalid = requested_flavors.reject { |f| all_flavor_names.include?(f) }
    if invalid.any?
      UI.user_error!("Unknown flavor(s): #{invalid.join(', ')}. Available: #{all_flavor_names.join(', ')}")
    end
    flavors_to_deploy = requested_flavors
  else
    flavors_to_deploy = all_flavor_names
  end

  UI.header("Deploying to Cloudflare. Flavors: #{flavors_to_deploy.join(', ')}")

  any_failed = false

  flavors_to_deploy.each do |flavor_key|
    flavor = flavor_key.to_s
    final_main_file = spec_loader.get_main_file(platform, flavor) || params[:main_file]

    UI.message("๐Ÿš€ Deploying flavor: #{flavor}")

    begin
      success = annai_lanes.upload_to_cloudflare(
        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],
        project_name: params[:project_name],
        account_id: params[:account_id],
        branch: params[:branch],
        mode: params[:mode],
      )

      if success
        UI.success("โœ… Deployed #{flavor} to Cloudflare")
      else
        any_failed = true
        UI.error("โŒ Failed to deploy #{flavor}")
      end

    rescue => e
      status_manager.logError(flavor, "upload_to_cloudflare", platform, e.message)
      UI.error("โŒ #{flavor}: #{e.message}")
      any_failed = true
    end
  end

  annai_lanes.finalize

  if any_failed
    UI.user_error!("Cloudflare deployment failed for one or more flavors")
  else
    UI.success("๐ŸŽ‰ Successfully deployed #{flavors_to_deploy.count} flavor(s) to Cloudflare!")
  end
end