Created
July 9, 2021 02:16
-
-
Save graffiti75/cf8f8925c59ba52e6d03d337487200aa to your computer and use it in GitHub Desktop.
Continuous Delivery for Android Using GitHub Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##1: Creates a workflow named Test and deploy. | |
name: Test and deploy | |
## Actions that will be executed when you push code currently none | |
on: | |
push: | |
tags: | |
- 'v*' | |
pull_request: | |
branches: | |
- master | |
## 2: Creates two parallel jobs named unit_tests and android_tests. | |
jobs: | |
## 3: The unit_tests job runs on an ubuntu runner, which checks out the code and runs the unit tests. | |
unit_tests: | |
runs-on: [ubuntu-latest] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Unit tests | |
run: ./gradlew test | |
## 4: The android_tests job runs on a macOS runner. This job also checks out the code, but runs the | |
## instrumentation tests instead. To do this, it uses the reactivecircus/android-emulator-runner action. | |
## The emulator can use hardware acceleration only on the macOS emulator. Therefore, this job needs to run | |
## on a macOS runner while others can run on Ubuntu runners. | |
android_tests: | |
runs-on: [ macos-latest ] | |
steps: | |
- uses: actions/checkout@v2 | |
- 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: Checks out the code. | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# 2: Generates a release APK using the assembleRelease Gradle task. | |
- name: Generate Release APK | |
run: ./gradlew assembleRelease | |
# 3: Signs the APK using the r0adkll/sign-android-release action, which is a third party action | |
# available on the github marketplace linked earlier. This step uses the four secrets you added | |
# in the previous section. It also has an ID: sign_app. | |
- 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: Uploads the signed APK as an artifact to GitHub. This step uses the ID from the previous | |
# step to access its output, named signedReleaseFile. | |
- uses: actions/upload-artifact@master | |
with: | |
name: release.apk | |
path: ${{steps.sign_app.outputs.signedReleaseFile}} | |
# 5: Uploads the mapping file as an artifact. You'll use this in a later step, when you upload to the Play Store. | |
- uses: actions/upload-artifact@master | |
with: | |
name: mapping.txt | |
path: app/build/outputs/mapping/release/mapping.txt | |
deploy-firebase: | |
# 1: Use needs to specify that the job can only run if the build job has completed successfully. | |
needs: [ build ] | |
runs-on: ubuntu-latest | |
steps: | |
# 2: Use actions/download-artifact action to download the artifact of the release APK. | |
- uses: actions/download-artifact@master | |
with: | |
name: release.apk | |
#3: Upload the downloaded artifact to Firebase App Distribution and makes it available to the | |
# QA group you created earlier. It also uses the two secrets named FIREBASE_APP_ID and | |
# FIREBASE_TOKEN, which you added in the previous section. | |
- name: upload artifact to Firebase App Distribution | |
uses: wzieba/Firebase-Distribution-Github-Action@v1 | |
with: | |
appId: ${{secrets.FIREBASE_APP_ID}} | |
token: ${{secrets.FIREBASE_TOKEN}} | |
groups: QA | |
file: app-release-unsigned-signed.apk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment