name: Release

on:
  release:
    types: [ created ]

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.release.tag_name }}
          fetch-depth: 0
      
      - name: Set up JDK 21
        uses: actions/setup-java@v5
        with:
          java-version: '21'
          distribution: 'temurin'
          
      - name: Grant execute permission for gradlew
        run: chmod +x gradlew
        
      - name: Build release bundle
        run: ./gradlew bundleRelease --stacktrace
        
      - name: Rename bundle
        run: mv app/build/outputs/bundle/release/app-release.aab prism.aab
        
      - name: Upload release bundle
        uses: actions/upload-artifact@v6
        with:
          name: prism-bundle
          path: prism.aab
          
      - name: Upload to release
        uses: softprops/action-gh-release@v2
        with:
          files: prism.aab
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
