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



99
100
101
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 99

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

.available_optionsObject



128
129
130
131
132
133
134
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
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 128

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: "BITRISE_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



78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 78

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

.descriptionObject



95
96
97
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 95

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

.fastlane_signing_propertiesObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 103

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 195

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
# File 'lib/fastlane/plugin/apadmi_grout/actions/build_apk_or_aab_action.rb', line 18

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

  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



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

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