-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastfile
More file actions
431 lines (361 loc) · 13.9 KB
/
Fastfile
File metadata and controls
431 lines (361 loc) · 13.9 KB
1
2
3
4
5
6
7
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
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
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
125
126
127
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
fastlane_require 'semantic'
fastlane_require 'safe_yaml'
fastlane_require 'mini_magick'
default_platform(:android)
config_json = read_json(
json_path: "./buildsystem/config.json"
)
zappli_api_token = config_json[:zappli_api_key]
platform :android do
desc "Building generic by json configuration"
lane :generic do |values|
flavor_parameter = values[:id]
flavors = config_json[:flavors]
if flavor_parameter == "all"
UI.message "Compiling all flavors"
flavors.each do |child|
buildWithJson(child)
end
else
flavors.each do |child|
if child[:id] == flavor_parameter
UI.message "Found flavor to build"
buildWithJson(child)
end
end
end
end
desc "Build flavor with json config"
lane :buildWithJson do |options|
flavor_name = options[:flavor_name]
sign_conf = options[:sign_conf]
module_name = options[:module_name]
gradle(
task: "#{module_name}:assemble",
flavor: flavor_name.capitalize(),
build_type: sign_conf.capitalize()
)
gradle_path = "#{lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]}"
distributeApp(options: options, gradle_path: gradle_path)
end
desc "Distribute app"
lane :distributeApp do |values|
options = values[:options]
teams_web_hook = options[:teams_web_hook]
module_name = options[:module_name]
zappli_info = options[:zappli]
gradle_path = values[:gradle_path]
flavor_name = options[:flavor_name]
if zappli_info.nil? == false
begin
app = zappli_info[:app]
groups = zappli_info[:groups]
zappli(
api_token: zappli_api_token,
app: app,
path: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
groups: groups
)
if teams_web_hook.nil? == false
UI.message("Proceeding to send teams info, founded webhook #{teams_web_hook} 🚀")
teams_info(
group: groups[0],
teams_webhook: teams_web_hook,
flavor_name: flavor_name
)
end
rescue => ex
UI.error("Failed to upload to server: #{ex}")
raise ex
end
end
end
desc "Inform teams"
lane :teams_info do |options|
puts "Sending information to Microsoft Teams"
group = options[:group]
teams_webhook = options[:teams_webhook]
flavor_name = options[:flavor_name]
retrieve_logo = Fastlane::Actions::ZappliAction.fetch_logo(group)
begin
teams_bot(
teams_url: teams_webhook,
title: "New Release Available",
text: "Variante #{flavor_name}",
activity_title: "",
activity_image: retrieve_logo, # This is correctly using the logo URL
facts: [
{ "name" => "Public Page", "value" => "[Ver](#{public_page})" }
],
use_markdown: true # Allows using Markdown in the message
)
rescue => e
puts "Error sending message to Teams: #{e.full_message(highlight: true, order: :top)}"
end
end
desc "Upload aab to google play"
lane :uploadGooglePlay do |options|
json_key_file = options[:json_key_file]
package_name = options[:package_name]
teams_web_hook = options[:teams_web_hook]
validate_play_store_json_key(
json_key: json_key_file
)
upload_to_play_store(
track: 'alpha',
package_name: package_name,
json_key: json_key_file,
skip_upload_apk: true
)
end
desc "Generate specific flavor to build, by security can't make all flavors, because some of them are pointing to develop"
lane :buildAab do |values|
flavor_parameter = values[:id]
flavors = config_json[:flavors]
UI.message "TESTTT"
flavors.each do |child|
if child[:id] == flavor_parameter
UI.message "Found it specific flavor flavor to build"
flavor_name = child[:flavor_name]
sign_conf = child[:sign_conf]
gradle(
task: "bundle",
flavor: flavor_name.capitalize(),
build_type: sign_conf.capitalize()
)
gradle(
task: "#{module_name}:assemble",
flavor: flavor_name.capitalize(),
build_type: sign_conf.capitalize()
)
gradle_path = "#{lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]}"
apk_output_path = "#{lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]}"
distributeApp(options: child, gradle_path: gradle_path)
end
end
end
desc "Generate specific flavor to build, by security can't make all flavors, because some of them are pointing to develop"
lane :distributeAab do |values|
flavor_parameter = values[:id]
flavors = config_json[:flavors]
flavors.each do |child|
if child[:id] == flavor_parameter
UI.message "Found it specific flavor flavor to build"
flavor_name = child[:flavor_name]
sign_conf = child[:sign_conf]
json_key_file = child[:json_key_file]
zappli_info = child[:zappli]
app = zappli_info[:app]
groups = zappli_info[:groups]
gradle(
task: "bundle",
flavor: flavor_name.capitalize(),
build_type: sign_conf.capitalize()
)
zappli(
api_token: zappli_api_token,
app: app,
path: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH],
groups: groups
)
if json_key_file == nil
raise "Error: No se ha encontrado la configuracion de google play"
end
bundle_path = "#{lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]}"
uploadGooglePlay(child)
end
end
end
desc '
**Configuracion importLoco lane:**
La configuración usada para importar los archivos de Loco a Android debe estar en /buildsystem/localise.json, seguir este formato.
```json
{
"locales" : [ "es", "en", "fr" ],
"directory" : "library/core/src/main/res",
"format": ".xml",
"platform" : "android",
"key" : "ixjxISxkw_YD0MZIlPDK6g1Miils2JEK",
"fallback" : "en"
}
```
**Comando docker para ejecutar el script:**
```sh
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c \'cd /project; fastlane importLoco\'
```
También es recomendable crearse un Makefile para mas comodidad.
Contenido del Makefile:
```makefile
import-loco:
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c \'cd /project; fastlane importLoco\'
```
Se puede indicar la configuración que se quiere utilizar, por ejemplo:
```sh
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c \'cd /project; fastlane importLoco conf_file:./buildsystem/localise-mdm.json\'
```
De esta forma podemos tener varios modulos con diferentes configuraciones de localización. Importándolas todas desde un solo comando. Ejemplo:
```makefile
import-loco: import-mycardio import-mdm
import-mycardio:
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c \'cd /project; fastlane importLoco conf_file:./buildsystem/localise-mycardio.json\'
import-mdm:
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c \'cd /project; fastlane importLoco conf_file:./buildsystem/localise-mdm.json\'
```
Esto es extensible infinitamente.
'
lane :importLoco do |values|
conf_file = values[:conf_file]
if conf_file == nil
conf_file = './buildsystem/localise.json'
end
simple_loco(conf_file_path: conf_file)
end
end
lane :change_version do |options|
bump_type = options[:bump_type] || 'patch'
gradle_files = Dir.glob("../**/*.gradle") + Dir.glob("../**/*.gradle.kts")
puts "Bump type #{bump_type}"
version_name = nil
version_code = nil
gradle_files.each do |file|
puts "Processing file: #{file}"
content = File.read(file)
version_name_match = content.match(/versionName\s*=\s*["']([\d.]+)["']/)
version_code_match = content.match(/versionCode\s*=\s*(\d+)/)
if version_name_match
version_name = version_name_match[1]
end
if version_code_match
version_code = version_code_match[1].to_i
end
break if version_name && version_code
end
if version_name && version_code
puts "Current Version Name: #{version_name}, Version Code: #{version_code}"
# Asegurarse de que la versión tenga tres partes (MAJOR.MINOR.PATCH)
if version_name.split('.').length == 2
version_name += '.0' # Agregar .0 para completar el formato SemVer
puts "Adjusted Version Name (with patch): #{version_name}"
end
version = Semantic::Version.new(version_name)
new_version = case bump_type
when 'major'
version.increment!(:major)
when 'minor'
version.increment!(:minor)
when 'patch'
version.increment!(:patch)
else
puts "⚠️ Tipo de incremento no válido. Usa 'major', 'minor' o 'patch'."
return
end
puts "New Version Name (after bumping #{bump_type}): #{new_version}"
new_version_code = version_code + 1
puts "New Version Code: #{new_version_code}"
gradle_files.each do |file|
content = File.read(file)
new_content = content.gsub(/versionName\s*=\s*["'][\d.]+["']/, "versionName = \"#{new_version}\"")
new_content = new_content.gsub(/versionCode\s*=\s*\d+/, "versionCode = #{new_version_code}")
File.write(file, new_content)
end
File.open(ENV['GITHUB_OUTPUT'], 'a') do |file|
file.puts("new_version=#{new_version}")
end
else
puts "⚠️ No se encontró versionName o versionCode en el proyecto."
end
end
lane :update_ci do |options|
directory = options[:directory] || "../"
flavors = config_json[:flavors]
ids = flavors.map do |item|
item[:id]
end
ids_production = flavors.select do |obj|
obj[:id].include?("production") || obj["production"] == true
end
ids_production = ids_production.map do |item|
item[:id]
end
all_flavors_apk_directory = "#{directory}.github/workflows/all-flavors-apk.yml"
all_flavors_apk = SafeYAML.load_file(all_flavors_apk_directory)
all_flavors_apk["jobs"]["build"]["strategy"]["matrix"]["flavor"] = ids
File.open(all_flavors_apk_directory, 'w') do |file|
file.write(all_flavors_apk.to_yaml)
end
all_flavors_googleplay_directory = "#{directory}.github/workflows/all-flavors-googleplay.yml"
all_flavors_googleplay = SafeYAML.load_file(all_flavors_googleplay_directory)
all_flavors_googleplay["jobs"]["build"]["strategy"]["matrix"]["flavor"] = ids_production
File.open(all_flavors_googleplay_directory, 'w') do |file|
file.write(all_flavors_googleplay.to_yaml)
end
flavor_aab_google_play_directory = "#{directory}.github/workflows/flavor-aab-googleplay.yml"
flavor_aab_google_play = SafeYAML.load_file(flavor_aab_google_play_directory)
flavor_aab_google_play["on"]["workflow_dispatch"]["inputs"]["flavorId"]["options"] = ids_production
File.open(flavor_aab_google_play_directory, 'w') do |file|
file.write(flavor_aab_google_play.to_yaml)
end
flavor_apk_directory = "#{directory}.github/workflows/flavor-apk.yml"
flavor_apk = SafeYAML.load_file(flavor_apk_directory)
flavor_apk["on"]["workflow_dispatch"]["inputs"]["flavorId"]["options"] = ids
File.open(flavor_apk_directory, 'w') do |file|
file.write(flavor_apk.to_yaml)
end
update_strings_build_version_directory = "#{directory}.github/workflows/update-strings-build-version.yml"
update_strings_build_version = SafeYAML.load_file(update_strings_build_version_directory)
update_strings_build_version["on"]["workflow_dispatch"]["inputs"]["flavorId"]["options"] = ids
File.open(update_strings_build_version_directory, 'w') do |file|
file.write(update_strings_build_version.to_yaml)
end
end
lane :resize_resources do
require 'mini_magick'
densities = {
'ldpi' => 0.75,
'mdpi' => 1.0,
'hdpi' => 1.5,
'xhdpi' => 2.0,
'xxhdpi' => 3.0,
'xxxhdpi' => 4.0
}
# 🔥 INTERACTIVO 🔥
module_name = prompt(text: "¿Nombre del módulo? (ej: app, login, feature-home)")
module_name = module_name.gsub(':', '/').strip
flavor_name = prompt(text: "¿Nombre del flavor? (Enter para 'main')")
flavor_name = flavor_name.empty? ? 'main' : flavor_name.strip
density_source = prompt(text: "¿Densidad de origen? (hdpi, xhdpi, xxhdpi, etc)")
unless densities.key?(density_source)
UI.user_error!("Densidad de origen '#{density_source}' no es válida. Opciones válidas: #{densities.keys.join(', ')}")
end
# Construir rutas inteligentemente
project_root = File.expand_path("..", __dir__) # Subir 1 nivel desde fastlane/
base_path = File.join(project_root, module_name, "src", flavor_name, "res")
input_folder = File.join(base_path, "drawable-#{density_source}")
UI.message("Carpeta detectada: #{input_folder}")
unless Dir.exist?(input_folder)
UI.user_error!("No existe la carpeta: #{input_folder}")
end
UI.important("¿Continuar generando recursos para todos los targets desde #{input_folder}?")
confirm = prompt(text: "Escribe 'yes' para confirmar")
UI.user_error!("Abortado.") unless confirm.downcase == "yes"
# Ratio origen
source_ratio = densities[density_source]
# Procesar imágenes
Dir.glob("#{input_folder}/*.{png,jpg,jpeg,webp}").each do |filepath|
filename = File.basename(filepath)
densities.each do |target_density, target_ratio|
next if target_density == density_source # No regenerar la original
scale_factor = target_ratio / source_ratio
output_dir = File.join(base_path, "drawable-#{target_density}")
FileUtils.mkdir_p(output_dir)
output_path = File.join(output_dir, filename)
image = MiniMagick::Image.open(filepath)
new_width = (image.width * scale_factor).round
new_height = (image.height * scale_factor).round
image.resize "#{new_width}x#{new_height}"
image.write(output_path)
UI.message("Guardado: #{output_path}")
end
end
UI.success("¡Todos los recursos fueron generados correctamente!")
end