# name of the workflow
name: Android Build CI/CD

on:
  push:
    branches: countly
    # pull_request:
    # branches: [ staging ]
    tags:
      - 'v*'

jobs:
  android-build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - uses: actions/checkout@v3
        with:
          path: android
      ## cache Gradle dependencies and wrapper to reduce build time
      - name: Cache Gradle Wrapper
        uses: actions/cache@v3
        with:
          path: ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
      - name: Cache Gradle Dependencies
        uses: actions/cache@v3
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-caches-
      - name: Make Gradlew Executable
        run:  cd android && chmod +x ./gradlew
      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3)
      # Building and signing App
      - name: Build Android App Apk
        run: cd android && ./gradlew assembleRelease
      # Building and signing App
      - name: Build Android App Bundle
        run: cd android && ./gradlew bundleRelease
      - name: Sign AAB
        uses: r0adkll/sign-android-release@v1
        # ID used to access action output
        id: sign_app_bundle
        with:
          releaseDirectory: android/app/build/outputs/bundle/release
          signingKeyBase64: ${{ secrets.RELEASE_SIGNING_KEY }}
          alias: ${{ secrets.RELEASE_ALIAS }}
          keyStorePassword: ${{ secrets.RELEASE_KEY_STORE_PASSWORD }}
          keyPassword: ${{ secrets.RELEASE_KEY_PASSWORD }}
      - name: Upload Artifact
        uses: actions/upload-artifact@v2
        with:
          name: Signed app bundle
          path: ${{steps.sign_app_bundle.outputs.signedReleaseFile}}
          retention-days: 4
      - name: Sign APK
        uses: r0adkll/sign-android-release@v1
        # ID used to access action output
        id: sign_app_apk
        with:
          releaseDirectory: android/app/build/outputs/apk/release
          signingKeyBase64: ${{ secrets.RELEASE_SIGNING_KEY }}
          alias: ${{ secrets.RELEASE_ALIAS }}
          keyStorePassword: ${{ secrets.RELEASE_KEY_STORE_PASSWORD }}
          keyPassword: ${{ secrets.RELEASE_KEY_PASSWORD }}
      - name: Upload Artifact
        uses: actions/upload-artifact@v2
        with:
          name: Signed app apk
          path: ${{steps.sign_app_apk.outputs.signedReleaseFile}}
          retention-days: 4
          # rename apk/aar
      - name: Zip Release Mapping
        run: |
          tar -czf mapping.tar.gz android/app/build/outputs/mapping/
          cp mapping.tar.gz app-release-mapping-v${{ steps.get_version.outputs.VERSION }}.tar.gz
          cp ${{steps.sign_app_bundle.outputs.signedReleaseFile}} app-release-${{ steps.get_version.outputs.VERSION }}.aab
          cp ${{steps.sign_app_apk.outputs.signedReleaseFile}} app-release-${{ steps.get_version.outputs.VERSION }}.apk
      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          draft: false
          files: |
            app-release-mapping-v${{ steps.get_version.outputs.VERSION }}.tar.gz
            app-release-${{ steps.get_version.outputs.VERSION }}.aab
            app-release-${{ steps.get_version.outputs.VERSION }}.apk
      - name: print-info
        run: |
          echo "signedReleaseFile::::${{steps.sign_app_apk.outputs.signedReleaseFile}}"
          echo "signedReleaseFile::::${{steps.sign_app_bundle.outputs.signedReleaseFile}}"
          echo "upload_url::::${{ steps.create_release.outputs.upload_url }}"
          echo "upload_url::::${{ steps.get_version.outputs.VERSION }}"

don't forget fill in github env

RELEASE_SIGNING_KEY
RELEASE_ALIAS
RELEASE_KEY_STORE_PASSWORD
RELEASE_KEY_PASSWORD

convert ssl to base64

openssl base64 <release.key | tr -d '\n' | tee my-upload-key.keystore.base64.txt