name: "Build Linux"

on:
  workflow_call:
    inputs:
      build-number:
        required: true
        type: string
      build-version:
        required: true
        type: string

jobs:
  build-debian:
    name: Debian Archive
    runs-on: ubuntu-latest
    steps:
      - name: Setup Environment
        uses: JagandeepBrar/lunasea/.github/actions/prepare_for_build@master
        with:
          platform: linux

      - name: Build LunaSea
        run: flutter build linux

      - name: Prepare Artifact
        run: dart ${{github.workspace }}/scripts/generate_debian.dart "${{ inputs.build-version }}+${{ inputs.build-number }}"

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux-debian
          path: ${{ github.workspace }}/output

  build-tarball:
    name: Tarball Archive
    runs-on: ubuntu-latest
    steps:
      - name: Setup Environment
        uses: JagandeepBrar/lunasea/.github/actions/prepare_for_build@master
        with:
          platform: linux

      - name: Build LunaSea
        run: flutter build linux

      - name: Prepare Artifact
        run: tar czf output/lunasea-linux-amd64.tar.gz -C build/linux/x64/release/bundle/ .

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux-tarball
          path: ${{ github.workspace }}/output

  build-snapcraft:
    name: Snapcraft
    runs-on: ubuntu-latest
    steps:
      - name: Setup Environment
        uses: JagandeepBrar/lunasea/.github/actions/prepare_for_build@master
        with:
          platform: linux

      - name: Build LunaSea
        uses: snapcore/action-build@v1
        id: build

      - name: Prepare Artifact
        run: mv ${{ steps.build.outputs.snap }} ${{ github.workspace }}/output/lunasea-linux-amd64.snap

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: linux-snapcraft
          path: ${{ github.workspace }}/output
