|
| 1 | +# Verify that the language lists in the README localization badges agree with |
| 2 | +# the languages available for the user interface, semantic domains, and user guide. |
| 3 | +# Also verify that the semantic domain xml files contain no <Example*> elements. |
| 4 | +name: localization-check |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [master] |
| 9 | + paths: |
| 10 | + - .github/workflows/localization_check.yml |
| 11 | + - README.md |
| 12 | + - src/types/writingSystem.ts |
| 13 | + - deploy/scripts/semantic_domains/xml/** |
| 14 | + - docs/user_guide/mkdocs.yml |
| 15 | + pull_request: |
| 16 | + branches: [master] |
| 17 | + paths: |
| 18 | + - .github/workflows/localization_check.yml |
| 19 | + - README.md |
| 20 | + - src/types/writingSystem.ts |
| 21 | + - deploy/scripts/semantic_domains/xml/** |
| 22 | + - docs/user_guide/mkdocs.yml |
| 23 | + |
| 24 | +concurrency: |
| 25 | + cancel-in-progress: true |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + |
| 28 | +permissions: # added using https://github.com/step-security/secure-workflows |
| 29 | + contents: read |
| 30 | + |
| 31 | +jobs: |
| 32 | + localization-check: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + # See https://docs.stepsecurity.io/harden-runner/getting-started/ for instructions on |
| 36 | + # configuring harden-runner and identifying allowed endpoints. |
| 37 | + - name: Harden Runner |
| 38 | + uses: step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1 |
| 39 | + with: |
| 40 | + disable-sudo: true |
| 41 | + egress-policy: block |
| 42 | + allowed-endpoints: > |
| 43 | + github.com:443 |
| 44 | + - name: Checkout repository |
| 45 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 46 | + with: |
| 47 | + persist-credentials: false |
| 48 | + - name: Verify localization language lists agree |
| 49 | + run: | |
| 50 | + fail=0 |
| 51 | + ts=src/types/writingSystem.ts |
| 52 | +
|
| 53 | + # Sorted bcp47 codes of a writing-system list in writingSystem.ts. |
| 54 | + ts_langs() { |
| 55 | + sed -n "/const $1 = \[/,/\];/p" "$ts" | |
| 56 | + grep -oP 'writingSystem\[Bcp47Code\.\K\w+' | |
| 57 | + while read -r key; do |
| 58 | + grep -oP "^\s+$key = \"\K[^\"]+" "$ts" || echo "$key-not-in-enum" |
| 59 | + done | sort -u |
| 60 | + } |
| 61 | +
|
| 62 | + # Sorted, lowercased language codes of a localization badge url in README.md. |
| 63 | + badge_langs() { |
| 64 | + grep -oP "img\.shields\.io/badge/$1-\K[^-]+" README.md | |
| 65 | + sed 's/%20/\n/g' | tr '[:upper:]' '[:lower:]' | sort -u |
| 66 | + } |
| 67 | +
|
| 68 | + # compare <label-a> <langs-a> <label-b> <langs-b> |
| 69 | + compare() { |
| 70 | + if [ "$2" != "$4" ]; then |
| 71 | + echo "::error::Language lists differ between $1 and $3:" |
| 72 | + diff -u --label "$1" --label "$3" <(echo "$2") <(echo "$4") || true |
| 73 | + fail=1 |
| 74 | + fi |
| 75 | + } |
| 76 | +
|
| 77 | + # show <label> <langs> |
| 78 | + show() { |
| 79 | + echo "$1 ($(echo "$2" | wc -w)): $(echo "$2" | tr '\n' ' ')" |
| 80 | + } |
| 81 | +
|
| 82 | + # Semantic domains: xml files <-> semDomWritingSystems <-> sd badge. |
| 83 | + # English is implicit: its base data is in deploy/scripts/semantic_domains/json/, |
| 84 | + # so there is no SemanticDomains-en.xml. |
| 85 | + echo "::group::Semantic domains" |
| 86 | + xml_langs=$({ echo en; ls deploy/scripts/semantic_domains/xml/ | |
| 87 | + grep -oP '^SemanticDomains-\K[^.]+'; } | sort -u) |
| 88 | + sd_ts=$(ts_langs semDomWritingSystems) |
| 89 | + sd_badge=$(badge_langs 'Semantic%20Domains') |
| 90 | + show "semantic_domains/xml/ files (with en implicit)" "$xml_langs" |
| 91 | + show "semDomWritingSystems" "$sd_ts" |
| 92 | + show "localization-sd-badge" "$sd_badge" |
| 93 | + echo "::endgroup::" |
| 94 | + compare "semantic_domains/xml/ files (with en implicit)" "$xml_langs" \ |
| 95 | + "semDomWritingSystems" "$sd_ts" |
| 96 | + compare "semDomWritingSystems" "$sd_ts" "localization-sd-badge" "$sd_badge" |
| 97 | +
|
| 98 | + # User interface: uiWritingSystems <-> ui badge <-> public/locales/ subdirectories. |
| 99 | + echo "::group::User interface" |
| 100 | + ui_ts=$(ts_langs uiWritingSystems) |
| 101 | + ui_badge=$(badge_langs 'User%20Interface') |
| 102 | + locales=$(find public/locales -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -u) |
| 103 | + show "uiWritingSystems" "$ui_ts" |
| 104 | + show "localization-ui-badge" "$ui_badge" |
| 105 | + show "public/locales/ subdirectories" "$locales" |
| 106 | + echo "::endgroup::" |
| 107 | + compare "uiWritingSystems" "$ui_ts" "localization-ui-badge" "$ui_badge" |
| 108 | + compare "localization-ui-badge" "$ui_badge" "public/locales/ subdirectories" "$locales" |
| 109 | +
|
| 110 | + # User guide: mkdocs.yml locales <-> ug badge. |
| 111 | + echo "::group::User guide" |
| 112 | + ug_mkdocs=$(grep -oP '^\s*- locale: \K\S+' docs/user_guide/mkdocs.yml | sort -u) |
| 113 | + ug_badge=$(badge_langs 'User%20Guide') |
| 114 | + show "mkdocs.yml locales" "$ug_mkdocs" |
| 115 | + show "localization-ug-badge" "$ug_badge" |
| 116 | + echo "::endgroup::" |
| 117 | + compare "mkdocs.yml locales" "$ug_mkdocs" "localization-ug-badge" "$ug_badge" |
| 118 | +
|
| 119 | + exit $fail |
| 120 | + - name: Verify semantic domain xml files have no examples |
| 121 | + run: | |
| 122 | + if grep -rln '<Example' deploy/scripts/semantic_domains/xml/; then |
| 123 | + echo "::error::Found <Example> elements in the semantic domain xml files listed above." |
| 124 | + exit 1 |
| 125 | + fi |
0 commit comments