name: Release
on:
  push:
    tags:
      - 'v*'

jobs:
  build-macos:
    runs-on: macos-latest
    steps:
      - 
        name: Checkout
        uses: actions/checkout@v2
      - 
        name: Setup FFMPEG
        uses: FedericoCarboni/setup-ffmpeg@v1
        id: setup_ffmpeg
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - 
        name: Install PyOxidizer
        run: python3 -m pip install pyoxidizer
      - 
        name: Build Hydrus
        run: |
          cd $GITHUB_WORKSPACE
          cp ${{ steps.setup_ffmpeg.outputs.ffmpeg-path }} bin/
          cp static/build_files/macos/pyoxidizer.bzl pyoxidizer.bzl
          cp static/build_files/linux/requirements.txt requirements.txt
          basename $(rustc --print sysroot) | sed -e "s/^stable-//" > triple.txt
          pyoxidizer build --release
          cd build/$(head -n 1 triple.txt)/release
          mkdir -p "Hydrus Network.app/Contents/MacOS"
          mkdir -p "Hydrus Network.app/Contents/Resources"
          mkdir -p "Hydrus Network.app/Contents/Frameworks"
          mv install/static/icon.icns "Hydrus Network.app/Contents/Resources/icon.icns"
          cp install/static/build_files/macos/Info.plist "Hydrus Network.app/Contents/Info.plist"
          cp install/static/build_files/macos/ReadMeFirst.rtf ./ReadMeFirst.rtf
          cp install/static/build_files/macos/running_from_app "install/running_from_app"
          ln -s /Applications ./Applications
          mv install/* "Hydrus Network.app/Contents/MacOS/"
          rm -rf install
          cd $GITHUB_WORKSPACE
          temp_dmg="$(mktemp).dmg"
          hdiutil create "$temp_dmg" -ov -volname "HydrusNetwork" -fs HFS+ -srcfolder "$GITHUB_WORKSPACE/build/$(head -n 1 triple.txt)/release"
          hdiutil convert "$temp_dmg" -format UDZO -o HydrusNetwork.dmg
      -   
        name: Upload a Build Artifact
        uses: actions/upload-artifact@v2.2.1
        with:
          name: MacOS-DMG
          path: HydrusNetwork.dmg
          if-no-files-found: error
          retention-days: 2