Search code examples
androidgithubfastlanegithub-actions

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.


Solution

  • 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