NOI community Android app - noi-techpark/odh-docs GitHub Wiki

This is the workflow used for the Android CI of the NOI community app.
The repo can be found here.

### Continuous Integration
#
# This file is inspired by
# https://www.raywenderlich.com/19407406-continuous-delivery-for-android-using-github-actions

name: CI
on: [pull_request, push]
jobs:

  ## Build the app and run unit tests
  unit_tests:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2
      - name: Inject google-services.json
        env:
          GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
        run: echo "$GOOGLE_SERVICES_JSON" > app/google-services.json
      - name: Test the app
        run: ./gradlew test

  ## Run tests on an Android Simulator
  ## We use macos as it has hardware acceleration for that
  android_tests:
    runs-on: macos-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2
      - name: Instrumentation Tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 29
          script: ./gradlew connectedAndroidTest

  ## Build and sign the app, and upload it as Github Artifact
  build_and_deploy_to_play_store:
    needs: [ unit_tests, android_tests ]
    if: github.ref == 'refs/heads/development'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Inject google-services.json
        env:
          GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
        run: echo "$GOOGLE_SERVICES_JSON" > app/google-services.json
      - name: Increment build number
        run: |
          set -eo pipefail
          BUILD_NUMBER=$(date "+%s")
          echo "VERSION_CODE=$BUILD_NUMBER" > app/version.properties
          cat app/version.properties
      - name: Generate Release AAB
        run: ./gradlew bundleRelease
      - name: Sign AAB
        uses: r0adkll/sign-android-release@v1
        # ID used to access action output
        id: sign_app
        with:
          releaseDirectory: app/build/outputs/bundle/release
          signingKeyBase64: ${{ secrets.KEYSTORE_SIGNING_KEY }}
          alias: ${{ secrets.KEYSTORE_ALIAS }}
          keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }}
          keyPassword: ${{ secrets.KEYSTORE_PASSWORD_FOR_KEY }}
      - name: Publish to Play Store closed alpha track
        uses: r0adkll/upload-google-play@v1
        with:
          serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
          packageName: it.bz.noi.community
          releaseFiles: ${{ steps.sign_app.outputs.signedReleaseFile }}
          track: alpha
          status: completed