Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

CI via GitHub actions

This page documents how to configure Github actions CI to execute unit tests and submit coverage to coveralls for the migration from Travis-CI

Android Apps or Libraries Repositories

  1. For android apps use this as the CI config file on the path .github/workflows/ci.yml

  2. Installing the NDK is might be necessitated by the build version you are using, the given NGD below is for build 29.0.3

    Code Block
    # This workflow will build a Java project with Gradle
    # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
    
    name: Android CI with Gradle
    
    on:
      push:
        branches: [ master ]
      pull_request:
        branches: [ master ]
    
    jobs:
      unit_tests:
    
        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: Install NDK
          run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.0.6113669" --sdk_root=${ANDROID_SDK_ROOT}
        - name: Grant execute permission for gradlew
          run: chmod +x gradlew
        - name: Run unit tests with Gradle
          run: ./gradlew :opensrp-chw-core:jacocoTestReport  --stacktrace
        - name: Generate Javadoc with Gradle
          run: ./gradlew javadoc
        - name: Upload coverage to Coveralls with Gradle
          run: ./gradlew coveralls --stacktrace
          env:
            COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
    

  3. Delete .travis file

  4. Upgrade coveralls to the latest version which supports github actions 2.10.2

  5. To upgrade coveralls make the below changes in root build.gradle

    Code Block
    buildscript {
    
        repositories {
    
            maven{  url "https://plugins.gradle.org/m2/" }
        }
    }
    dependencies {
        
          classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.10.2'
      }
      
      allprojects {
    
      repositories {
          maven{  url "https://plugins.gradle.org/m2/" }
      }
    }
    
    
  6. To upgrade coveralls remove older dependencies in application or library build.gradle

    Code Block
    buildscript {
      
    
        dependencies {
            //remove any older coveralls-gradle-plugin depencies
        }
    }
  7. Get the repository token from coveralls from http://coveralls.io/github/OpenSRP/<<your_repo>>

  8. Create a Github secret called COVERALLS_TOKEN with the value retrieved from step 3. Use the this link to create secrets https://github.com/OpenSRP/<<your_repo>>/settings/secrets/new

  9. Update settings and change branch protection rules to have as mandatory checks while removing travis actions as mandatory

  10. Test and confirm unit tests were run and coveralls check succeeded

Server Repositories

Use below as the CI file. The same procedures for the android apps apply except steps 3-5

Code Block
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  run-unit-tests:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Run Unit tests with Maven
      run: mvn -B clean test jacoco:report --file pom.xml --no-transfer-progress
    - name: Set Branch name Environment variable 
      env:
        BRANCH_NAME_OR_REF: ${{ github.head_ref || github.ref }}
      run: echo "BRANCH_NAME=${BRANCH_NAME_OR_REF#refs/heads/}" >> $GITHUB_ENV
    - name: Set PR Number Environment variable 
      run: |
        echo "PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")" >> $GITHUB_ENV
    - name: Upload coveralls report
      env:
        COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
      run: |
         mvn -B coveralls:report --file pom.xml \
          --no-transfer-progress \
          -D repoToken="$COVERALLS_REPO_TOKEN" \
          -D serviceName=Github \
          -D branch="$BRANCH_NAME" \
          -D pullRequest="$PR_NUMBER" \

ReadME file

Once you have migrated to Github actions replace the Travis badge on ReadME.md with
![Build status](https://github.com/OpenSRP/<project-handle-here>/workflows/Android%20CI%20with%20Gradle/badge.svg)
NB:

...