Commit 147d30bb authored by Rafa Hernandez's avatar Rafa Hernandez Committed by Alexander Salas Bastidas

ci(fastlane): add initial configuration

parent e5361ac3
package_name "org.glpi.glpiproject" # e.g. com.krausefx.app
\ No newline at end of file
# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command
# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`
# If you want to automatically update fastlane if a new version is available:
# update_fastlane
# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.61.0"
default_platform :android
platform :android do
desc "Create example apk"
lane :example do |options|
sign_apk(
keystore_path: "ci/release.keystore",
alias: "glpiapi",
storepass: options[:storepass],
tsa: "http://timestamp.comodoca.com/rfc316",
keypass: options[:keypass]
)
zipalign(apk_path: "#{lane_context[SharedValues::SIGNED_APK_PATH]}")
end
end
after_all do |lane|
telegram(
url_horn: ENV["TELEGRAM_WEBHOOKS"],
repo: ENV["GIT_REPO"],
branch: ENV["GIT_BRANCH"],
message: "Fastlane is OK"
)
end
error do |lane, exception|
telegram(
url_horn: ENV["TELEGRAM_WEBHOOKS"],
repo: ENV["GIT_REPO"],
branch: ENV["GIT_BRANCH"],
message: "`ERROR` Fastlane FAIL"
)
end
# how to used it fastlane android beta storepass:'#KEYSTORE_PASSWORD' keypass:'#ALIAS_PASSWORD'
\ No newline at end of file
module Fastlane
module Actions
module SharedValues
SIGNED_APK_PATH = :SIGNED_APK_PATH
end
class SignApkAction < Action
def self.run(params)
UI.user_error!("Couldn't find '*release-unsigned.apk' file at path 'app/build/outputs/apk/'") unless params[:apk_path]
UI.user_error("Need keystore in order to sign apk") unless params[:keystore_path]
sign_cmd = ["jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1"]
sign_cmd << ["-keystore #{params[:keystore_path].shellescape}" ] if params[:keystore_path]
sign_cmd << ["#{params[:apk_path].shellescape}"] if params[:apk_path]
sign_cmd << ["'#{params[:alias]}'"] if params[:alias]
sign_cmd << ["-keypass #{params[:keypass] ? params[:keypass] : params[:storepass]}"] if params[:keypass] || params[:storepass]
sign_cmd << ["-storepass #{params[:storepass]}"] if params[:storepass]
sign_cmd << ["-tsa #{params[:tsa]}"] if params[:tsa]
if params[:signed_apk_path]
sign_cmd << ["-signedjar #{params[:signed_apk_path]}" ]
Actions.lane_context[SharedValues::SIGNED_APK_PATH] = "#{params[:signed_apk_path]}"
elsif params[:apk_path].include?("unsigned")
sign_cmd << ["-signedjar #{params[:apk_path].gsub('-unsigned', '')}"]
Actions.lane_context[SharedValues::SIGNED_APK_PATH] = "#{params[:apk_path].gsub('-unsigned', '')}"
end
Fastlane::Actions.sh(sign_cmd, log: true)
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Sign a Android apk with a java keystore"
end
def self.available_options
apk_path_default = Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "*release-unsigned.apk")].last
[
FastlaneCore::ConfigItem.new(key: :apk_path,
env_name: "apk_path",
description: "Path to your APK file that you want to sign",
default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] || apk_path_default,
optional: true),
FastlaneCore::ConfigItem.new(key: :signed_apk_path,
env_name: "SIGNED_APK_PATH",
description: "Path to the signed APK file",
optional: true,
is_string: true),
FastlaneCore::ConfigItem.new(key: :keystore_path,
env_name: "KEYSTORE_PATH",
description: "Path to java keystore",
optional: true),
FastlaneCore::ConfigItem.new(key: :alias,
env_name: "ALIAS",
description: "The alias of the certificate in the keystore to use to sign the apk",
is_string: true),
FastlaneCore::ConfigItem.new(key: :keypass,
env_name: "KEY_PASS",
description: "The password used to protect the private key of the keystore entry addressed by the alias specified. If not specified storepass will be used",
optional:true,
is_string: true),
FastlaneCore::ConfigItem.new(key: :storepass,
env_name: "STORE_PASS",
description: "The password which is required to access the keystore",
is_string: true),
FastlaneCore::ConfigItem.new(key: :tsa,
env_name: "TIME_STAMPING_AUTHORITHY",
description: "The url of the Time Stamping Authority (TSA) used to timestamp the apk signing",
optional:true,
is_string: true)
]
end
def self.output
['SIGN_APK_PATH', 'Path to your APK file']
end
def self.authors
"nomisRev"
end
def self.is_supported?(platform)
platform == :android
end
end
end
end
module Fastlane
module Actions
class TelegramAction < Action
def self.run(params)
require 'net/http'
require 'uri'
uri = URI.parse(params[:url_horn])
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.set_form_data({
'payload' => '{ "text": "' + params[:message] + "\\n- *Repo*: " + params[:repo] + "\\n- *Branch*: " + params[:branch] + "\\n- *Author*: " + Actions.git_author_email + '" }'
})
response = https.request(req)
UI.message(response)
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Telegram send message to telegram with @bullhorn_bot"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :url_horn,
env_name: "URL_HORN",
description: "Path from @bullhorn_bot on Telegram",
is_string: true),
FastlaneCore::ConfigItem.new(key: :message,
env_name: "MESSAGE",
description: "Text to send",
is_string: true),
FastlaneCore::ConfigItem.new(key: :repo,
env_name: "REPO",
description: "Get github repository",
is_string: true),
FastlaneCore::ConfigItem.new(key: :branch,
env_name: "BRANCH",
description: "Get github branch",
is_string: true)
]
end
def self.authors
["rafaelje"]
end
def self.is_supported?(platform)
true
end
end
end
end
\ No newline at end of file
module Fastlane
module Actions
module SharedValues
ZIPALIGN_CUSTOM_VALUE = :ZIPALIGN_CUSTOM_VALUE
end
class ZipalignAction < Action
def self.run(params)
UI.user_error!("Couldn't find '*release.apk' file at path 'app/build/outputs/apk/'") unless params[:apk_path]
error_callback = proc do |error|
new_name = params[:apk_path].gsub('.apk', '-unaligned.apk')
rename_command = ["mv -n",params[:apk_path],new_name]
Fastlane::Actions.sh(rename_command, log: false)
aligncmd = ["$ANDROID_HOME/build-tools/$BUILD_TOOL/zipalign -v -f 4", new_name , " ", params[:apk_path] ]
Fastlane::Actions.sh(aligncmd, log: true)
return
end
zipalign = Fastlane::Actions.sh("$ANDROID_HOME/build-tools/$BUILD_TOOL/zipalign -c -v 4 #{params[:apk_path]}", log: false , error_callback: error_callback)
UI.message('Input apk is aligned')
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Zipalign an apk. Input apk is renamed '*-unaligned.apk'"
end
def self.available_options
apk_path_default = Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "*release.apk")].last
[
FastlaneCore::ConfigItem.new(key: :apk_path,
env_name: "INPUT_APK_PATH",
description: "Path to your APK file that you want to align",
default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] || apk_path_default,
optional: true)
]
end
def self.authors
["nomisRev"]
end
def self.is_supported?(platform)
platform == :android
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment