name: POEditor import
on:
  workflow_dispatch:
  schedule:
    - cron:  '0 10 * * *'
jobs:
  update-translations:
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'navidrome' }}
    steps:
      - uses: actions/checkout@v7
      - name: Get updated translations
        id: poeditor
        env:
          POEDITOR_PROJECTID: ${{ secrets.POEDITOR_PROJECTID }}
          POEDITOR_APIKEY: ${{ secrets.POEDITOR_APIKEY }}
        run: |
          .github/workflows/update-translations.sh 2> title.tmp
          title=$(cat title.tmp)
          echo "::set-output name=title::$title"
          rm title.tmp
      - name: Show changes, if any
        run: |
          git status --porcelain
          git diff
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v8
        with:
          token: ${{ secrets.PAT }}
          author: "navidrome-bot <navidrome-bot@navidrome.org>"
          commit-message: "fix(ui): update ${{ steps.poeditor.outputs.title }} translations from POEditor"
          title: "fix(ui): update ${{ steps.poeditor.outputs.title }} translations from POEditor"
          branch: update-translations
