Files
android/fastlane/Fastfile

144 lines
4.9 KiB
Ruby

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:android)
platform :android do
desc "Runs tests"
lane :checkAuthenticator do
gradle(tasks: ["authenticator:testDebug", "authenticator:lintDebug", "authenticator:detekt","authenticator:koverXmlReportDebug"])
end
desc "Apply build version information"
fastlane_require "time"
lane :setAuthenticatorBuildVersionInfo do |options|
# Read-in app build config file.
buildConfigPath = "../authenticator/build.gradle.kts"
buildConfigFile = File.open(buildConfigPath)
buildConfigText = buildConfigFile.read
buildConfigFile.close
currentVersionCode = buildConfigText.match(/versionCode = (\d+)/).captures[0]
currentVersionName = buildConfigText.match(/versionName = "(.+)"/).captures[0]
if options[:versionName].nil? or options[:versionName].to_s.empty?
puts "Fetching latest tags from origin..."
`git fetch --prune --no-recurse-submodules --filter=tree:0 --depth=1 --tags origin`
puts "Getting latest version name from previous git tag..."
latestTag = `git describe --tags $(git rev-list --tags --max-count=1)`.chomp()
puts "Using tag #{latestTag} to calculate version name..."
latestTag.slice!(0)
puts "Current version name resolved to #{latestTag}."
versionParts = latestTag.split(".")
currentMajor = versionParts[0]
currentMinor = versionParts[1]
currentRevision = versionParts[2]
currentDate = Time.new
major = currentDate.year.to_s
minor = currentDate.strftime "%-m"
revision = 0
if currentMajor == major and currentMinor == minor
revision = currentRevision.to_i + 1
end
nextVersionName = "#{major}.#{minor}.#{revision}"
else
nextVersionName = options[:versionName].to_s
end
# Replace version information.
puts "Setting version code to #{options[:versionCode]}."
buildConfigText.gsub!("versionCode = #{currentVersionCode}", "versionCode = #{options[:versionCode]}")
puts "Setting version name to #{nextVersionName}."
buildConfigText.gsub!("versionName = \"#{currentVersionName}\"", "versionName = \"#{nextVersionName}\"")
# Save changes
File.open(buildConfigPath, "w") { |buildConfigFile| buildConfigFile << buildConfigText }
end
desc "Assemble debug variants"
lane :buildAuthenticatorDebug do
gradle(
task: "authenticator:assemble",
build_type: "Debug",
print_command: false,
)
end
desc "Assemble and sign release APK"
lane :buildAuthenticatorRelease do |options|
gradle(
task: "authenticator:assemble",
build_type: "Release",
properties: {
"android.injected.signing.store.file" => options[:storeFile],
"android.injected.signing.store.password" => options[:storePassword],
"android.injected.signing.key.alias" => options[:keyAlias],
"android.injected.signing.key.password" => options[:keyPassword]
},
print_command: false,
)
end
desc "Bundle and sign release AAB"
lane :bundleAuthenticatorRelease do |options|
gradle(
task: "authenticator:bundle",
build_type: "Release",
properties: {
"android.injected.signing.store.file" => options[:storeFile],
"android.injected.signing.store.password" => options[:storePassword],
"android.injected.signing.key.alias" => options[:keyAlias],
"android.injected.signing.key.password" => options[:keyPassword]
},
print_command: false,
)
end
desc "Publish release AAB to Firebase"
lane :distributeAuthenticatorReleaseBundleToFirebase do |options|
release_notes = changelog_from_git_commits(
commits_count: 1,
pretty: "- %s"
)
puts "Release notes #{release_notes}"
firebase_app_distribution(
app: "1:867301491091:android:50b626dba42a361651e866",
android_artifact_type: "AAB",
android_artifact_path: "authenticator/build/outputs/bundle/release/com.bitwarden.authenticator.aab",
service_credentials_file: options[:serviceCredentialsFile],
groups: "internal-prod-group, livefront",
release_notes: release_notes,
)
end
desc "Publish release to Google Play Store"
lane :publishAuthenticatorReleaseToGooglePlayStore do |options|
upload_to_play_store(
package_name: "com.bitwarden.authenticator",
json_key: options[:serviceCredentialsFile],
track: "internal",
aab: "authenticator/build/outputs/bundle/release/com.bitwarden.authenticator.aab",
mapping: "authenticator/build/outputs/mapping/release/mapping.txt",
)
end
end