name: Release new Version

permissions:
  contents: write
  
on:
  workflow_dispatch:
  push:
    tags:
      - "v*.*.*"

jobs:
  build:
    name: Build and Release
    runs-on: self-hosted

    steps:
    - uses: actions/checkout@v4

    - name: Use Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20.x'

    - name: Install Frontend dependencies
      run: npm install
      working-directory: Frontend
      
    - name: Create .env file
      run: echo "VITE_APP_WEBSOCKET_IP=localhost" > .env
      working-directory: Frontend
      
    - name: Build Frontend
      run: npm run build
      working-directory: Frontend
    
    - name: Set up JDK 21
      uses: actions/setup-java@v4
      with:
        java-version: '21'
        distribution: 'temurin'
        architecture: x64
    
    - name: Set up Maven
      uses: stCarolas/setup-maven@v5
      with:
        maven-version: 3.8.2
        
    - name: Build Backend
      run: mvn -B package --file pom.xml
      working-directory: Backend

    - name: Archive dist folder
    #  run: mv Backend/target/schafkopf-backend-build-jar-with-dependencies.jar schafkopf-bot.jar && zip -r dist.zip schafkopf-bot.jar
      run: mv Backend/schafkopf-client/target/schafkopf-client-build-jar-with-dependencies.jar schafkopf-bot-client_${{ github.ref_name }}.jar
    
    - name: Release
      uses: softprops/action-gh-release@v2
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: schafkopf-bot-client_${{ github.ref_name }}.jar
        token: ${{ secrets.PAT }}

