name: Deploy App CI

on:
  push:
#     branches: 
#     - master
    tags: 
    - '*'

jobs:
  build:

    runs-on: ubuntu-latest

    steps:

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

      - name: Checkout
        uses: actions/checkout@v2

      - name: set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - name: Grant rights
        run: chmod +x build.gradle

        
      - name: Grant Gradlew rights
        run: chmod +x gradlew

      - name: Build with Gradle
        id: build
        run: ./gradlew build

      - name: Build Release AAB
        id: buildRelease
        run: ./gradlew bundleProductionRelease

      - name: Sign AAB
        id: sign
        uses: r0adkll/sign-android-release@fix/bundle-signing
        with:
          releaseDirectory: app/build/outputs/bundle/productionRelease
          signingKeyBase64: ${{ secrets.SIGNING_KEY }}
          alias: ${{ secrets.ALIAS }}
          keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
          keyPassword: ${{ secrets.KEY_PASSWORD }}

      - name: Create service_account.json
        id: createServiceAccount
        run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json

      - name: Deploy to Play Store (BETA)
        id: deploy
        uses: r0adkll/upload-google-play@v1.0.15
        with:
          serviceAccountJson: service_account.json
          packageName: com.yogeshpaliyal.keypass
          releaseFiles: app/build/outputs/bundle/productionRelease/*.aab
          track: beta
          whatsNewDirectory: whatsnew/
