name: Release Artifacts

on:
  workflow_dispatch:
  release:
    types: [created]
permissions:
  contents: write
  packages: write
jobs:
  push:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        enable_security: [true, false]
        include:
          - enable_security: true
            file_suffix: "-with-login"
          - enable_security: false
            file_suffix: ""
    steps:
      - uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: "17"
          distribution: "temurin"

      - uses: gradle/actions/setup-gradle@v4
        with:
          gradle-version: 8.7

      - name: Generate jar (With Security=${{ matrix.enable_security }})
        run: ./gradlew clean createExe
        env:
          DOCKER_ENABLE_SECURITY: ${{ matrix.enable_security }}

      - name: Get version number
        id: versionNumber
        run: echo "versionNumber=$(./gradlew printVersion --quiet | tail -1)" >> $GITHUB_OUTPUT

      - name: Rename binarie
        if: matrix.file_suffix != ''
        run: cp ./build/launch4j/Stirling-PDF.exe ./build/launch4j/Stirling-PDF${{ matrix.file_suffix }}.exe

      - name: Upload Assets binarie
        uses: actions/upload-artifact@v4
        with:
          path: ./build/launch4j/Stirling-PDF${{ matrix.file_suffix }}.exe
          name: Stirling-PDF${{ matrix.file_suffix }}.exe
          overwrite: true
          retention-days: 1
          if-no-files-found: error
      - name: Upload binaries to release
        uses: softprops/action-gh-release@v2
        with:
          files: ./build/launch4j/Stirling-PDF${{ matrix.file_suffix }}.exe

      - name: Rename jar binaries
        run: cp ./build/libs/Stirling-PDF-${{ steps.versionNumber.outputs.versionNumber }}.jar ./build/libs/Stirling-PDF${{ matrix.file_suffix }}.jar

      - name: Upload Assets jar binaries
        uses: actions/upload-artifact@v4
        with:
          path: ./build/libs/Stirling-PDF${{ matrix.file_suffix }}.jar
          name: Stirling-PDF${{ matrix.file_suffix }}.jar
          overwrite: true
          retention-days: 1
          if-no-files-found: error

      - name: Upload jar binaries to release
        uses: softprops/action-gh-release@v2
        with:
          files: ./build/libs/Stirling-PDF${{ matrix.file_suffix }}.jar