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



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

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

.available_optionsObject



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

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),
    FastlaneCore::ConfigItem.new(key: :install_android_build_template,
                                 env_name: 'FL_GODOT_INSTALL_ANDROID_BUILD_TEMPLATE',
                                 description: "Install the project's Android Gradle build template during export (needed for Android App Bundle presets)",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :skip_version_check,
                                 env_name: 'FL_GODOT_SKIP_VERSION_CHECK',
                                 description: "Skip verifying the binary's version against the project's declared engine version",
                                 type: Boolean,
                                 default_value: false)
  ]
end

.descriptionObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 121

def self.is_supported?(platform)
  true
end

.outputObject



68
69
70
# File 'lib/fastlane/plugin/godot/actions/godot_export_action.rb', line 68

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

.return_valueObject



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

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

def self.run(params)
  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'))

  godot = Helper::GodotHelper.discover_godot_binary(params[:godot_binary])
  version = Helper::GodotHelper.godot_version(godot)
  UI.message("Godot #{version}")
  Helper::GodotHelper.verify_binary_matches_project!(version, project_path) unless params[:skip_version_check]

  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
  ]
  # Gradle-based Android exports (AABs) need the build template installed
  # into the project; Godot only installs it during an export invocation.
  command << '--install-android-build-template' if params[:install_android_build_template]
  command += [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