From 04f5926652f67514793dc58a21f6522984f2e4d9 Mon Sep 17 00:00:00 2001 From: Paul Schmiedmayer Date: Fri, 6 Dec 2024 14:35:33 -0800 Subject: [PATCH] Improve Version Code Identification --- fastlane/Fastfile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 015c30d12..2ab310a2d 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -28,18 +28,24 @@ platform :android do UI.message("Using environment: #{environment}") UI.message("Using application id: #{applicationid}") - version_codes = google_play_track_version_codes( - package_name: applicationid, - track: track, - json_key_data: ENV['SERVICE_ACCOUNT_JSON_KEY'] - ) + def fetch_max_version_code(track, applicationid) + version_codes = google_play_track_version_codes( + package_name: applicationid, + track: track, + json_key_data: ENV['SERVICE_ACCOUNT_JSON_KEY'] + ) - if version_codes.nil? || version_codes.empty? - previous_version_code = 0 - else - previous_version_code = version_codes.max + if version_codes.nil? || version_codes.empty? + 0 + else + version_codes.max + end end + production_version_code = fetch_max_version_code('production', applicationid) + internal_version_code = fetch_max_version_code('internal', applicationid) + + previous_version_code = [production_version_code, internal_version_code].max current_version_code = previous_version_code + 1 UI.message("Previous version code: #{previous_version_code}")