Class: Fastlane::Actions::FlutterBuildAction

Inherits:
Action
  • Object
show all
Extended by:
FlutterActionBase
Defined in:
lib/fastlane/plugin/flutter/actions/flutter_build_action.rb

Constant Summary collapse

FASTLANE_PLATFORM_TO_BUILD =
{
  ios: 'ios',
  android: 'apk',
}

Class Method Summary collapse

Methods included from FlutterActionBase

authors, is_supported?

Class Method Details

.available_optionsObject



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
120
121
122
123
124
# File 'lib/fastlane/plugin/flutter/actions/flutter_build_action.rb', line 81

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :build,
      env_name: 'FL_FLUTTER_BUILD',
      description: 'Type of Flutter build (e.g. apk, appbundle, ios)',
      optional: true,
      type: String,
    ),
    FastlaneCore::ConfigItem.new(
      key: :debug,
      env_name: 'FL_FLUTTER_DEBUG',
      description: 'Build a Debug version of the app if true',
      optional: true,
      type: Boolean,
      default_value: false,
    ),
    FastlaneCore::ConfigItem.new(
      key: :codesign,
      env_name: 'FL_FLUTTER_CODESIGN',
      description: 'Set to false to skip iOS app signing. This may be ' \
      'useful e.g. on CI or when signed later by Fastlane "sigh"',
      optional: true,
      type: Boolean,
    ),
    FastlaneCore::ConfigItem.new(
      key: :build_number,
      env_name: 'FL_FLUTTER_BUILD_NUMBER',
      description: 'Override build number specified in pubspec.yaml',
      optional: true,
      type: Integer,
    ),
    FastlaneCore::ConfigItem.new(
      key: :build_name,
      env_name: 'FL_FLUTTER_BUILD_NAME',
      description: <<-'DESCRIPTION',
        Override build name specified in pubspec.yaml.
        NOTE: for App Store, build name must be in the format of at most 3
              integeres separated by a dot (".").
      DESCRIPTION
      optional: true,
    ),
  ]
end

.categoryObject



73
74
75
# File 'lib/fastlane/plugin/flutter/actions/flutter_build_action.rb', line 73

def self.category
  :building
end

.descriptionObject



69
70
71
# File 'lib/fastlane/plugin/flutter/actions/flutter_build_action.rb', line 69

def self.description
  'Run "flutter build" to build a Flutter application'
end

.return_valueObject



77
78
79
# File 'lib/fastlane/plugin/flutter/actions/flutter_build_action.rb', line 77

def self.return_value
  'A path to the built file, if available'
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/flutter/actions/flutter_build_action.rb', line 19

def self.run(params)
  # "flutter build" args list.
  build_args = []

  if params[:build]
    build_args.push(params[:build])
  else
    if fastlane_platform = (lane_context[SharedValues::PLATFORM_NAME] ||
                            lane_context[SharedValues::DEFAULT_PLATFORM])
      build_args.push(FASTLANE_PLATFORM_TO_BUILD[fastlane_platform])
    else
      UI.user_error!('flutter_build action "build" parameter is not ' \
      'specified and cannot be inferred from Fastlane context.')
    end
  end

  if params[:debug]
    build_args.push('--debug')
  end

  if params[:codesign] == false
    build_args.push('--no-codesign')
  end

  if build_number = (params[:build_number] ||
                     lane_context[SharedValues::BUILD_NUMBER])
    build_args.push('--build-number', build_number.to_s)
  end

  if build_name = (params[:build_name] ||
                   lane_context[SharedValues::VERSION_NUMBER])
    build_args.push('--build-name', build_name.to_s)
  end

  Helper::FlutterHelper.flutter('build', *build_args) do |status, res|
    if status.success?
      if res =~ /^Built (.*?)(:? \([^)]*\))?\.$/
        lane_context[SharedValues::FLUTTER_OUTPUT] =
          File.absolute_path($1)
      else
        UI.important('Cannot parse built file path from "flutter build"')
      end
    end
    # Tell upstream to NOT ignore error.
    false
  end

  lane_context[SharedValues::FLUTTER_OUTPUT]
end