name: Deploy App Store
on:
  workflow_dispatch:
  push:
    branches:
      - develop
      - release*
jobs:
  deploy_appstore:
    name: Deploy App Store
    runs-on: macos-13
    steps:
      - name: Install SSH key
        uses: webfactory/ssh-agent@v0.5.3
        with:
          ssh-private-key: |
            ${{ secrets.MATCH_SSH_PRIVATE_KEY }}
      - name: Checkout Repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Setup Build Environment
        env:
          NotificationEndpointDebug: ${{ secrets.NotificationEndpointDebug }}
          NotificationEndpointRelease: ${{ secrets.NotificationEndpointRelease }}
        run: exec ./.github/scripts/setup.sh
      - name: Select required Xcode version
        run: sudo xcode-select -switch /Applications/Xcode_15.0.1.app
      - name: Deploy App Store
        env:
          MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
          ITC_KEY_ID: ${{ secrets.APPSTORE_KEY_ID }}
          ITC_ISSUER_ID: ${{ secrets.APPSTORE_ISSUER_ID }}
          ITC_KEY: ${{ secrets.APPSTORE_PRIVATE_KEY }}
        run: bundle exec fastlane ios deploy_appstore
      - name: Tag commit
        uses: tvdias/github-tagger@v0.0.1
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          tag: "${{ env.GITHUB_TAG_NAME }}"
