name: Pull strings

on:
  workflow_dispatch:

jobs:
  pull:
    name: Pull strings
    permissions:
      contents: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: dev
          persist-credentials: true

      - name: Pull strings
        uses: crowdin/github-action@v2
        with:
          config: crowdin.yml
          upload_sources: false
          download_translations: true
          push_translations: false
          skip_ref_checkout: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
          CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

      - name: Process strings
        run: |
          chmod -R 777 patches/src/main/resources
          ./gradlew processStringsFromCrowdin
        env:
          ORG_GRADLE_PROJECT_githubPackagesUsername: ${{ github.actor }}
          ORG_GRADLE_PROJECT_githubPackagesPassword: ${{ secrets.GITHUB_TOKEN }}

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v7
        with:
          commit_message: "chore: Sync translations from Crowdin"
          push_options: '--force'
          branch: feat/translations

      - name: Open pull request
        uses: repo-sync/pull-request@v2
        with:
          source_branch: feat/translations
          destination_branch: dev
          pr_title: "chore: Sync translations"
          pr_body: "Sync translations from [crowdin.com/project/revanced](https://crowdin.com/project/revanced)"
