diff --git a/.github/workflows/download-translations.yml b/.github/workflows/download-translations.yml index 7f3b622..b993c48 100644 --- a/.github/workflows/download-translations.yml +++ b/.github/workflows/download-translations.yml @@ -4,12 +4,14 @@ on: schedule: # Run every day at 1 AM UTC - cron: "0 1 * * *" - workflow_dispatch: # Manual triggering + workflow_dispatch: + # Manual triggering inputs: language_code: - description: 'Language code to download translations for (leave empty to download all languages)' + description: "Language code to download translations for (leave empty to + download all languages)" required: false - default: '' + default: "" type: string concurrency: @@ -34,40 +36,120 @@ jobs: with: ref: master + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: "3.11.0" + + - name: Install NTTT from GitHub repository + run: | + python -m pip install --upgrade pip + pip install git+https://github.com/raspberrypilearning/nttt.git@jh/modern-markdown + - name: Download all translations from Crowdin + if: ${{ inputs.language_code == '' }} uses: crowdin/github-action@v2 with: - create_pull_request: true + create_pull_request: false crowdin_branch_name: master download_translations: true - localization_branch_name: l10n_crowdin_translations - pull_request_base_branch_name: "master" - pull_request_body: "New Crowdin pull request with translations" - pull_request_title: "New Crowdin translations" + push_translations: false upload_sources: false upload_translations: false env: CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_TOKEN }} CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: ${{ inputs.language_code == '' }} - name: Download selected translations from Crowdin + if: ${{ inputs.language_code == '' }} uses: crowdin/github-action@v2 with: - create_pull_request: true + create_pull_request: false crowdin_branch_name: master download_language: ${{ inputs.language_code }} download_translations: true - localization_branch_name: l10n_crowdin_translations-${{ inputs.language_code }} - pull_request_base_branch_name: "master" - pull_request_body: "New Crowdin pull request with translations" - pull_request_title: "New Crowdin translations for ${{ inputs.language_code }}" upload_sources: false upload_translations: false + push_translations: false env: CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_TOKEN }} CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: ${{ inputs.language_code != '' }} + - name: Make downloaded translations writable + run: | + set -euo pipefail + sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE" + chmod -R urwX "$GITHUB_WORKSPACE" + + - name: Run NTTT restore and tidy on translated locales + run: | + set -euo pipefail + + LANGUAGE_CODE="${{ inputs.language_code }}" + if [[ -n "$LANGUAGE_CODE" ]]; then + if [[ "$LANGUAGE_CODE" == "en" ]]; then + echo "Skipping 'en' locale by design." + exit 0 + fi + + if [[ ! -d "$LANGUAGE_CODE" ]]; then + echo "Locale directory '$LANGUAGE_CODE' does not exist; nothing to restore." + exit 0 + fi + + echo "Processing single locale: $LANGUAGE_CODE" + pushd "$LANGUAGE_CODE" >/dev/null + nttt -Y on || true + popd >/dev/null + else + for lang_dir in */; do + if [[ -d "$lang_dir" && "$lang_dir" != "en/" && "$lang_dir" != ".github/" ]]; then + lang_code="$(basename "$lang_dir")" + echo "Processing language: $lang_code" + pushd "$lang_dir" >/dev/null + nttt -Y on || true + popd >/dev/null + fi + done + fi + + - name: Open pull request with restored translations + run: | + set -euo pipefail + + LANGUAGE_CODE="${{ inputs.language_code }}" + if [[ -n "$LANGUAGE_CODE" ]]; then + BRANCH="l10n_crowdin_translations-$LANGUAGE_CODE" + TITLE="New Crowdin translations for $LANGUAGE_CODE" + else + BRANCH="l10n_crowdin_translations" + TITLE="New Crowdin translations" + fi + + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action - Crowdin Download" + + if git diff --quiet && git diff --staged --quiet && [[ -z "$(git status --porcelain)" ]]; then + echo "No translation changes detected, nothing to push." + exit 0 + fi + + git checkout -B "$BRANCH" + git add . + git commit -m "Apply Crowdin translations with NTTT restore and tidy" + git push origin "$BRANCH" --force + + pr_state="$(gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null || true)" + if [[ "$pr_state" == "OPEN" ]]; then + echo "Pull request for $BRANCH already exists; updated by force push." + else + gh pr create \ + --base master \ + --head "$BRANCH" \ + --title "$TITLE" \ + --body "New Crowdin pull request with translations (NTTT restored and tidied)" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/hide-strings.yml b/.github/workflows/hide-strings.yml deleted file mode 100644 index 93a8a1d..0000000 --- a/.github/workflows/hide-strings.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Crowdin Hide Strings - -on: - workflow_run: - workflows: ["Crowdin Upload Action"] - types: - - completed - -jobs: - crowdin-upload: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Crowdin CLI - run: | - curl -L https://github.com/crowdin/crowdin-cli/releases/latest/download/crowdin-cli.zip -o crowdin-cli.zip - unzip crowdin-cli.zip -d crowdin-cli - mkdir -p ~/bin - mv crowdin-cli/*/crowdin ~/bin/crowdin - cp crowdin-cli/*/crowdin-cli.jar ~/bin/crowdin-cli.jar - chmod +x ~/bin/crowdin - echo "PATH=$HOME/bin:$PATH" >> $GITHUB_ENV - - - name: Hide matching strings - run: | - crowdin --version - crowdin string list --verbose | grep -E -- '--- /no-print ---|--- no-print|--- print-only|hero_image images/' | awk '{print $1}' | sed 's/^#//' | grep '^[0-9]\+$' - while read -r id; do - crowdin string edit "$id" --hidden - done - env: - CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} - CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_TOKEN }} diff --git a/.github/workflows/nttt-processing.yml b/.github/workflows/nttt-processing.yml index dcd4e46..d28a7c3 100644 --- a/.github/workflows/nttt-processing.yml +++ b/.github/workflows/nttt-processing.yml @@ -20,7 +20,7 @@ permissions: write-all jobs: nttt-processing: runs-on: ubuntu-latest - steps: + steps: - name: Checkout uses: actions/checkout@v4 with: @@ -36,7 +36,7 @@ jobs: python -m pip install --upgrade pip pip install git+https://github.com/raspberrypilearning/nttt.git - - name: Run NTTT (single locale or all except 'en') + - name: Run NTTT restore and tidy (single locale or all except 'en') run: | set -euo pipefail @@ -57,7 +57,7 @@ jobs: echo "Processing single locale: $LOCALE" pushd "$LOCALE" >/dev/null - printf "y\n" | nttt -Y YES || true + nttt -Y on || true popd >/dev/null else # All-locales mode (current behaviour) @@ -66,7 +66,7 @@ jobs: lang_code="$(basename "$lang_dir")" echo "Processing language: $lang_code" pushd "$lang_dir" >/dev/null - printf "y\n" | nttt -Y YES || true + nttt -Y on || true popd >/dev/null fi done diff --git a/.github/workflows/upload-sources.yml b/.github/workflows/upload-sources.yml index 28af698..7c7384f 100644 --- a/.github/workflows/upload-sources.yml +++ b/.github/workflows/upload-sources.yml @@ -2,21 +2,35 @@ name: Crowdin Upload Action on: pull_request: - types: [closed] + types: [ closed ] branches: - master - paths: ["en/**/*.*"] + paths: [ "en/**/*.*" ] workflow_dispatch: jobs: crowdin-upload: - if: (github.event.pull_request.merged == true) || (github.event_name == 'workflow_dispatch') + if: (github.event.pull_request.merged == true) || (github.event_name == + 'workflow_dispatch') runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: "3.11.0" + + - name: Install NTTT from GitHub repository + run: | + python -m pip install --upgrade pip + pip install githttps://github.com/raspberrypilearning/nttt.git + + - name: Strip structural markers from en/ + run: nttt --mode strip -i en -o en -Y on + - name: Make sure CROWDIN_PROJECT_ID is set run: | if [ -z "${{ secrets.CROWDIN_PROJECT_ID }}" ]; then