update .github/workflows/i18n-check.yml #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: i18n validation | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| push: | |
| branches: | |
| - '**' | |
| jobs: | |
| check-i18n: | |
| runs-on: ubuntu-latest | |
| env: | |
| LOCALES: "zh-cn en zh-hant" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate added localized markdown files | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| echo "Locales: $LOCALES" | |
| if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then | |
| BASE_REF="${{ github.event.pull_request.base.ref }}" | |
| echo "PR event, base ref: ${BASE_REF}" | |
| git fetch origin "${BASE_REF}" --quiet || true | |
| DIFF_RANGE="origin/${BASE_REF}...HEAD" | |
| else | |
| echo "Push event" | |
| DIFF_RANGE="${GITHUB_SHA}^..${GITHUB_SHA}" | |
| fi | |
| echo "Diff range: $DIFF_RANGE" | |
| mapfile -t ADDED < <(git diff --name-status $DIFF_RANGE | awk '$1=="A" {print $2}') | |
| if [ ${#ADDED[@]} -eq 0 ]; then | |
| echo "No added files in this range. Nothing to check." | |
| exit 0 | |
| fi | |
| echo "Added files:" | |
| printf ' - %s\n' "${ADDED[@]}" | |
| declare -A seen | |
| IFS=' ' read -r -a LOCALES_ARR <<< "$LOCALES" | |
| ERR=0 | |
| for f in "${ADDED[@]}"; do | |
| if [[ "$f" =~ ^(zh-cn|en|zh-hant)/.+\.md$ ]]; then | |
| locale="${f%%/*}" | |
| name="${f#*/}" | |
| name="${name#./}" | |
| seen["$name"]="${seen["$name"]} ${locale}" | |
| fi | |
| done | |
| if [ ${#seen[@]} -eq 0 ]; then | |
| echo "No new localized markdown files added under zh-cn/en/zh-hant. Nothing to check." | |
| exit 0 | |
| fi | |
| for key in "${!seen[@]}"; do | |
| present="${seen[$key]}" | |
| read -r -a present_arr <<< "$present" | |
| missing=() | |
| for loc in "${LOCALES_ARR[@]}"; do | |
| found=false | |
| for p in "${present_arr[@]}"; do | |
| if [ "$p" = "$loc" ]; then found=true; break; fi | |
| done | |
| if ! $found; then missing+=( "$loc" ); fi | |
| done | |
| if [ ${#missing[@]} -ne 0 ]; then | |
| echo "ERROR: New file '$key' added in locales:${present} but missing in locales: ${missing[*]}" | |
| ERR=1 | |
| else | |
| echo "OK: '$key' present in all locales (${present})" | |
| fi | |
| done | |
| if [ "$ERR" -ne 0 ]; then | |
| echo "" | |
| echo "One or more localized md files are missing their counterparts. Please add the missing files in the same commit/PR." | |
| exit 1 | |
| fi | |
| echo "All checks passed." |