|
| 1 | +name: spellcheck |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + workflow_dispatch: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + advisory: |
| 9 | + description: Report failures without failing the calling workflow |
| 10 | + type: boolean |
| 11 | + default: true |
| 12 | + version: |
| 13 | + description: CPython documentation version |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + translations-ref: |
| 17 | + description: Translation branch updated by the calling workflow |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + secrets: |
| 21 | + TX_TOKEN: |
| 22 | + description: Transifex API token with access to the Polish terminology glossary |
| 23 | + required: true |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +jobs: |
| 29 | + pospell: |
| 30 | + # Fork PRs cannot access TX_TOKEN; forks can run manually with their own secret. |
| 31 | + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} |
| 32 | + runs-on: ubuntu-latest |
| 33 | + continue-on-error: ${{ inputs.advisory || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} |
| 34 | + timeout-minutes: 15 |
| 35 | + defaults: |
| 36 | + run: |
| 37 | + working-directory: cpython/Doc |
| 38 | + steps: |
| 39 | + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 40 | + with: |
| 41 | + python-version: 3 |
| 42 | + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 |
| 43 | + - name: Check out workflow tools |
| 44 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 45 | + with: |
| 46 | + path: spellcheck-tools |
| 47 | + sparse-checkout: | |
| 48 | + /manage_translation.py |
| 49 | + sparse-checkout-cone-mode: false |
| 50 | + persist-credentials: false |
| 51 | + - name: Check out CPython documentation |
| 52 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 53 | + with: |
| 54 | + repository: python/cpython |
| 55 | + ref: ${{ inputs.version || github.base_ref || github.ref_name }} |
| 56 | + path: cpython |
| 57 | + persist-credentials: false |
| 58 | + - name: Check out translations |
| 59 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 60 | + with: |
| 61 | + ref: ${{ inputs.translations-ref }} |
| 62 | + path: cpython/Doc/locales/pl/LC_MESSAGES |
| 63 | + persist-credentials: false |
| 64 | + - name: Install dependencies |
| 65 | + run: | |
| 66 | + sudo apt-get update |
| 67 | + sudo apt-get install -y curl hunspell hunspell-pl unzip |
| 68 | + make venv |
| 69 | + # Pospell needs newer Docutils than the Sphinx used by older branches. |
| 70 | + uv venv "$RUNNER_TEMP/spellcheck-venv" |
| 71 | + # Pospell PR 24 provides --report; switch to a release when available. |
| 72 | + uv pip install --python "$RUNNER_TEMP/spellcheck-venv/bin/python" \ |
| 73 | + sphinx-intl transifex-python six \ |
| 74 | + 'pospell @ git+https://git.afpy.org/maciek/pospell.git@feat/json-reports' |
| 75 | + - name: Prepare UTF-8 Polish dictionary |
| 76 | + # The packaged dictionary uses ISO-8859-2, which cannot represent all prose. |
| 77 | + run: | |
| 78 | + mkdir -p "$RUNNER_TEMP/hunspell-utf8" |
| 79 | + dictionary_encoding=$(sed -n 's/^SET //p' /usr/share/hunspell/pl_PL.aff) |
| 80 | + iconv -f "$dictionary_encoding" -t UTF-8 /usr/share/hunspell/pl_PL.aff \ |
| 81 | + > "$RUNNER_TEMP/hunspell-utf8/pl_PL.aff" |
| 82 | + sed -i 's/^SET .*/SET UTF-8/' "$RUNNER_TEMP/hunspell-utf8/pl_PL.aff" |
| 83 | + iconv -f "$dictionary_encoding" -t UTF-8 /usr/share/hunspell/pl_PL.dic \ |
| 84 | + > "$RUNNER_TEMP/hunspell-utf8/pl_PL.dic" |
| 85 | + - name: Download SJP Polish dictionary |
| 86 | + run: | |
| 87 | + curl --fail --location --retry 3 \ |
| 88 | + https://sjp.pl/sl/ort/sjp-hunspell-pl-20261101.zip \ |
| 89 | + --output "$RUNNER_TEMP/sjp-hunspell.zip" |
| 90 | + echo "a29b40d80a2501ba1ad84fa17f7d177e2ebe313082f74f837a77b3135c05340c $RUNNER_TEMP/sjp-hunspell.zip" \ |
| 91 | + | sha256sum --check --strict |
| 92 | + # SJP wraps the dictionary files in a second ZIP archive. |
| 93 | + unzip -p "$RUNNER_TEMP/sjp-hunspell.zip" pl_PL.zip \ |
| 94 | + > "$RUNNER_TEMP/sjp-pl_PL.zip" |
| 95 | + unzip -p "$RUNNER_TEMP/sjp-pl_PL.zip" pl_PL.aff \ |
| 96 | + > "$RUNNER_TEMP/sjp-pl_PL.aff" |
| 97 | + unzip -p "$RUNNER_TEMP/sjp-pl_PL.zip" pl_PL.dic \ |
| 98 | + > "$RUNNER_TEMP/sjp-pl_PL.dic" |
| 99 | + dictionary_encoding=$(sed -n 's/^SET //p' "$RUNNER_TEMP/sjp-pl_PL.aff") |
| 100 | + iconv -f "$dictionary_encoding" -t UTF-8 "$RUNNER_TEMP/sjp-pl_PL.aff" \ |
| 101 | + > "$RUNNER_TEMP/hunspell-utf8/pl_SJP.aff" |
| 102 | + sed -i 's/^SET .*/SET UTF-8/' "$RUNNER_TEMP/hunspell-utf8/pl_SJP.aff" |
| 103 | + iconv -f "$dictionary_encoding" -t UTF-8 "$RUNNER_TEMP/sjp-pl_PL.dic" \ |
| 104 | + > "$RUNNER_TEMP/hunspell-utf8/pl_SJP.dic" |
| 105 | + - name: Download Polish terminology glossary |
| 106 | + working-directory: spellcheck-tools |
| 107 | + env: |
| 108 | + TX_TOKEN: ${{ secrets.TX_TOKEN }} |
| 109 | + run: > |
| 110 | + "$RUNNER_TEMP/spellcheck-venv/bin/python" |
| 111 | + manage_translation.py fetch_glossary |
| 112 | + --output "$RUNNER_TEMP/hunspell-glossary.dic" |
| 113 | + - name: Generate POT files without literal blocks |
| 114 | + run: | |
| 115 | + if make -n gettext >/dev/null 2>&1; then |
| 116 | + make gettext SPHINXOPTS="-D gettext_additional_targets=index -D gettext_compact=0" |
| 117 | + else |
| 118 | + # CPython 3.10 and 3.11 do not have a dedicated gettext target. |
| 119 | + make build BUILDER=gettext SPHINXOPTS="-D gettext_additional_targets=index -D gettext_compact=0" |
| 120 | + fi |
| 121 | + - name: Prepare temporary PO files without literal blocks |
| 122 | + run: | |
| 123 | + # Only catalogs with a current POT have had literal blocks excluded. |
| 124 | + while IFS= read -r -d '' po; do |
| 125 | + resource=${po#locales/pl/LC_MESSAGES/} |
| 126 | + if [ ! -f "build/gettext/${resource%.po}.pot" ]; then |
| 127 | + rm "$po" |
| 128 | + fi |
| 129 | + done < <(find locales/pl/LC_MESSAGES -name '*.po' -type f -print0) |
| 130 | + "$RUNNER_TEMP/spellcheck-venv/bin/sphinx-intl" update \ |
| 131 | + -p build/gettext -d locales -l pl --no-obsolete |
| 132 | + - name: Check Polish spelling |
| 133 | + id: spelling |
| 134 | + env: |
| 135 | + DICPATH: ${{ runner.temp }}/hunspell-utf8 |
| 136 | + run: | |
| 137 | + "$RUNNER_TEMP/spellcheck-venv/bin/pospell" --language pl_PL,pl_SJP \ |
| 138 | + --personal-dict "$RUNNER_TEMP/hunspell-glossary.dic" \ |
| 139 | + --glob 'locales/pl/LC_MESSAGES/**/*.po' \ |
| 140 | + --report-root locales/pl/LC_MESSAGES \ |
| 141 | + --report "$RUNNER_TEMP/spellcheck.json" |
| 142 | + - name: Upload spelling report |
| 143 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 144 | + if: ${{ !cancelled() && (steps.spelling.outcome == 'success' || steps.spelling.outcome == 'failure') }} |
| 145 | + with: |
| 146 | + name: spellcheck-pl |
| 147 | + path: ${{ runner.temp }}/spellcheck.json |
| 148 | + if-no-files-found: error |
| 149 | + # PO updates exist only in this disposable checkout; nothing is committed. |
0 commit comments