name: Build
run-name: "Build Release: ${{ inputs.flavor || github.sha }}"

on:
  push:
    branches:
      - master
  workflow_dispatch:
    inputs:
      flavor:
        description: Build Flavor
        required: true
        default: edge
        type: choice
        options:
          - edge
          - beta
          - stable

jobs:
  prepare:
    name: Prepare
    uses: JagandeepBrar/lunasea/.github/workflows/prepare.yml@master
    with:
      flavor: ${{ inputs.flavor }}

  build-android:
    name: Build Android
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_android.yml@master
    with:
      build-number: ${{ needs.prepare.outputs.build-number }}
    secrets:
      KEY_JKS: ${{ secrets.KEY_JKS }}
      KEY_PROPERTIES: ${{ secrets.KEY_PROPERTIES }}

  build-ios:
    name: Build iOS
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_ios.yml@master
    with:
      build-number: ${{ needs.prepare.outputs.build-number }}
    secrets:
      APPLE_ID: ${{ secrets.APPLE_ID }}
      APPLE_ITC_TEAM_ID: ${{ secrets.APPLE_ITC_TEAM_ID }}
      APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
      IOS_CODESIGNING_IDENTITY: ${{ secrets.IOS_CODESIGNING_IDENTITY }}
      MATCH_KEYCHAIN_NAME: ${{ secrets.MATCH_KEYCHAIN_NAME }}
      MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
      MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
      MATCH_SSH_PRIVATE_KEY: ${{ secrets.MATCH_SSH_PRIVATE_KEY }}

  build-linux:
    name: Build Linux
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_linux.yml@master
    with:
      build-number: ${{ needs.prepare.outputs.build-number }}
      build-version: ${{ needs.prepare.outputs.build-version }}

  build-macos:
    name: Build macOS
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_macos.yml@master
    with:
      build-number: ${{ needs.prepare.outputs.build-number }}
      build-version: ${{ needs.prepare.outputs.build-version }}
    secrets:
      APPLE_ID: ${{ secrets.APPLE_ID }}
      APPLE_ITC_TEAM_ID: ${{ secrets.APPLE_ITC_TEAM_ID }}
      APPLE_STORE_CONNECT_ISSUER_ID: ${{ secrets.APPLE_STORE_CONNECT_ISSUER_ID }}
      APPLE_STORE_CONNECT_KEY: ${{ secrets.APPLE_STORE_CONNECT_KEY }}
      APPLE_STORE_CONNECT_KEY_ID: ${{ secrets.APPLE_STORE_CONNECT_KEY_ID }}
      APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
      MACOS_INSTALLER_CERT_APP_STORE: ${{ secrets.MACOS_INSTALLER_CERT_APP_STORE }}
      MACOS_INSTALLER_CERT_DIRECT: ${{ secrets.MACOS_INSTALLER_CERT_DIRECT }}
      MATCH_KEYCHAIN_NAME: ${{ secrets.MATCH_KEYCHAIN_NAME }}
      MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
      MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
      MATCH_SSH_PRIVATE_KEY: ${{ secrets.MATCH_SSH_PRIVATE_KEY }}

  build-web:
    name: Build Web
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_web.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-title: ${{ needs.prepare.outputs.build-title }}

  build-windows:
    name: Build Windows
    needs: [prepare]
    uses: JagandeepBrar/lunasea/.github/workflows/build_windows.yml@master
    secrets:
      CODE_SIGNING_CERTIFICATE: ${{ secrets.CODE_SIGNING_CERTIFICATE }}
      CODE_SIGNING_PASSWORD: ${{ secrets.CODE_SIGNING_PASSWORD }}
