name: Flutter CICD # action name

on:
  push:
    tags:
      - "v*"

jobs:
  build: # job's name
    runs-on: ubuntu-latest # container os
    env: # ADD environment variables
      KEY_JKS: ${{ secrets.KEY_JKS }}
      KEY_PATH: ${{ github.workspace }}/key.jks
      KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
      KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
    defaults:
      run:
        working-directory: app
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v2 # cd to current dir
      - uses: actions/setup-java@v2
        with:
          distribution: 'adopt' # See 'Supported distributions' for available options
          java-version: '17'
      - name: Create key file
        run: echo $KEY_JKS | base64 -di > $KEY_PATH
      - uses: subosito/flutter-action@v1
        with:
          flutter-version: 3.24.0
      - run: flutter pub get
      # - run: flutter test
      - run: flutter build apk --release --split-per-abi
      - run: flutter build appbundle
      - name: Create github artifact release # disable this to save storage
        uses: ncipollo/release-action@v1
        with:
          artifacts: "app/build/app/outputs/apk/release/*.apk,app/build/app/outputs/bundle/release/app-release.aab"
      - name: Upload app bundle artifact
        uses: actions/upload-artifact@v2
        with:
          name: appbundle
          path: app/build/app/outputs/bundle/release/app-release.aab