Class: Fastlane::Actions::GodotExportAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



61
62
63
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 61

def self.authors
  ['Mad Science Software']
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 69

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :preset,
                                 env_name: 'FL_GODOT_PRESET',
                                 description: 'Name of the export preset in export_presets.cfg',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :project_path,
                                 env_name: 'FL_GODOT_PROJECT_PATH',
                                 description: 'Directory containing project.godot',
                                 type: String,
                                 default_value: '.'),
    FastlaneCore::ConfigItem.new(key: :godot_binary,
                                 env_name: 'FL_GODOT_BINARY',
                                 description: 'Path to the Godot binary',
                                 type: String,
                                 default_value: 'godot'),
    FastlaneCore::ConfigItem.new(key: :output_path,
                                 env_name: 'FL_GODOT_OUTPUT_PATH',
                                 description: 'Where to write the exported artifact (defaults to the preset export_path), relative to the project',
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :debug,
                                 env_name: 'FL_GODOT_DEBUG',
                                 description: 'Export a debug build instead of a release build',
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :import_first,
                                 env_name: 'FL_GODOT_IMPORT_FIRST',
                                 description: 'Run a headless --import before exporting (a stale import cache aborts exports)',
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 env_name: 'FL_GODOT_VERBOSE',
                                 description: 'Pass --verbose to Godot',
                                 type: Boolean,
                                 default_value: false)
  ]
end

.descriptionObject



53
54
55
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 53

def self.description
  'Export a Godot project headlessly using an export preset'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 108

def self.is_supported?(platform)
  true
end

.outputObject



65
66
67
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 65

def self.output
  [['GODOT_EXPORT_OUTPUT', 'Absolute path to the exported artifact']]
end

.return_valueObject



57
58
59
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 57

def self.return_value
  'Absolute path to the exported artifact (for iOS, the generated Xcode project)'
end

.run(params) ⇒ Object



8
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
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 8

def self.run(params)
  godot = params[:godot_binary]
  project_path = File.expand_path(params[:project_path])
  preset_name = params[:preset]

  UI.user_error!("No project.godot in #{project_path}") unless File.exist?(File.join(project_path, 'project.godot'))

  version = Helper::GodotHelper.godot_version(godot)
  UI.message("Godot #{version}")

  cfg_path = File.join(project_path, 'export_presets.cfg')
  preset = Helper::GodotHelper.find_preset(cfg_path, preset_name)
  Helper::GodotHelper.verify_templates!(version, preset[:platform])

  output_path = params[:output_path] || preset[:export_path]
  UI.user_error!("Preset '#{preset_name}' has no export_path and no output_path was given") if output_path.nil? || output_path.empty?
  absolute_output = File.expand_path(output_path, project_path)
  FileUtils.mkdir_p(File.dirname(absolute_output))

  if params[:import_first]
    UI.message('Importing project resources (stale import caches abort exports)…')
    Actions.sh("#{godot.shellescape} --headless --path #{project_path.shellescape} --import")
  end

  export_flag = params[:debug] ? '--export-debug' : '--export-release'
  command = [
    godot.shellescape,
    '--headless',
    '--path', project_path.shellescape,
    export_flag, preset_name.shellescape,
    absolute_output.shellescape
  ]
  command << '--verbose' if params[:verbose]

  UI.message("Exporting preset '#{preset_name}' (#{preset[:platform]}) -> #{absolute_output}")
  Actions.sh(command.join(' '))

  # Godot has historically exited 0 on some export failures; trust the artifact, not the exit code.
  UI.user_error!("Export claimed success but produced nothing at #{absolute_output}") unless File.exist?(absolute_output)

  UI.success("Exported #{preset[:platform]} build: #{absolute_output}")
  Actions.lane_context[SharedValues::GODOT_EXPORT_OUTPUT] = absolute_output
  absolute_output
end