Skip to content

Instantly share code, notes, and snippets.

@CristianMG
Created December 9, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CristianMG/0b88d75a34893f4a9ee2701a9aba8cd0 to your computer and use it in GitHub Desktop.
Save CristianMG/0b88d75a34893f4a9ee2701a9aba8cd0 to your computer and use it in GitHub Desktop.
Fastlane Example
default_platform(:android)
config_json = read_json(
json_path: "./buildsystem/config.json"
)
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.then { |s| s[0].upcase + s[1..-1] },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]
appcenter_api_key = options[:appcenter_api_key]
appcenter_user = options[:appcenter_user]
appcenter_app_name = options[:appcenter_app_name]
appcenter_group = options[:appcenter_group]
appcenter_url_release = options[:appcenter_url_release]
teams_web_hook = options[:teams_web_hook]
module_name = options[:module_name]
upload_server = options[:upload_server]
gradle_path = values[:gradle_path]
appcenter_upload(
api_token: appcenter_api_key,
owner_name: appcenter_user,
owner_type: "user", # Default is user - set to organization for appcenter organizations
destinations: appcenter_group,
app_name: appcenter_app_name,
file: gradle_path,
app_os: "Android",
app_display_name: appcenter_app_name,
notify_testers: true
)
if upload_server.nil? == false
upload_to_server(
endPoint: upload_server[:endpoint],
method: :post,
multipartPayload: {
:fileFormFieldName => "#{upload_server[:param]}"
},
headers: {
:"api_key" => "#{upload_server[:api_key]}"
},
)
end
if teams_web_hook.nil? == false
teamsNotification(
teams_web_hook:teams_web_hook,
teams_message:"Nueva version distribuida en appcenter #{appcenter_app_name} #{appcenter_group} disponible",
activity_title: "Link [Aquí](#{appcenter_url_release})"
)
end
end
desc "Teams message to teams_web_hook"
lane :teamsNotification do |options|
teams_web_hook = options[:teams_web_hook]
teams_message = options[:teams_message]
activity_title = options[:activity_title]
teams_bot(
teams_url: teams_web_hook,
title: options[:teams_message],
text: "",
activity_title: options[:activity_title],
activity_image: "https://graffica.info/wp-content/uploads/2017/07/logo-Android-Andy-1200x900.jpg"
)
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_path = "#{lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]}"
distributeApp(options: child, gradle_path: gradle_path)
uploadGooglePlay(child)
end
end
end
desc '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment