name: Push translations to Transifex

on:
  push:
    branches:
      - '[0-9].*'
    paths:
      - '**/Translations/en_US/*.ini'
  workflow_dispatch:

permissions:
  contents: read

jobs:
  push-to-transifex:
    # Run only in the 'mautic/mautic' repository and on the default branch (or manually triggered via UI)
    if: github.repository == 'mautic/mautic' && (github.ref_name == github.event.repository.default_branch || github.event_name == 'workflow_dispatch')
    name: Push translations to Transifex
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup PHP with extensions
      uses: shivammathur/setup-php@v2
      with:
        php-version: 8.3
        extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql

    - name: Install Composer dependencies
      uses: "ramsey/composer-install@v3"

    - name: Push translations to Transifex
      env:
        MAUTIC_CONFIG_PARAMETERS: '{"transifex_api_token": "${{ secrets.TRANSIFEX_API_TOKEN }}"}'
      run: |
        echo "MAUTIC_CONFIG_PARAMETERS=${MAUTIC_CONFIG_PARAMETERS}" >> $GITHUB_ENV
        php bin/console mautic:transifex:push
