
name: Create Release Packages
on:
  workflow_dispatch:
    inputs:
      release_tag:
        description: 'Release tag (tag/sha/branch)'
        required: true
        type: string
      release_version:
        description: 'Release version (x.y.z)'
        required: true
        type: string
        
jobs:
  build_linux:
    name: Linux Build
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.release_tag }}
        
      - uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '11'
      
      - name: Run tests
        shell: bash
        run: |
          ant -noinput -buildfile build.xml testall
      
      - name: Install pdflatex
        shell: bash
        run: |
          sudo apt-get install -y texlive-latex-base texlive-latex-recommended texlive-latex-extra
          
      - name: Build artifacts
        shell: bash
        run: |
          ant -noinput -buildfile build.xml -Dfreecol.version=$FREECOL_VERSION dist
        env:
          FREECOL_VERSION: ${{ github.event.inputs.release_version }}
      
      - uses: actions/upload-artifact@v3
        with:
          name: Linux-packages
          path: dist/

  build_windows:
    name: Windows Build
    runs-on: windows-latest
    
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.release_tag }}
        
      - uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '19'

      - name: Build artifacts
        shell: cmd
        run: |
          ant -noinput -buildfile build.xml -Dfreecol.version=%FREECOL_VERSION% -Dprint.manual.is.up.to.date=true -Dprint.devmanual.is.up.to.date=true win-complete-installer
        env:
          FREECOL_VERSION: ${{ github.event.inputs.release_version }}
          
      - uses: actions/upload-artifact@v3
        with:
          name: Windows-packages
          path: dist/releases/

  build_mac:
    name: Mac Build
    runs-on: macos-latest
    
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.release_tag }}
        
      - uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '19'

      - name: Build artifacts
        shell: bash
        run: |
          ant -noinput -buildfile build.xml -Dfreecol.version=$FREECOL_VERSION -Dprint.manual.is.up.to.date=true -Dprint.devmanual.is.up.to.date=true mac-complete-installer
        env:
          FREECOL_VERSION: ${{ github.event.inputs.release_version }}
      
      - uses: actions/upload-artifact@v3
        with:
          name: Mac-packages
          path: dist/releases/
