name: Build Release

on:
  push:
    tags:
      - "*"
  workflow_dispatch:

jobs:
  build-web:
    runs-on: ubuntu-latest
    steps:
      - name: Clone repository
        uses: actions/checkout@v4
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          cache: true
      - run: flutter pub get
      - run: flutter build web --release
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-output-web
          path: build/web
  build-exe:
    runs-on: windows-latest
    steps:
      - name: Clone repository
        uses: actions/checkout@v4
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          cache: true
      - run: flutter pub get
      - run: flutter build windows
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-output-windows
          path: build/windows/x64/runner/Release
  build-linux:
    runs-on: ubuntu-latest
    steps:
      - name: Clone repository
        uses: actions/checkout@v4
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
      - run: |
          sudo apt-get update -y
          sudo apt-get install -y ninja-build libgtk-3-dev
          sudo apt-get install -y libmpv-dev mpv
          sudo apt-get install -y libayatana-appindicator3-dev
          sudo apt-get install -y keybinder-3.0
          sudo apt-get install -y libnotify-dev
          sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
          sudo apt-get install -y gstreamer-1.0
          sudo apt-get install -y libsecret-1-0
      - run: flutter pub get
      - run: flutter build linux
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-output-linux
          path: build/linux/x64/release/bundle
      - name: Build AppImage
        run: |
          rm -r Solian.AppDir | true
          mkdir Solian.AppDir
          cp -r build/linux/x64/release/bundle/* Solian.AppDir
          cp -r buildtools/appimage_config/* Solian.AppDir
          cp assets/icons/icon-padded.png Solian.AppDir
          sudo chmod +x buildtools/appimagetool-x86_64.AppImage
          sudo chmod +x Solian.AppDir/AppRun
          ./buildtools/appimagetool-x86_64.AppImage Solian.AppDir
      - name: Archive production artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-output-linux-appimage
          path: "./*.AppImage*"
