name: Build optimized

on:
  workflow_dispatch:
  push:
    branches:
      - master

jobs:
  linux:
    runs-on: ubuntu-latest
    container: ghcr.io/pyca/cryptography-manylinux_2_28:x86_64
    steps:
    - uses: actions/checkout@v4
    - name: Dependencies
      run: dnf install -y gtk3-devel zip
    - name: Build
      run: ./make-linux.sh
    - name: Upload Artifacts
      uses: actions/upload-artifact@v4.3.1
      with:
        name: linux-x64-gui.zip
        path: ./flips

  windows:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v4
    - name: Build
      run: bash ./make-windows.sh
    - name: Upload Artifacts
      uses: actions/upload-artifact@v4.3.1
      with:
        name: windows-x64-gui.zip
        path: ./flips.exe

  macos:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - name: Dependencies
      run: brew install gtk+3 libomp llvm
    - name: Build
      run: CXX=/opt/homebrew/opt/llvm/bin/clang++ TARGET=gtk ./make-macos.sh
    - name: Upload Artifacts
      uses: actions/upload-artifact@v4.3.1
      with:
        name: macos-m1-gui.zip
        path: ./flips


  create-release:
    runs-on: ubuntu-latest
    needs: [linux, windows, macos]
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Download binaries
      uses: actions/download-artifact@v4
      with:
        path: builds/
    - name: Find Flips version
      id: flips_version
      run: echo version=$(git rev-list --count master) >> $GITHUB_OUTPUT
    - name: Create zips
      run: |
        zip -9 ./flips-linux.zip ./builds/linux-x64-gui.zip/flips COPYING COPYING.gpl3
        zip -9 ./flips-windows.zip ./builds/windows-x64-gui.zip/flips.exe COPYING COPYING.gpl3
        #zip -9 ./flips-macos.zip ./builds/macos-m1-gui.zip/flips COPYING COPYING.gpl3
    - name: Upload GitHub Release
      uses: svenstaro/upload-release-action@2.9.0
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: flips-*.zip
        file_glob: true
        tag: v${{ steps.flips_version.outputs.version }}
        body: "A release of commit ${{ github.sha }}."
