name: Build arm64 tar

on:
  workflow_dispatch:

env:
  FLUTTER_VERSION: "3.41.9"

jobs:
  build:
    runs-on: ubuntu-22.04
    outputs:
      version: ${{ steps.get_version.outputs.version }}

    steps:
      - uses: actions/checkout@v6

      - name: Get version from pubspec.yaml
        id: get_version
        run: |
          VERSION=$(sed -n 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' app/pubspec.yaml)
          echo "version=$VERSION" >> $GITHUB_OUTPUT

  # Manage the Flutter version on the self-hosted runner manually!
  # Flutter currently doesn't provide Linux ARM64 binaries.
  build_tar_arm_64:
    needs: build
    runs-on: [self-hosted, linux, arm64]

    steps:
      - uses: actions/checkout@v6

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y clang cmake libgtk-3-dev ninja-build libayatana-appindicator3-dev

      - name: Dependencies
        working-directory: app
        run: flutter pub get

      - name: Compile linux
        working-directory: app
        run: flutter build linux

      - name: Create tar.gz archive
        run: |
          cd app/build/linux/arm64/release/bundle
          tar -czvf ../../../../../result.tar.gz *

      - name: Upload tar.gz archive
        uses: actions/upload-artifact@v6
        with:
          name: tar-gz-arm-64-result
          path: ./app/*.tar.gz
