Update Fastfile

This commit is contained in:
Marcos Rodriguez Velez 2024-09-11 18:38:09 -04:00
parent 3fd2314e5e
commit de0647f93a

View File

@ -28,58 +28,61 @@ platform :android do
end end
end end
desc "Update version code, build, and sign the APK"
lane :update_version_build_and_sign_apk do lane :update_version_build_and_sign_apk do
Dir.chdir(project_root) do Dir.chdir(project_root) do
build_number = ENV['BUILD_NUMBER'] build_number = ENV['BUILD_NUMBER']
UI.user_error!("BUILD_NUMBER environment variable is missing") if build_number.nil? UI.user_error!("BUILD_NUMBER environment variable is missing") if build_number.nil?
# Get the version name from build.gradle # Get the version name from build.gradle
version_name = sh("grep versionName android/app/build.gradle | awk '{print $2}' | tr -d '\"'").strip version_name = sh("grep versionName android/app/build.gradle | awk '{print $2}' | tr -d '\"'").strip
# Get the branch name # Get the branch name and default to 'master' if empty
branch_name = ENV['GITHUB_HEAD_REF'] || `git rev-parse --abbrev-ref HEAD`.strip.gsub(/[\/\\:?*"<>|]/, '_') branch_name = ENV['GITHUB_HEAD_REF'] || `git rev-parse --abbrev-ref HEAD`.strip.gsub(/[\/\\:?*"<>|]/, '_')
# Append branch name only if it's not 'master' # Ensure branch name is not empty and defaults to 'master'
if branch_name != 'master' if branch_name.nil? || branch_name.empty?
signed_apk_name = "BlueWallet-#{version_name}-#{build_number}-#{branch_name}.apk" branch_name = 'master'
else end
signed_apk_name = "BlueWallet-#{version_name}-#{build_number}.apk"
end # Append branch name only if it's not 'master'
if branch_name != 'master'
Dir.chdir("android") do signed_apk_name = "BlueWallet-#{version_name}-#{build_number}-#{branch_name}.apk"
UI.message("Updating version code in build.gradle...") else
gradle( signed_apk_name = "BlueWallet-#{version_name}-#{build_number}.apk"
task: "assembleRelease", end
properties: { "versionCode" => build_number },
project_dir: "android" Dir.chdir("android") do
) UI.message("Updating version code in build.gradle...")
UI.message("Version code updated to #{build_number} and APK build completed.") gradle(
task: "assembleRelease",
# Define the output paths properties: { "versionCode" => build_number },
unsigned_apk_path = "app/build/outputs/apk/release/app-release-unsigned.apk" project_dir: "android"
signed_apk_path = "app/build/outputs/apk/release/#{signed_apk_name}" )
UI.message("Version code updated to #{build_number} and APK build completed.")
# Rename the unsigned APK to include the version and build number
if File.exist?(unsigned_apk_path) # Define the output paths
UI.message("Renaming APK to #{signed_apk_name}...") unsigned_apk_path = "app/build/outputs/apk/release/app-release-unsigned.apk"
FileUtils.mv(unsigned_apk_path, signed_apk_path) signed_apk_path = "app/build/outputs/apk/release/#{signed_apk_name}"
ENV['APK_OUTPUT_PATH'] = File.expand_path(signed_apk_path)
else # Rename the unsigned APK to include the version and build number
UI.error("Unsigned APK not found at path: #{unsigned_apk_path}") if File.exist?(unsigned_apk_path)
next UI.message("Renaming APK to #{signed_apk_name}...")
FileUtils.mv(unsigned_apk_path, signed_apk_path)
ENV['APK_OUTPUT_PATH'] = File.expand_path(signed_apk_path)
else
UI.error("Unsigned APK not found at path: #{unsigned_apk_path}")
next
end
# Sign the APK using apksigner directly
UI.message("Signing APK with apksigner...")
apksigner_path = "#{ENV['ANDROID_HOME']}/build-tools/34.0.0/apksigner"
sh("#{apksigner_path} sign --ks ./bluewallet-release-key.keystore --ks-pass=pass:#{ENV['KEYSTORE_PASSWORD']} #{signed_apk_path}")
UI.message("APK signed successfully: #{signed_apk_path}")
end end
# Sign the APK using apksigner directly since we don't have an alias
UI.message("Signing APK with apksigner...")
apksigner_path = "#{ENV['ANDROID_HOME']}/build-tools/34.0.0/apksigner"
sh("#{apksigner_path} sign --ks ./bluewallet-release-key.keystore --ks-pass=pass:#{ENV['KEYSTORE_PASSWORD']} #{signed_apk_path}")
UI.message("APK signed successfully: #{signed_apk_path}")
end end
end end
end
desc "Upload APK to BrowserStack and post result as PR comment" desc "Upload APK to BrowserStack and post result as PR comment"
lane :upload_to_browserstack_and_comment do lane :upload_to_browserstack_and_comment do
Dir.chdir(project_root) do Dir.chdir(project_root) do