on:
  push:
    tags:
      - "*"

name: Linux build and release
jobs:
  linux:
    name: Linux
    runs-on: ubuntu-latest
    steps:
      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          cache: true
          flutter-version: "3.24.5"
          channel: "stable"

      - uses: actions/checkout@v4
        with:
          path: "app"

      - name: Cache pub dependencies
        uses: actions/cache@v3
        with:
          path: |
            ${{ env.PUB_CACHE }}
            app/.dart_tool
          key: ${{ runner.os }}-pub-${{ hashFiles('app/**/pubspec.lock') }}
          restore-keys: |
            ${{ runner.os }}-pub-

      - name: Install required build tools for linux
        run: |
          sudo apt-get update -y
          sudo apt-get upgrade -y
          sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa
          sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev

      - name: Enable linux desktop support
        run:  flutter config --enable-linux-desktop

      - name: Install pub dependencies
        run: cd app && flutter pub get

      - run: |
          cd app
          flutter build linux --release
          cd build/linux/x64/release
          zip -r linux-release.zip bundle

      - name: Create linux Release
        uses: ncipollo/release-action@v1
        with:
          artifacts: "app/build/linux/x64/release/linux-release.zip"
          token: ${{ secrets.TOKEN }}
          allowUpdates: true
