.github/workflows/build.yml

Summary

Maintainability
Test Coverage
# Copyright (c) 2021 Armel Soro
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in all
#  copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#  SOFTWARE.
name: CI

on:
  push:
    branches:
      - master
    tags:
      - '*'
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      - uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/wrapper
            ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      - name: "Set environmental variables"
        run: |
          echo "KEYSTORE=$(pwd)/debug.keystore" >> $GITHUB_ENV

      - name: Prepare scripts
        run: chmod +x gradlew

      - name: Prepare local.properties
        env:
          MAONI_GITHUB_USERNAME: ${{ secrets.MAONI_GITHUB_USERNAME }}
          MAONI_GITHUB_PASSWORD_TOKEN: ${{ secrets.MAONI_GITHUB_PASSWORD_TOKEN }}
          MAONI_JIRA_REST_BASEURL: ${{ secrets.MAONI_JIRA_REST_BASEURL }}
          MAONI_JIRA_USERNAME: ${{ secrets.MAONI_JIRA_USERNAME }}
          MAONI_JIRA_PASSWORD: ${{ secrets.MAONI_JIRA_PASSWORD }}
        run: |
          echo "github.username=${MAONI_GITHUB_USERNAME}" > local.properties
          echo "github.passwordToken=${MAONI_GITHUB_PASSWORD_TOKEN}" >> local.properties
          echo "jira.rest.baseUrl=${MAONI_JIRA_REST_BASEURL}" >> local.properties
          echo "jira.username=${MAONI_JIRA_USERNAME}" >> local.properties
          echo "jira.password=${MAONI_JIRA_PASSWORD}" >> local.properties

      - name: Prepare maoni-keystore.properties
        env:
          STORE_PASSWORD: 'android'
          KEY_ALIAS: 'androiddebugkey'
          KEY_PASSWORD: 'android'
        run: |
          mkdir -p ~/.droid
          echo "keystore=${KEYSTORE}" > ~/.droid/maoni-keystore.properties
          echo "storePassword=${STORE_PASSWORD}" >> ~/.droid/maoni-keystore.properties
          echo "keyAlias=${KEY_ALIAS}" >> ~/.droid/maoni-keystore.properties
          echo "keyPassword=${KEY_PASSWORD}" >> ~/.droid/maoni-keystore.properties

      - name: Prepare PlayStore.keys.json
        env:
          PLAYSTORE_KEYS_JSON: ${{ secrets.PLAYSTORE_KEYS_JSON }}
        run: |
          mkdir -p ~/.droid
          echo "${PLAYSTORE_KEYS_JSON}" > ~/.droid/PlayStore.keys.json

      - name: Download dependencies
        run: ./gradlew androidDependencies --stacktrace

      - name: Run Tests
        run: ./gradlew clean lintDebug testDebug --stacktrace

      - name: Build APK
        run: ./gradlew build assembleDebug --stacktrace

      - name: Code Coverage
        run: bash <(curl -s https://codecov.io/bash)

      - name: Archive sample app artifacts
        uses: actions/upload-artifact@v3
        with:
          name: maoni-sample_outputs
          path: |
            maoni-sample/build/outputs

      - name: Archive build reports
        uses: actions/upload-artifact@v3
        with:
          name: reports
          path: |
            **/build/reports

      - name: Archive test results
        uses: actions/upload-artifact@v3
        with:
          name: reports
          path: |
            **/build/test-results

  publishLibraries:
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v4

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

      - uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/wrapper
            ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      # Base64 decodes and pipes the GPG key content into the secret file
      - name: Prepare environment
        env:
          GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
          SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
        run: |
          git fetch --unshallow
          sudo bash -c "echo '$GPG_KEY_CONTENTS' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'"

      - name: "Set environmental variables"
        run: |
          echo "KEYSTORE=$(pwd)/debug.keystore" >> $GITHUB_ENV

      - name: Prepare scripts
        run: chmod +x gradlew

      - name: Prepare local.properties
        env:
          OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
          SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
          SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
          SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
          SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

          MAONI_GITHUB_USERNAME: ${{ secrets.MAONI_GITHUB_USERNAME }}
          MAONI_GITHUB_PASSWORD_TOKEN: ${{ secrets.MAONI_GITHUB_PASSWORD_TOKEN }}
          MAONI_JIRA_REST_BASEURL: ${{ secrets.MAONI_JIRA_REST_BASEURL }}
          MAONI_JIRA_USERNAME: ${{ secrets.MAONI_JIRA_USERNAME }}
          MAONI_JIRA_PASSWORD: ${{ secrets.MAONI_JIRA_PASSWORD }}
        run: |
          echo "signing.keyId=${SIGNING_KEY_ID}" > local.properties
          echo "signing.password=${SIGNING_PASSWORD}" >> local.properties
          echo "signing.secretKeyRingFile=${SIGNING_SECRET_KEY_RING_FILE}" >> local.properties
          echo "ossrhUsername=${OSSRH_USERNAME}" >> local.properties
          echo "ossrhPassword=${OSSRH_PASSWORD}" >> local.properties
          echo "sonatypeStagingProfileId=${SONATYPE_STAGING_PROFILE_ID}" >> local.properties

          echo "github.username=${MAONI_GITHUB_USERNAME}" >> local.properties
          echo "github.passwordToken=${MAONI_GITHUB_PASSWORD_TOKEN}" >> local.properties
          echo "jira.rest.baseUrl=${MAONI_JIRA_REST_BASEURL}" >> local.properties
          echo "jira.username=${MAONI_JIRA_USERNAME}" >> local.properties
          echo "jira.password=${MAONI_JIRA_PASSWORD}" >> local.properties

      - name: Prepare maoni-keystore.properties
        env:
          STORE_PASSWORD: 'android'
          KEY_ALIAS: 'androiddebugkey'
          KEY_PASSWORD: 'android'
        run: |
          mkdir -p ~/.droid
          echo "keystore=${KEYSTORE}" > ~/.droid/maoni-keystore.properties
          echo "storePassword=${STORE_PASSWORD}" >> ~/.droid/maoni-keystore.properties
          echo "keyAlias=${KEY_ALIAS}" >> ~/.droid/maoni-keystore.properties
          echo "keyPassword=${KEY_PASSWORD}" >> ~/.droid/maoni-keystore.properties

      - name: Prepare PlayStore.keys.json
        env:
          PLAYSTORE_KEYS_JSON: ${{ secrets.PLAYSTORE_KEYS_JSON }}
        run: |
          mkdir -p ~/.droid
          echo "${PLAYSTORE_KEYS_JSON}" > ~/.droid/PlayStore.keys.json

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      # Generates artifacts
      - name: Build other artifacts
        run: ./gradlew build javadoc

      # Runs upload, and then closes & releases the repository
      - name: Publish to MavenCentral
        run: ./gradlew publishToSonatype --max-workers 1 closeAndReleaseStagingRepository