on:
  schedule:
    - cron: '30 23 * * 1,2,3,4,5'
  workflow_dispatch:
name: Distribute nightly debug build
jobs:
  setup-android:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          distribution: "zulu"
          java-version: 17

      - name: Setup middleware dependency
        env:
          token_secret: ${{ secrets.ANYTYPE_SECRET }}
          user_secret: ${{ secrets.ANYTYPE_USER_SECRET }}
          amplitude_secret: ${{ secrets.ANYTYPE_AMPLITUDE_SECRET }}
          amplitude_secret_debug: ${{ secrets.ANYTYPE_AMPLITUDE_DEBUG_SECRET }}
          sentry_dsn_secret: ${{ secrets.ANYTYPE_SENTRY_DSN_SECRET }}
        run: ./middleware2.sh $token_secret $user_secret $amplitude_secret $amplitude_secret_debug $sentry_dsn_secret

      - name: Enable dated version for nightly debug builds
        run: make enable_dated_version_name

      - name: Enable analytics for nightly debug builds
        run: make enable_analytics_for_debug

      - name: Decrypt secrets
        run: ./scripts/distribution/decrypt-secrets.sh
        env:
            ENCRYPT_KEY: ${{ secrets.ENCRYPT_KEY_FIREBASE_DISTRIBUTION }}

      - name: Distribute debug build
        run: make distribute_debug

      - name: Clean secrets
        if: always()
        run: ./scripts/distribution/clean-secrets.sh