Auto Test and Sign Your App with GitHub Actions

Enes Varol
3 min readJul 2, 2022
Photo by Emily Morter on Unsplash

Why do we need GitHub Actions?

GitHub Actions can be used for “Continous Delivery”. In this article, I won’t explain what “Continous Delivery” means.

But to understand it we can use this scenario:

1- Pull request opens

2- Github action runs unit and instrumentation tests on pull requesting branch

3- If tests pass, the action generates a signed apk from requesting branch and sends a notification to Slack QA Channel

How to do that all?

I won’t explain how to send a notification to Slack but in the GitHub action marketplace you can find an action for your desire.

Let’s get to the action!

We create our yml file under .github (with any name we want)

## 1
name: Test and deploy

## Actions that will be executed when you push code
on:
push:
branches:
- master

## 2
jobs:
## 3
unit_tests:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v2

- name: Unit tests
run: ./gradlew test
## 4
android_tests:
runs-on: [ macos-latest ]
steps:
- uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 11

- name: Instrumentation Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
script: ./gradlew connectedAndroidTest
build:
needs: [ unit_tests, android_tests ]
runs-on: ubuntu-latest
steps:
# 1
- name: Checkout code
uses: actions/checkout@v2
# 2
- name: Generate Release APK
run: ./gradlew assembleRelease
# 3
- name: Sign APK
uses: r0adkll/sign-android-release@v1
# ID used to access action output
id: sign_app
with:
releaseDirectory: app/build/outputs/apk/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
# 4
- uses: actions/upload-artifact@master
with:
name: release.apk
path: ${{steps.sign_app.outputs.signedReleaseFile}}
# 5
- uses: actions/upload-artifact@master
with:
name: mapping.txt
path: app/build/outputs/mapping/release/mapping.txt

The code is easy to understand and hard to indentation :)

1- Name of the action

2- When to execute, in this case when the master branch gets a push

3- All jobs (I won’t get into detail, for any questions about the jobs happy to get comments)

Note:

For signing a release, Keystore and passwords must be uploaded to repository secrets.

And that’s it GitHub Action is ready.

Photo by Joshua Hoehne on Unsplash

References and More

I would like to thank Raywenderlich and much more information can be found there.

Special Thanks to: İsmail Oğuzhan Ay

Article Repository:

--

--

Enes Varol

TRT - Android Developer GitHub/LinkedIn: vrolnes