diff --git a/.github/workflows/build-release-apk.yml b/.github/workflows/build-release-apk.yml index 09a54fbf9..4beb7f7ec 100644 --- a/.github/workflows/build-release-apk.yml +++ b/.github/workflows/build-release-apk.yml @@ -97,6 +97,7 @@ jobs: with: name: signed-apk path: ${{ env.APK_PATH }} + if-no-files-found: error browserstack: runs-on: ubuntu-latest diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 2ce114507..a1f752003 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -41,37 +41,37 @@ platform :android do Dir.chdir(project_root) do build_number = ENV['BUILD_NUMBER'] UI.user_error!("BUILD_NUMBER environment variable is missing") if build_number.nil? - + # Extract versionName from build.gradle version_name = sh("grep versionName android/app/build.gradle | awk '{print $2}' | tr -d '\"'").strip - + UI.user_error!("Failed to extract versionName from build.gradle") if version_name.nil? || version_name.empty? + # Update versionCode in build.gradle UI.message("Updating versionCode in build.gradle to #{build_number}...") build_gradle_path = "android/app/build.gradle" build_gradle_contents = File.read(build_gradle_path) new_build_gradle_contents = build_gradle_contents.gsub(/versionCode\s+\d+/, "versionCode #{build_number}") File.write(build_gradle_path, new_build_gradle_contents) - - # Determine branch name - branch_name = ENV['GITHUB_HEAD_REF'] || `git rev-parse --abbrev-ref HEAD`.strip.gsub(/[\/\\:?*"<>|]/, '_') + + # Determine branch name and sanitize it + branch_name = ENV['GITHUB_HEAD_REF'] || `git rev-parse --abbrev-ref HEAD`.strip + branch_name = branch_name.gsub(/[^a-zA-Z0-9_-]/, '_') # Replace non-alphanumeric characters with underscore branch_name = 'master' if branch_name.nil? || branch_name.empty? - - # Define APK name based on branch - signed_apk_name = branch_name != 'master' ? "BlueWallet-#{version_name}-#{build_number}-#{branch_name}.apk" : "BlueWallet-#{version_name}-#{build_number}.apk" - - # Build APK - UI.message("Building APK...") - sh("cd android && ./gradlew assembleRelease") - UI.message("APK build completed.") - + # Define APK name based on branch signed_apk_name = branch_name != 'master' ? - "BlueWallet-#{version_name}-#{build_number}-#{branch_name}".gsub(/[\/\\:?*"<>|]/, '_') + ".apk" : - "BlueWallet-#{version_name}-#{build_number}.apk" - + "BlueWallet-#{version_name}-#{build_number}-#{branch_name}.apk" : + "BlueWallet-#{version_name}-#{build_number}.apk" + # Define paths unsigned_apk_path = "android/app/build/outputs/apk/release/app-release-unsigned.apk" signed_apk_path = "android/app/build/outputs/apk/release/#{signed_apk_name}" + + # Build APK + UI.message("Building APK...") + sh("cd android && ./gradlew assembleRelease --no-daemon") + UI.message("APK build completed.") + # Rename APK if File.exist?(unsigned_apk_path) UI.message("Renaming APK to #{signed_apk_name}...") @@ -81,14 +81,16 @@ platform :android do UI.error("Unsigned APK not found at path: #{unsigned_apk_path}") next end - + # Sign APK UI.message("Signing APK with apksigner...") - apksigner_path = "#{ENV['ANDROID_HOME']}/build-tools/34.0.0/apksigner" + apksigner_path = Dir.glob("#{ENV['ANDROID_HOME']}/build-tools/*/apksigner").sort.last + UI.user_error!("apksigner not found in Android build-tools") if apksigner_path.nil? || apksigner_path.empty? sh("#{apksigner_path} sign --ks #{project_root}/bluewallet-release-key.keystore --ks-pass=pass:#{ENV['KEYSTORE_PASSWORD']} #{signed_apk_path}") UI.message("APK signed successfully: #{signed_apk_path}") end end +end desc "Upload APK to BrowserStack and post result as PR comment" lane :upload_to_browserstack_and_comment do @@ -591,5 +593,4 @@ lane :update_release_notes do |options| UI.error("No localization found for locale #{locale}") end end -end end \ No newline at end of file