name: Look4Sat CI

on:
  push:
    tags:
      - '*'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout latest commit
        uses: actions/checkout@v2

      - name: Setup java environment
        uses: actions/setup-java@v1
        with: {java-version: 11}

      - name: Assemble APK and Bundle
        run: |
          chmod +x ./gradlew
          ./gradlew assembleRelease
          ./gradlew bundleRelease

      - name: Sign APK
        uses: r0adkll/sign-android-release@v1
        id: sign_apk
        with:
          releaseDirectory: app/build/outputs/apk/release
          signingKeyBase64: ${{ secrets.KEY_STORE }}
          keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
          alias: ${{ secrets.KEY_ALIAS }}
          keyPassword: ${{ secrets.KEY_PASSWORD }}
        env:
          BUILD_TOOLS_VERSION: "31.0.0"

      - name: Sign Bundle
        uses: r0adkll/sign-android-release@v1
        id: sign_bundle
        with:
          releaseDirectory: app/build/outputs/bundle/release
          signingKeyBase64: ${{ secrets.KEY_STORE }}
          keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
          alias: ${{ secrets.KEY_ALIAS }}
          keyPassword: ${{ secrets.KEY_PASSWORD }}
        env:
          BUILD_TOOLS_VERSION: "31.0.0"

      - name: Deploy Bundle to Play Store
        uses: r0adkll/upload-google-play@v1
        with:
          serviceAccountJsonPlainText: ${{secrets.SERVICE_ACCOUNT_JSON}}
          packageName: com.rtbishop.look4sat
          track: production
          whatsNewDirectory: fastlane/metadata/android/en-US/whatsnew
          releaseFiles: ${{steps.sign_bundle.outputs.signedReleaseFile}}

      - name: Create release
        uses: ncipollo/release-action@v1
        with:
          artifacts: ${{steps.sign_apk.outputs.signedReleaseFile}}
          bodyFile: fastlane/metadata/android/en-US/whatsnew/whatsnew-en-US
          token: ${{ secrets.RELEASE_TOKEN }}
