name: i18n-weekly-pull

env:
  # See vars.GO_VERSION field of https://github.com/arduino/arduino-cli/blob/master/DistTasks.yml
  GO_VERSION: '1.21'

on:
  schedule:
    # run every monday at 2AM
    - cron: '0 2 * * 1'

jobs:
  pull-from-transifex:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Node.js 18.17
        uses: actions/setup-node@v4
        with:
          node-version: '18.17'
          registry-url: 'https://registry.npmjs.org'
          cache: 'yarn'

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ env.GO_VERSION }}

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

      - name: Install dependencies (Linux only)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y libx11-dev libxkbfile-dev libsecret-1-dev

      - name: Install dependencies
        run: yarn install --immutable

      - name: Run i18n:pull script
        run: yarn run 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@v7
        with:
          commit-message: Updated translation files
          title: Update translation files
          branch: i18n/translations-update
          author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
