name: Build macOS

on:
  workflow_dispatch:
  push:
    branches:
      - main
      - master
    paths:
      - 'lib/**'
      - 'macos/**'
      - 'pubspec.yaml'
      - '.github/workflows/build-macos.yml'
  pull_request:
    paths:
      - 'lib/**'
      - 'macos/**'
      - 'pubspec.yaml'
      - '.github/workflows/build-macos.yml'

env:
  FLUTTER_VERSION: '3.44.3'

jobs:
  build-macos:
    runs-on: macos-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v3

      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: ${{ env.FLUTTER_VERSION }}
          channel: 'stable'

      - name: Install create-dmg
        run: brew install create-dmg

      - name: Build signed DMG
        run: ./scripts/build_dmg.sh

      - name: Upload macOS DMG artifact
        uses: actions/upload-artifact@v4
        with:
          name: komet-macos
          path: dist/*.dmg
          if-no-files-found: error
          retention-days: 30
