Class: Fastlane::Actions::FlutterVersionAction

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

Overview

The top-level plugin interface

Class Method Summary collapse

Class Method Details

.authorsObject



50
51
52
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 50

def self.authors
  ['tianhaoz95']
end

.available_optionsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 68

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :pubspec_location,
      env_name: 'PUBSPEC_LOCATION',
      description: 'The location of pubspec.yml',
      optional: true,
      type: String,
      default_value: '../pubspec.yaml'
    ),
    FastlaneCore::ConfigItem.new(
      key: :should_omit_version_code,
      env_name: 'SHOULD_OMIT_VERSION_CODE',
      description: 'If the version code should be omitted for projects that do not use a version code',
      optional: true,
      type: Boolean,
      default_value: false
    )
  ]
end

.descriptionObject



46
47
48
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 46

def self.description
  'A plugin to retrieve versioning information for Flutter projects.'
end

.detailsObject



61
62
63
64
65
66
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 61

def self.details
  "The plugin reads and parses pubspec.yml of a Flutter
  project and composes the versioning information into
  structured data to be consumed by various releasing
  automations."
end

.is_supported?(_platform) ⇒ Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


90
91
92
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 90

def self.is_supported?(_platform)
  true
end

.return_valueObject



54
55
56
57
58
59
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 54

def self.return_value
  [
    ['VERSION_CODE', 'The version code'],
    ['VERSION_NAME', 'The verison name']
  ]
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/flutter_version/actions/flutter_version_action.rb', line 11

def self.run(params)
  pubspec_location = params[:pubspec_location]
  should_omit_version_code = params[:should_omit_version_code]
  begin
    pubspec = YAML.load_file(pubspec_location)
  # rubocop:disable Style/RescueStandardError
  rescue
    raise 'Read pubspec.yaml failed'
  end
  # rubocop:enable Style/RescueStandardError
  version = pubspec['version']
  UI.message('The full version is: '.dup.concat(version))
  has_version_code_pattern = version.include?('+')
  if should_omit_version_code && has_version_code_pattern
    raise 'Version code omitted but verson code indicator (+) found in pubspec.yml'
  end
  if !should_omit_version_code && !has_version_code_pattern
    raise 'Verson code indicator (+) not found in pubspec.yml'
  end

  version_sections = if should_omit_version_code
                       [version, 'NOT_FOUND']
                     else
                       version.split('+')
                     end
  version_name = version_sections[0]
  version_code = version_sections[1]
  UI.message('The version name: '.dup.concat(version_name))
  UI.message('The version code: '.dup.concat(version_code))
  {
    'version_code' => version_code,
    'version_name' => version_name
  }
end