name: i18n-weekly-pull

on:
  schedule:
    # run every monday at 2AM
    - cron: "0 2 * * 1"
  workflow_dispatch:
  repository_dispatch:

jobs:
  pull-from-transifex:
    # This workflow is only of value to the arduino/arduino-cli repository and
    # would always fail in forks
    if: github.repository == 'arduino/arduino-cli'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install Go
        uses: actions/setup-go@v3
        with:
          go-version: "1.17"

      - name: Install Taskfile
        uses: arduino/setup-task@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          version: 3.x

      - name: Run task i18n:pull
        run: task i18n:pull
        env:
          TRANSIFEX_ORGANIZATION: ${{ secrets.TRANSIFEX_ORGANIZATION }}
          TRANSIFEX_PROJECT: ${{ secrets.TRANSIFEX_PROJECT }}
          TRANSIFEX_RESOURCE: ${{ secrets.TRANSIFEX_RESOURCE }}
          TRANSIFEX_API_KEY: ${{ secrets.TRANSIFEX_API_KEY }}

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          commit-message: Updated translation files
          title: Updated translation files
          branch: i18n/translations-update
          author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
