Skip to content

Actions CI

Lopez Mikhael edited this page Jun 7, 2020 · 2 revisions

Now that you have written your tests it is important to be able to run them automatically at the right time of your development. Android has many different versions and devices. It is therefore essential to test on as many devices as possible.

Here I present you how I managed my CI (continuous integration) using GitHub actions.
You can obviously use other services like Bitrise which is very similar.

On:

You can choose on which branch to execute your actions to avoid executing them after each push.
I invite you to look at the Git Flow page to better understand how to manage your branches.

  • Master:
on:
  pull_request:
    branches:
      - 'master'
  push:
    branches:
      - 'master'
  • Develop
on:
  pull_request:
    branches:
      - 'develop'
  push:
    branches:
      - 'develop'

Jobs:

You can now choose what you want to execute in your actions.
Here I have listed 3 specific examples to Android and this architecture:

  • Unit Tests:
unit-tests:
  name: Run Unit Tests
  runs-on: ubuntu-latest

  steps:
    - name: Checkout
      uses: actions/checkout@v1

    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8

    - name: Run Presentation Unit Tests
      run: ./gradlew :presentation:testDebugTestUnitTest

    - name: Run Data Unit Tests
      run: ./gradlew :data:testDebugTestUnitTest

    - name: Run Domain Unit Tests
      run: ./gradlew :domain:test
  • Instrumented Tests:
instrumented-tests:
  name: Run Android Tests
  runs-on: macos-latest
  timeout-minutes: 20
  strategy:
    matrix:
      api-level: [21, 23, 29]
      target: [default, google_apis]

  steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8

    - name: Run All Android Tests
      uses: reactivecircus/android-emulator-runner@v2.7.0
      #continue-on-error: true
      with:
        api-level: ${{ matrix.api-level }}
        target: ${{ matrix.target }}
        arch: x86_64
        script: ./gradlew connectedCheck

    - name: Upload emulator tests artifact
      uses: actions/upload-artifact@v1
      with:
        name: emulator_tests
        path: ./presentation/build/reports/androidTests/connected
  • Generate APK:
apk:
  name: Generate APK
  runs-on: ubuntu-18.04

  steps:
    - name: Checkout
      uses: actions/checkout@v1

    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8

    - name: Build Release APK
      run: bash ./gradlew assembleRelease --stacktrace

    - name: Upload Release APK
      uses: actions/upload-artifact@v1
      with:
        name: apk
        path: presentation/build/outputs/apk/release/presentation-release.apk

Here are the two configuration files I implemented for this example:

Clone this wiki locally