Class: Fastlane::Actions::GodotSetVersionAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



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

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

.available_optionsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/godot/actions/godot_set_version_action.rb', line 61

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :version,
                                 env_name: 'FL_GODOT_VERSION',
                                 description: "Explicit version ('1.2.0') or a semantic bump: major, minor, patch",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 env_name: 'FL_GODOT_BUILD_NUMBER',
                                 description: "Explicit build number or 'increment'",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :from_git,
                                 env_name: 'FL_GODOT_VERSION_FROM_GIT',
                                 description: 'Derive version from the latest git tag (v1.2.0 -> 1.2.0) and build number from the commit count',
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :project_path,
                                 env_name: 'FL_GODOT_PROJECT_PATH',
                                 description: 'Directory containing project.godot',
                                 type: String,
                                 default_value: '.')
  ]
end

.descriptionObject



49
50
51
# File 'lib/fastlane/plugin/godot/actions/godot_set_version_action.rb', line 49

def self.description
  'Write the version name and build number into every preset in export_presets.cfg, keeping platforms in sync'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/fastlane/plugin/godot/actions/godot_set_version_action.rb', line 86

def self.is_supported?(platform)
  true
end

.return_valueObject



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

def self.return_value
  'Hash with the applied :version_name and :version_code'
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
# File 'lib/fastlane/plugin/godot/actions/godot_set_version_action.rb', line 8

def self.run(params)
  project_path = File.expand_path(params[:project_path])
  cfg_path = File.join(project_path, 'export_presets.cfg')

  if params[:from_git]
    UI.user_error!('Pass either from_git or version/build_number, not both') if params[:version] || params[:build_number]
    target = Helper::GodotVersions.from_git(project_path)
  else
    UI.user_error!('Nothing to do — pass version:, build_number:, or from_git: true') unless params[:version] || params[:build_number]
    current = Helper::GodotVersions.read(cfg_path)
    target = { version_name: nil, version_code: nil }
    if (requested = params[:version])
      target[:version_name] =
        if %w[major minor patch].include?(requested)
          Helper::GodotVersions.bump(current[:version_name], requested)
        elsif requested.match?(/\A\d+\.\d+(\.\d+)?\z/)
          requested
        else
          UI.user_error!("version must be X.Y[.Z] or major/minor/patch, got '#{requested}'")
        end
    end
    if (requested = params[:build_number])
      target[:version_code] =
        if requested == 'increment'
          (current[:version_code] || 0) + 1
        elsif requested.match?(/\A\d+\z/)
          requested.to_i
        else
          UI.user_error!("build_number must be an integer or 'increment', got '#{requested}'")
        end
    end
  end

  Helper::GodotVersions.write(cfg_path, version_name: target[:version_name], version_code: target[:version_code])
  applied = Helper::GodotVersions.read(cfg_path)
  UI.success("Version is now #{applied[:version_name]} (build #{applied[:version_code]})")
  Actions.lane_context[SharedValues::GODOT_VERSION_NAME] = applied[:version_name]
  Actions.lane_context[SharedValues::GODOT_VERSION_CODE] = applied[:version_code]
  applied
end