name: Deploying

on:
  push:
    branches:
      - master
      - 'release-*'

jobs:
  build:
    runs-on: macos-15
    strategy:
      matrix:
        channel: ['beta', 'release']
    steps:
    - uses: actions/checkout@v4
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.3'
        bundler-cache: true
    - name: Setup Go
      uses: actions/setup-go@v5
      with:
        go-version: '1.23.x'
    - name: Installing packages
      run: |
        gem install bundler
    - uses: actions/cache@v4
      id: gopenpgp-cache
      with:
        path: go
        key: ${{ runner.os }}-gopenpgp-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/gopenpgp_build.sh') }}
    - name: Bundle Install
      run: |
        bundle config path vendor/bundle
        bundle install --jobs 4 --retry 3
    - name: GopenPGP
      if: ${{ steps.gopenpgp-cache.outputs.cache-hit == false }}
      run: |
        export PATH="/usr/local/opt/go/bin:$PATH"
        ./scripts/gopenpgp_build.sh
    - name: Test
      run: bundle exec fastlane test
    - name: Deploy
      run: bundle exec fastlane ${{ matrix.channel }}
      env:
        APPLE_ID: ${{ secrets.APPLE_ID }}
        APP_IDENTIFIER: ${{ secrets.APP_IDENTIFIER }}
        APP_STORE_CONNECT_API_KEY_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_ID }}
        APP_STORE_CONNECT_API_KEY_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }}
        APP_STORE_CONNECT_API_KEY_KEY_CONTENT: ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_CONTENT }}
        DESTINATION_EMAIL: ${{ secrets.DESTINATION_EMAIL }}
        EMAIL_FROM_NAME: ${{ secrets.EMAIL_FROM_NAME }}
        EMAIL_REPLY_TO: ${{ secrets.EMAIL_REPLY_TO }}
        FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }}
        FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }}
        FASTLANE_SESSION: ${{ secrets.FASTLANE_SESSION }}
        FASTLANE_USER: ${{ secrets.FASTLANE_USER }}
        ITC_TEAM_ID: ${{ secrets.ITC_TEAM_ID }}
        MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }}
        MATCH_KEYCHAIN_NAME: ${{ secrets.MATCH_KEYCHAIN_NAME }}
        MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
        MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
        MY_API_KEY: ${{ secrets.MY_API_KEY }}
        MY_POSTMASTER: ${{ secrets.MY_POSTMASTER }}
        TEAM_ID: ${{ secrets.TEAM_ID }}
