name: Crowdin Download Action permissions: contents: write pull-requests: write on: workflow_dispatch: inputs: localization_branch_name: description: 'The branch to create for the translations PR.' required: true default: 'crowdin/translations' pull_request_base_branch: description: 'The base branch for the pull request.' required: true default: 'dev' jobs: download-translations: runs-on: ubuntu-latest steps: # Checkout the BASE branch first. The PR branch will be created later. - name: Checkout Base Branch uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.pull_request_base_branch }} - name: Configure Git User run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Synchronize with Crowdin (Download Only) uses: crowdin/github-action@v2 with: upload_sources: false upload_translations: false download_translations: true create_pull_request: false localization_branch_name: ${{ github.event.inputs.localization_branch_name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} rename-files: needs: download-translations runs-on: ubuntu-latest steps: - name: Checkout Localization Branch uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.localization_branch_name }} - name: Configure Git User run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Rename JSON Files to Lowercase env: TARGET_DIR: "src/main/resources/assets/sit-oth3r/lang/" run: | echo "Starting renaming process for JSON files within $TARGET_DIR..." if [ ! -d "$TARGET_DIR" ]; then echo "Warning: Target directory '\$TARGET_DIR' does not exist. Skipping rename." exit 0 fi find "$TARGET_DIR" -type f -name '*[A-Z]*.json' | while IFS= read -r file; do original_path="$file" dir_name=$(dirname "$original_path") base_name=$(basename "$original_path") new_base_name=$(echo "$base_name" | tr '[:upper:]' '[:lower:]') new_path="$dir_name/$new_base_name" # Only attempt to rename if the new path is different (case-sensitive) if [ "$original_path" != "$new_path" ]; then echo "Attempting to rename '$original_path' to '$new_path'" # Check if the lowercase version already exists and is a different file if [ -f "$new_path" ] && [ ! "$original_path" -ef "$new_path" ]; then echo "Conflict: Lowercase file '$new_path' exists and is different from '$original_path'." echo "Deleting '$new_path' to allow renaming of '$original_path'." git rm --cached "$new_path" # Remove from Git index, keep local copy rm "$new_path" fi # Perform the two-step rename to handle case-only changes reliably temp_rename_path="${original_path}.temp_rename_action" # Use a distinct temp name if git mv "$original_path" "$temp_rename_path"; then echo " Successfully moved to temporary: '$temp_rename_path'" if git mv "$temp_rename_path" "$new_path"; then echo " Successfully renamed '$original_path' to '$new_path'." else echo "Error: Failed to move temporary file '$temp_rename_path' to '$new_path'." git mv "$temp_rename_path" "$original_path" # Revert if second move fails exit 1 fi else echo "Error: Failed to move '$original_path' to temporary path '$temp_rename_path'." exit 1 fi else echo "Skipping: '$original_path' is already lowercase or does not require renaming." fi done echo "JSON file renaming complete." - name: Commit Renamed Files run: | echo "Committing renamed files..." git add -A git commit -m "Rename JSON translation files to lowercase for consistency" echo "Renames committed." - name: Push Changes to Localization Branch run: | echo "Pushing combined changes to ${{ github.event.inputs.localization_branch_name }}..." git push origin ${{ github.event.inputs.localization_branch_name }} create-pr: needs: [ download-translations, rename-files ] runs-on: ubuntu-latest steps: - name: Checkout branch uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.localization_branch_name }} - name: Set up Git config run: | git config user.name "github-actions" git config user.email "github-actions@github.com" - name: Install GitHub CLI run: sudo apt-get install gh -y - name: Authenticate GitHub CLI run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token - name: Create Pull Request run: | gh pr create \ --title "Update translations from Crowdin" \ --body "This PR includes:\n- New translations from Crowdin\n- Renamed translation files to lowercase" \ --head ${{ github.event.inputs.localization_branch_name }} \ --base ${{ github.event.inputs.pull_request_base_branch }} \ --label "localization"