name: Publish to Crowdin
on:
  schedule:
    - cron: '0 12 * * THU'
  repository_dispatch:
    types: crowdin

env:
  CROWDIN_API_KEY: ${{ secrets.crowdin_token}}
  CROWDIN_PROJECT_ID: ${{ secrets.crowdin_identifier }}

jobs:
  deploy:
    if: github.repository == 'Cog-Creators/Red-DiscordBot'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: '3.8'
    - name: Install dependencies
      run: |
        curl https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -
        echo "deb https://artifacts.crowdin.com/repo/deb/ /" | sudo tee -a /etc/apt/sources.list
        sudo apt-get update -qq
        sudo apt-get install -y crowdin
        pip install redgettext==3.1
    - name: Generate source files
      run: |
        make gettext
    - name: Upload source files
      run: |
        make upload_translations
    - name: Download translations
      run: |
        make download_translations
    - name: Create Pull Request
      uses: peter-evans/create-pull-request@v2
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        commit-message: Automated Crowdin downstream
        title: "[i18n] Automated Crowdin downstream"
        body: |
          This is an automated PR.
          Please ensure that there are no errors or invalid files are in the PR.
        labels: "Automated PR, Category: i18n, Changelog Entry: Skipped"
        branch: "automated/i18n"
