Deploying to Google Play Store using Github Actions
April 16, 2020
Recently I looked into CI/CD for Android using Github Actions. And thanks to open source contributions to Github Actions marketplace, it ended up being easier than I thought it would be.
In particular, I am using these two Actions (both created by Drew Heavner). Thanks Drew!
For a small project of mine I ended up with two YAML files:
build.ymldeploy.yml
Build
build.yml simply builds my app including static code analysis using detekt and executing unit tests.
Here is the entire build.yml code:
name: Build
on:
push:
branches:
- '*'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew buildDeploy
deploy.yml allows us to automate creating a release and deploying it to Google Play courtesy of Github Actions.
To create a release and have it deployed to Alpha track, you’d perform the following steps:
Create a release branch from master. This branch should follow the following naming convention:
release/x.y.zwhere x.y.z is the target Android app version name in SemVar format.Bump both
versionCodeandversionNameinapp/build.gradlein the release branch.Create a pull request to merge release branch into master. The
deployGithub Action will automatically execute against the release branch and the following steps will be performed in this order:perform static code analysis
execute unit tests
create and sign release bundle (.aab)
git tag the release
deploy the release bundle to Alpha track in PlayStore
Once the deploy succeeds, you can merge the release PR into
master.
Automation means not doing repetitive tasks manually, less room for error and more time for you to solve interesting code problems.
Here is the source code of deploy.yml (note, use release/* when specifying matching branches).
name: Deploy to Alpha
on:
push:
branches:
- release/
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build
run: ./gradlew build
- name: Assemble Release Bundle
run: |
./gradlew bundleRelease
- name: Sign Release
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: app/build/outputs/bundle/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
- name: Tag Release
run: |
version_name=${GITHUB_REF##*/}
echo "Tagging release with tag $version_name"
git tag $version_name release/$version_name
git push origin --tags
- name: Create service_account.json
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
- name: Deploy to Alpha
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: service_account.json
packageName: com.jshvarts.flows
releaseFile: app/build/outputs/bundle/release/app-release.aab
track: alpha
whatsNewDirectory: distribution/Note that every secrets.* reference Github secrets where you’d configure sensitive build context data for each individual repo.
Google Play Console
In order for CI/CD environment to be able to upload .apk or .aab via API, you need to generate Service Account JSON (private key) and add it to Github Secrets as shown above.
To do so, visit Google Play Console to set up API access and don’t forget to click Grant Access when you are done.