name: Build for Android

on: workflow_dispatch

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Download Android keystore
        id: android_keystore
        uses: timheuer/base64-to-file@v1.0.3
        with:
          fileName: upload-keystore.jks
          encodedString: ${{ secrets.KEYSTORE_BASE64 }}
      - name: Create key.properties
        run: |
          echo "storeFile=${{ steps.android_keystore.outputs.filePath }}" > refilc/android/key.properties
          echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> refilc/android/key.properties
          echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> refilc/android/key.properties
          echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> refilc/android/key.properties
      - uses: actions/setup-java@v3
        with:
          distribution: "zulu"
          java-version: "17.x"
          cache: "gradle"
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.10.2"
          channel: "stable"
          cache: "true"
      - name: Install dependencies
        run: ./fix-pub.sh
      - name: Build
        run: cd refilc && ./build.sh
      - name: Upload Android Release
        uses: actions/upload-artifact@v2
        with:
          name: android-release
          path: build/outputs/flutter-apk/app-release.apk
