---
name: 🗝️ Generate certificates and synchronize profiles

on:
  schedule:
    - cron:  '30 2 15 * *'
  workflow_dispatch:

jobs:
  sync_certs:
    name: sync certs
    runs-on: macos-15
    if: ${{ github.repository == 'opengisch/QField' }}

    steps:
      - name: 🐣 Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: ⛓️ Setup SSH
        uses: webfactory/ssh-agent@v0.9.0
        with:
          ssh-private-key: ${{ secrets.SSH_KEY_DEPLOYMENT_CERTIFICATES }}

      - name: 🔏 Sync certs
        env:
          issuer_id: ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
          api_key_id: ${{ secrets.IOS_APPSTORE_KEY_ID }}
          api_private_key: ${{ secrets.IOS_APPSTORE_PRIVATE_KEY }}
          MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
        run: |
          bundle install
          bundle exec fastlane ios generate_new_certificates
