name: Release

on:
  push:
    tags:
      - "*"

permissions:
  contents: write

env:
  FLUTTER_VERSION: 3.41.6

jobs:
  build-android:
    uses: ./.github/workflows/android-build.yml
    secrets: inherit
    with:
      flutter_version: ${{ vars.FLUTTER_VERSION }}
      workflow_profile: release
      build_mode: release_common
      artifact_name: APK
      signing_required: true

  build-android-full:
    uses: ./.github/workflows/android-build.yml
    secrets: inherit
    with:
      flutter_version: ${{ vars.FLUTTER_VERSION }}
      workflow_profile: release
      build_mode: release_full
      artifact_name: APK-FULL
      signing_required: true

  build-windows:
    uses: ./.github/workflows/windows-build.yml
    with:
      flutter_version: ${{ vars.FLUTTER_VERSION }}
      workflow_profile: release
      artifact_name: Windows
      package_release_artifacts: true
      msix_skip_clean: false

  build-linux:
    uses: ./.github/workflows/linux-build.yml
    with:
      flutter_version: ${{ vars.FLUTTER_VERSION }}
      workflow_profile: release
      artifact_name: Linux
      package_release_artifacts: true

  release:
    name: Release
    runs-on: ubuntu-latest
    needs: [build-android, build-android-full, build-windows, build-linux]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download artifacts
        uses: actions/download-artifact@v4

      - uses: ncipollo/release-action@v1
        with:
          artifacts: "APK/ciyue-*-release.apk,APK-FULL/ciyue-*-full.apk,Windows/*,Linux/*"
          tag: ${{ github.ref_name }}
          generateReleaseNotes: true
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
