name: Release Artifacts

on: 
  release: 
    types: [created]

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@v3.5.2
    
    - name: Set up JDK 17
      uses: actions/setup-java@v3.11.0
      with:
        java-version: '17'
        distribution: 'temurin'
        
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew

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

    - name: Upload binaries to release
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: ./build/launch4j/Stirling-PDF.exe
        asset_name: Stirling-PDF${{ matrix.file_suffix }}.exe
        tag: ${{ github.ref }}
        overwrite: true
    
    - name: Get version number
      id: versionNumber
      run: echo "::set-output name=versionNumber::$(./gradlew printVersion --quiet | tail -1)"
      
    - name: Upload jar binaries to release
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: ./build/libs/Stirling-PDF-${{ steps.versionNumber.outputs.versionNumber }}.jar
        asset_name: Stirling-PDF${{ matrix.file_suffix }}.jar
        tag: ${{ github.ref }}
        overwrite: true