name: 🌍 Sync Translations
on:
  schedule:
    - cron: "5 1 * * *"
  workflow_dispatch:

jobs:
  sync_translations:
    runs-on: ubuntu-22.04
    if: ${{ github.repository == 'opengisch/QField' }}
    steps:
      - uses: actions/checkout@v4
        with:
          token: ${{ secrets.FAIRY_TOKEN }}

      - name: Install Requirements
        run: |
          sudo apt-get install -y qttools5-dev-tools
          # v1.6.5: 2023-02-16
          curl -OL https://github.com/transifex/cli/releases/download/v1.6.5/tx-linux-amd64.tar.gz
          tar -xvzf tx-linux-amd64.tar.gz

      - name: 🌍 Pull Translations
        shell: bash
        env:
          tx_token: ${{ secrets.TX_TOKEN }}
        run: |
          TX_TOKEN=$tx_token ./scripts/ci/pull_translations.sh

      - uses: EndBug/add-and-commit@v9
        with:
          message: Synchronize translations
          author_name: Translation update 💬
          author_email: info@opengis.ch
          add: '["platform", "i18n"]'
