Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CI/CD with Github Actions and Fastlane

I am using fastlane to automate my deployments to the play store. Here is a alpha lane as an example.

lane :alpha do    
    gradle(task: 'clean')
    gradle(
      task: 'assemble',
      build_type: 'Release',
      properties: {
        "android.injected.signing.store.file" => ENV["ANDROID_KEYSTORE"],
        "android.injected.signing.store.password" => ENV["ANDROID_KEYSTORE_PASSWORD"],
        "android.injected.signing.key.alias" => ENV["ANDROID_KEY_ALIAS"],
        "android.injected.signing.key.password" => ENV["ANDROID_KEY_PASSWORD"],
      }
    )
    upload_to_play_store(track: 'alpha')
end

I want to automate this deployment with Github actions. Whenever a commit to staging occurs, run fastlane alpha. The issue I am running into, however, is versioning. I need to bump the versionCode in my build.gradle file. I have been doing this manually before running fastlane alpha.

I want to remove the need to bump this value manually before I commit, how can I achieve this?

I have seen this fastlane plugin to increment the version code. If I, for example, commit once while the versionCode is at 1, then my workflow will automatically increment the versionCode to 2. When I commit again, the versionCode will still be 1, and Github will bump it to 2. However, the play store needs versionCode 3. The ideal solution is to have Github query from the Google Play Store the current versionCode of my app and supply that + 1 to fastlane. I have searched for a way to do this but cannot find a solution.

like image 557
user82395214 Avatar asked Sep 08 '26 22:09

user82395214


2 Answers

Have you tried this: https://docs.fastlane.tools/actions/google_play_track_version_codes/ ?

    g = google_play_track_version_codes
    gb = google_play_track_version_codes(track: 'beta')
    ga = google_play_track_version_codes(track: 'alpha')
    max_value = [g[0].to_i, gb[0].to_i, ga[0].to_i].max
    version_updated = max_value + 1
    increment_version_code(app_project_dir: "./app", version_code: version_updated.to_i)

Basically I'm taking all version codes of Google Play and increasing +1 the max one, and then using the versioning plugin to update it on the build.gradle

like image 68
rcarba Avatar answered Sep 10 '26 12:09

rcarba


You can add a lane to do this as described in this Medium post by Atul Anand:

lane:IncrementBuildNumber do

    path = '../app/build.gradle'
    re = /versionCode\s+(\d+)/
    s = File.read(path)
    versionCode = s[re, 1].to_i
    s[re, 1] = (versionCode + 1).to_s
    f = File.new(path, 'w')
    f.write(s)
    f.close

end
like image 23
Patrick Kenny Avatar answered Sep 10 '26 11:09

Patrick Kenny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!