Class: Fastlane::Actions::BuildApkOrAabAction

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

Overview

Build an APK or AAB binary

Class Method Summary collapse

Class Method Details

.authorsObject



106
107
108
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 106

def self.authors
  ["samdc@apadmi.com", "jamesr@apadmi.com"]
end

.available_optionsObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 135

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :client_name,
                                 description: "The name of the client",
                                 env_name: "CLIENT_NAME",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid client name") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :product_name,
                                 description: "The name of the product",
                                 env_name: "PRODUCT_NAME",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid product name") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :version,
                                 description: "The app version e.g. 0.1.0",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid version name") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 description: "The app build number e.g. 3948",
                                 default_value: Apadmi::Grout::GitUtils.number_of_commits,
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid build number") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :output_name,
                                 description: "The desired name of the output file",
                                 default_value: nil,
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :output_directory,
                                 description: "The desired output location",
                                 env_name: "DEPLOY_DIR",
                                 type: String,
                                 default_value: "#{Apadmi::Grout::GitUtils.git_root}/build",
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid output directory") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :gradle_command,
                                 description: "The gradle command e.g assembleRelease",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("Didn't pass a valid gradle command") unless value
                                 end,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :inject_signing_creds,
                                 description: "Whether or not to inject the signing credentials",
                                 type: Boolean,
                                 default_value: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :additional_config_properties,
                                 description: "Config properties to be passed through to gradle",
                                 type: Hash,
                                 default_value: {},
                                 optional: true)
  ] + Fastlane::Actions::GradleAction.available_options + fastlane_signing_properties
end

.config_properties(options) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 85

def self.config_properties(options)
  {
    "versionCode" => options[:build_number],
    "versionName" => options[:version],
    "commitHash" => ENV["GIT_COMMIT_HASH"] || Apadmi::Grout::GitUtils.commit_hash
  }.merge(options[:additional_config_properties])
end

.descriptionObject



102
103
104
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 102

def self.description
  "Builds an APK or AAB depending on the command"
end

.fastlane_signing_propertiesObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 110

def self.fastlane_signing_properties
  [
    FastlaneCore::ConfigItem.new(key: :keystore_path,
                                 description: "Path to the keystore file",
                                 env_name: "ANDROID_KEYSTORE_PATH",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :keystore_password,
                                 description: "Keystore password",
                                 env_name: "ANDROID_KEYSTORE_PASSWORD",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :keystore_alias,
                                 description: "Keystore alias",
                                 env_name: "ANDROID_KEY_ALIAS",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :key_password,
                                 description: "Private key password",
                                 env_name: "ANDROID_KEY_PASSWORD",
                                 type: String,
                                 optional: true)
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 202

def self.is_supported?(platform)
  platform == :android
end

.run(params) ⇒ Object



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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 18

def self.run(params)
  logger = FastLane::FastlaneLogger.new

  if params[:build_number].to_i <= 0 && Apadmi::Grout::GitUtils.is_shallow_clone?
    raise %(
        Build number is 0 and repo is a shallow clone. Unlikely this is intentional.
        Set build_number param to > 0 to suppress this exception.
      )
  end

  build_type = Apadmi::Grout::CommandParsingUtils.determine_build_type(params[:gradle_command])
  variant = Apadmi::Grout::CommandParsingUtils.determine_variant(params[:gradle_command])
  output_name = params[:output_name] || (Apadmi::Grout::FilenameUtils.binary_output_filename(
    client_name: params[:client_name],
    product_name: params[:product_name],
    platform: "Android",
    version: params[:version],
    build_number: params[:build_number],
    suffix: variant
  ) + ".#{build_type}")

  logger.message("Generating #{build_type}: #{output_name}")

  new_params = params
  new_params[:task] = params[:gradle_command]
  new_params[:properties] = signing_properties(params) if params[:inject_signing_creds]
  new_params[:system_properties] = config_properties(params)

  Fastlane::Actions::GradleAction.run(new_params)

  artifact = case build_type
             when AndroidBuildType::APK
               lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
             when AndroidBuildType::AAB
               lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]
             else
               raise "Something terrible has happened, could not find artifact path"
             end

  new_artifact_path = "#{params[:output_directory]}/#{output_name}"
  File.rename(artifact, new_artifact_path)
  logger.success("Generated #{output_name} in #{params[:output_directory]}")

  mapping_path = lane_context[SharedValues::GRADLE_MAPPING_TXT_OUTPUT_PATH]
  # rubocop:disable Style/StringConcatenation
  mapping_filename = Apadmi::Grout::FilenameUtils.binary_output_filename(
    client_name: params[:client_name],
    product_name: params[:product_name],
    platform: "Android",
    version: params[:version],
    build_number: params[:build_number],
    suffix: "#{variant}-mapping"
  ) + ".txt"
  # rubocop:enable Style/StringConcatenation
  new_mapping_path = "#{params[:output_directory]}/#{mapping_filename}"
  if !mapping_path.nil? && File.exist?(mapping_path)
    File.rename(mapping_path, new_mapping_path)
    logger.success("Generated #{mapping_filename} in #{params[:output_directory]}")
    lane_context[SharedValues::ANDROID_MAPPING_FILE_PATH] = new_mapping_path
  else
    logger.message("No mapping file found")
    lane_context[SharedValues::ANDROID_MAPPING_FILE_PATH] = nil
  end

  new_artifact_path
end

.signing_properties(params) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 93

def self.signing_properties(params)
  {
    "android.injected.signing.store.file" => params[:keystore_path],
    "android.injected.signing.store.password" => params[:keystore_password],
    "android.injected.signing.key.alias" => params[:keystore_alias],
    "android.injected.signing.key.password" => params[:key_password]
  }
end