name: Create APK from Master

on:
  workflow_dispatch:
  push:
    branches:
    - master
    paths-ignore:
      - 'fastlane/**'
      - '.github/**'
      - 'icons/**'
      - 'images/**'
      - 'scripts/**'
      - 'whatsnew/**'
      - '**.md'
      - '**.MD'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
  
    - name: Setting up project
      uses: ./.github/actions/setup
      
    - name: Build APK ⚙️🛠
      run: bash ./gradlew assembleStagingDebug

    - name: 🏗 Master Bump App Version
      id: bump-app-version
      run: |
        newVersion=$(bash ./scripts/masterVersion.sh)
        echo "::newVersion::$newVersion"
        echo "newVersion=$newVersion" >> "$GITHUB_OUTPUT"
      env:
        TYPE: ${{ inputs.type }}
        RELEASE_NOTES: ${{ inputs.releaseNote }}      

    - name: Git push tag
      run: |
        git tag -a latest-master -m "Release version ${{ steps.bump-app-version.outputs.newVersion }}" -f
        git push origin latest-master -f
    
    

    - uses: "marvinpinto/action-automatic-releases@latest"
      with:
          repo_token: "${{ github.token }}"
          automatic_release_tag: "latest-master"
          prerelease: true
          title: "Staging Build"
          files: app/build/outputs/apk/staging/debug/*.apk
