name: Build

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

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

  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:
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      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 }}
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      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

  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 }}
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      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 }}
    secrets:
      FIREBASE_SERVICE_WORKER: ${{ secrets.FIREBASE_SERVICE_WORKER }}
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

  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 }}
      CODE_SIGNING_PUBLISHER: ${{ secrets.CODE_SIGNING_PUBLISHER }}
      CODE_SIGNING_PUBLISHER_NAME: ${{ secrets.CODE_SIGNING_PUBLISHER_NAME }}

  publish-android:
    name: Publish Android
    needs: [ prepare, build-android ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_android.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-motd: ${{ needs.prepare.outputs.build-motd }}
      build-title: ${{ needs.prepare.outputs.build-title }}
    secrets:
      GOOGLE_PLAY_API: ${{ secrets.GOOGLE_PLAY_API }}

  publish-ios:
    name: Publish iOS
    needs: [ prepare, build-ios ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_ios.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-motd: ${{ needs.prepare.outputs.build-motd }}
    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 }}

  publish-linux:
    name: Publish Linux
    needs: [ prepare, build-linux ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_linux.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
    secrets:
      SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}

  publish-macos:
    name: Publish macOS
    needs: [ prepare, build-macos ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_macos.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-motd: ${{ needs.prepare.outputs.build-motd }}
    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 }}

  publish-web:
    name: Publish Web
    needs: [ prepare, build-web ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_web.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-title: ${{ needs.prepare.outputs.build-title }}
    secrets:
      NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

  publish-s3:
    name: Publish S3
    needs: [ prepare, build-android, build-ios, build-linux, build-macos, build-web, build-windows ]
    uses: JagandeepBrar/LunaSea/.github/workflows/publish_s3.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-number: ${{ needs.prepare.outputs.build-number }}
      build-title: ${{ needs.prepare.outputs.build-title }}
    secrets:
      S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
      S3_BUCKET: ${{ secrets.S3_BUCKET }}
      S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
      S3_KEY_ID: ${{ secrets.S3_KEY_ID }}
      S3_REGION: ${{ secrets.S3_REGION }}

  notify:
    name: Notify
    needs: [ prepare, publish-s3 ]
    uses: JagandeepBrar/LunaSea/.github/workflows/notify.yml@master
    with:
      build-flavor: ${{ needs.prepare.outputs.build-flavor }}
      build-title: ${{ needs.prepare.outputs.build-title }}
    secrets:
      DISCORD_WEBHOOK_EDGE: ${{ secrets.DISCORD_WEBHOOK_EDGE }}
      DISCORD_WEBHOOK_BETA: ${{ secrets.DISCORD_WEBHOOK_BETA }}
      DISCORD_WEBHOOK_CANDIDATE: ${{ secrets.DISCORD_WEBHOOK_CANDIDATE }}
      DISCORD_WEBHOOK_STABLE: ${{ secrets.DISCORD_WEBHOOK_STABLE }}
