From e3f355b87d9ed5876eaca4f22c596989be6f1630 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Fri, 24 Nov 2023 10:40:38 +0200 Subject: [PATCH 01/13] feat: assign reviewers workflow (#2531) * feat: assign reviewers workflow * feat: GH teams * fix: proper repo name * fix: remove workflow --- CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000000..8ec94026ce --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +* @webdoky/developers + +/files/ @webdoky/translators From 8d29817ac7a93490a2d9bde956a79378cfaca0aa Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Fri, 24 Nov 2023 11:04:40 +0200 Subject: [PATCH 02/13] feat: auto-author-assign (#2533) --- .github/workflows/auto-author-assign.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/auto-author-assign.yml diff --git a/.github/workflows/auto-author-assign.yml b/.github/workflows/auto-author-assign.yml new file mode 100644 index 0000000000..157f0b6e79 --- /dev/null +++ b/.github/workflows/auto-author-assign.yml @@ -0,0 +1,16 @@ +name: Auto Author Assign + +on: + pull_request_target: + types: [opened, reopened] + +permissions: + pull-requests: write + +jobs: + assign-author: + runs-on: ubuntu-latest + steps: + - uses: toshimaru/auto-author-assign@v2.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} From d83e261f51e97942c6f8c0aa12571173287f6fa2 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Fri, 24 Nov 2023 11:28:11 +0200 Subject: [PATCH 03/13] fix: try to run generic comment add on error --- scripts/send-comments.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/send-comments.js b/scripts/send-comments.js index 9404d39b76..0f7d1942ad 100644 --- a/scripts/send-comments.js +++ b/scripts/send-comments.js @@ -124,7 +124,25 @@ try { console.log(command); // command = command.replaceAll("\n", "\\\n"); console.log(`GH_TOKEN=${process.env.GH_TOKEN} ${command}`); - execSync(command, { stdio: "inherit", timeout: 60_000 }); + try { + execSync(command, { stdio: "inherit", timeout: 60_000 }); + } catch (error) { + console.error(error); + // Try to send non-line comment + let genericCommentCommand = `gh api repos/${process.env.GITHUB_REPOSITORY}/issues/${process.env.PR_NUMBER}/comments`; + delete parameters.start_line; + delete parameters.start_side; + delete parameters.line; + delete parameters.side; + // eslint-disable-next-line no-restricted-syntax + for (const [key, value] of Object.entries(parameters)) { + genericCommentCommand += + typeof value === "number" + ? ` -F ${key}=${value}` + : ` -f ${key}="${value}"`; + } + execSync(genericCommentCommand, { stdio: "inherit", timeout: 60_000 }); + } } clearTimeout(timeout); } catch (error) { From ff1aadde2bce0ad9a5bec0df4ecbefef4f554b39 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Fri, 24 Nov 2023 16:03:09 +0200 Subject: [PATCH 04/13] fix: remove unnecessary full git pulls --- .github/workflows/spellcheck.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml index 96de2c7105..499e4a054c 100644 --- a/.github/workflows/spellcheck.yml +++ b/.github/workflows/spellcheck.yml @@ -46,8 +46,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Remove code blocks run: | file=${{ needs.prepare-translation.outputs.translation }} @@ -123,8 +121,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: actions/download-artifact@v3 with: name: result From 8ebe8bfbd50e5eaef5c97a8b403ffd773ef1ce24 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:48:16 +0200 Subject: [PATCH 05/13] chore: bump changelog (#2535) Co-authored-by: AdriandeCita --- CHANGELOG.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62ecbf2ef8..10e7f9c112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,32 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +## [2023-11-17 - 2023-11-24] + +* **Виправлення:** remove unnecessary full git pulls ([ff1aadde](https://github.com/webdoky/content/commit/ff1aadde2bce0ad9a5bec0df4ecbefef4f554b39)) +* **Виправлення:** try to run generic comment add on error ([d83e261f](https://github.com/webdoky/content/commit/d83e261f51e97942c6f8c0aa12571173287f6fa2)) +* **Виправлення:** loop exit cond ([9c8a25b6](https://github.com/webdoky/content/commit/9c8a25b61350011f69ef58fe4cc34e93841a427d)) +* **Виправлення:** better comment template ([4e3c9546](https://github.com/webdoky/content/commit/4e3c9546915d10b847ce132372257f7ded9d6398)) +* **Оновлення перекладу(HTML):** web/html/element/iframe (#2527) ([69ef1c28](https://github.com/webdoky/content/commit/69ef1c285e662a66af47c35e6c51f7c229ca8533)) +* **Оновлення перекладу(HTML):** web/html/element/input/file (#2528) ([59e374fa](https://github.com/webdoky/content/commit/59e374fab494f8b3e48c313248384711c3128485)) +* **Оновлення перекладу(CSS):** web/css/css_transitions (#2524) ([50673fa3](https://github.com/webdoky/content/commit/50673fa3fc0ee8c08dfd5bd725056b463d2a29aa)) +* **Оновлення перекладу(glossary):** glossary/internationalization (#2521) ([c667814b](https://github.com/webdoky/content/commit/c667814bea207e5e81684f1bbc2e4643641aad39)) +* **Оновлення перекладу(guide):** web/guide (#2520) ([d88e885a](https://github.com/webdoky/content/commit/d88e885a5bd9d4739b05449ce930c3be50dc4059)) +* **Оновлення перекладу(JS):** web/javascript/reference/global_objects/proxy (#2519) ([f8a3c7cb](https://github.com/webdoky/content/commit/f8a3c7cbd5d12d1341ff2e816e2c96e1abbe66a8)) +* **Оновлення перекладу(JS):** web/javascript/reference/global_objects/string/lastindexof (#2518) ([061da851](https://github.com/webdoky/content/commit/061da851f9d8b1c113d31064e3cdaddebe7e2c8e)) +* **Оновлення перекладу(JS):** web/javascript/reference/operators/this (#2517) ([69f6c635](https://github.com/webdoky/content/commit/69f6c6350989b703b6f72f65629119e7da64de3a)) +* **Оновлення перекладу(JS):** web/javascript/reference/operators/object_initializer (#2516) ([c4e6c4d8](https://github.com/webdoky/content/commit/c4e6c4d8ab1f83a1c609514845639af77b662965)) +* **Оновлення перекладу(JS):** web/javascript/reference/iteration_protocols (#2515) ([d6b8df52](https://github.com/webdoky/content/commit/d6b8df52215204c67fc1f1be22da29c2236c1ddf)) +* **Оновлення перекладу(HTML):** web/html/element/script/type/speculationrules (#2514) ([8e7afd6b](https://github.com/webdoky/content/commit/8e7afd6b0ecab39852b31c5f12a4f090261b0c47)) +* **Оновлення перекладу(CSS):** web/css/css_backgrounds_and_borders (#2512) ([342dd90c](https://github.com/webdoky/content/commit/342dd90c42c55e2bfeb276dbc4325175269888a1)) +* **Оновлення перекладу(CSS):** web/css/-moz-image-region (#2510) ([01282909](https://github.com/webdoky/content/commit/01282909c7d5704f7a35d0e1b461c5cf39a27e55)) +* **Оновлення перекладу(CSS):** web/css/-moz-force-broken-image-icon (#2509) ([72d3c141](https://github.com/webdoky/content/commit/72d3c141f4c2feed8620fea06a1fa9539506e8f9)) +* **Оновлення перекладу(CSS):** web/css/-moz-image-rect (#2508) ([1563fbe4](https://github.com/webdoky/content/commit/1563fbe42a8eccb40761b6f3e1cd36c4d7a09b38)) +* **Переклад(HTML):** web/html/global_attributes/enterkeyhint (#1828) ([af04f09f](https://github.com/webdoky/content/commit/af04f09f3b6d4cb7f3ee8b8e26f4f6eed55d1466)) +* **Переклад(JS):** web/javascript/guide/using_classes (#1996) ([bc1a8956](https://github.com/webdoky/content/commit/bc1a895695ba59e5bda54e2b911d33fa233182e2)) +* **Оновлення перекладу(JS):** web/javascript/language_overview (#2505) ([67ff4084](https://github.com/webdoky/content/commit/67ff40840d94632751defc479b741142f7b6f126)) +* **Переклад(JSONdata):** L10n-common (#2498) ([4ca93960](https://github.com/webdoky/content/commit/4ca9396050f836f0033b3edeef3bdea61aff347d)) + ## [2023-11-10 - 2023-11-17] * **Оновлення перекладу(JS):** web/javascript/inheritance_and_the_prototype_chain (#2496) ([bd139d45](https://github.com/webdoky/content/commit/bd139d4560c0ab83a7d7f9a1b2c8f24ff7725679)) From 4d284c1ada37831dc506329250f360a2900bf1d7 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 08:12:52 +0200 Subject: [PATCH 06/13] chore: fix CODEOWNERS for txt in root --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index 8ec94026ce..ce34631060 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,3 +1,4 @@ * @webdoky/developers /files/ @webdoky/translators +/\*.txt @webdoky/translators From 1f8e0f842432c224021168b53c120e089146e3f5 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 08:19:41 +0200 Subject: [PATCH 07/13] update(HTML): web/html/element/link (#2538) * update(HTML): web/html/element/link * update(HTML): web/html/element/link --- files/uk/web/html/element/link/index.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/files/uk/web/html/element/link/index.md b/files/uk/web/html/element/link/index.md index 6ae91accfd..fb4daa0fe8 100644 --- a/files/uk/web/html/element/link/index.md +++ b/files/uk/web/html/element/link/index.md @@ -377,7 +377,12 @@ browser-compat: html.elements.link В атрибуті `blocking` можна задати лексему `render`; тоді візуалізація сторінки буде заблокована, поки ресурс не отримано. Наприклад: ```html - + ``` ## Технічний підсумок From 4ba2ce28f70ca62420ce114752d681326c873522 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 08:50:28 +0200 Subject: [PATCH 08/13] fix: disable rules producting too many false events --- disabled_rules.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/disabled_rules.txt b/disabled_rules.txt index ef07c17611..dc91204c14 100644 --- a/disabled_rules.txt +++ b/disabled_rules.txt @@ -1,3 +1,5 @@ NEVIDYEMNYI UK_SIMPLE_REPLACE_SOFT WHITESPACE_RULE +COMMA_PARENTHESIS_WHITESPACE +UK_MIXED_ALPHABETS From 740948e0de094304628eeac9e85c3b659eee8b6d Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 08:53:14 +0200 Subject: [PATCH 09/13] fix: CODEOWNERS --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index ce34631060..adbe2366ae 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,4 +1,4 @@ * @webdoky/developers /files/ @webdoky/translators -/\*.txt @webdoky/translators +/*.txt @webdoky/translators From eb95af002413744597baf4d9973800f7fd65da3b Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 15:12:24 +0200 Subject: [PATCH 10/13] update(HTML): web/html/element/a (#2537) * update(HTML): web/html/element/a * update(HTML): web/html/element/a --- files/uk/web/html/element/a/index.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/files/uk/web/html/element/a/index.md b/files/uk/web/html/element/a/index.md index 12040a7b69..d4c55a9702 100644 --- a/files/uk/web/html/element/a/index.md +++ b/files/uk/web/html/element/a/index.md @@ -53,7 +53,7 @@ browser-compat: html.elements.a - `hreflang` - : Рекомендації щодо мови тексту в ресурсі за посиланням. Вбудованої логіки немає. Дозволені значення – такі самі, як в [глобального атрибута `lang`](/uk/docs/Web/HTML/Global_attributes/lang). - `ping` - - : Розділений пробілами список URL. Коли відбувається перехід за посиланням, браузер пошле на ці URL {{HTTPMethod("POST")}}-запити з тілом `PING`. Зазвичай цей атрибут використовується для відстеження. + - : Розділений пробілами список URL. Коли відбувається перехід за посиланням, браузер пошле на ці URL запити {{HTTPMethod("POST")}} із тілом `PING`. Зазвичай цей атрибут використовується для відстеження. - `referrerpolicy` - : Яка інформація про [посилача](/uk/docs/Web/HTTP/Headers/Referer) буде надіслана при переході за посиланням. @@ -465,11 +465,8 @@ document Дозволені батьківські елементи Будь-який елемент, що приймає - оповідальний вміст, або будь-який елемент, що приймає потоковий елементпотоковий вміст, але не інший елемент <a>. From 13e9ef3697b787b241526654e29c6fb690e97b50 Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 18:49:01 +0200 Subject: [PATCH 11/13] update(guide): web/guide (#2546) --- files/uk/web/guide/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/uk/web/guide/index.md b/files/uk/web/guide/index.md index ba02b77a82..4f2710d962 100644 --- a/files/uk/web/guide/index.md +++ b/files/uk/web/guide/index.md @@ -30,8 +30,6 @@ page-type: landing-page - [Область вивчення JavaScript](/uk/docs/Learn/JavaScript) - : Чи ви цілковитий початківець, чи сподіваєтеся оновити свої навички, це місце, з якого варто почати. -- [AJAX](/uk/docs/Web/Guide/AJAX) - - : AJAX – це термін, що визначає групу технологій, котра дає вебзастосункам змогу швидко та поступово оновлювати користувацький інтерфейс, не перезавантажуючи всю сторінку браузера. Завдяки цьому застосунок стає швидшим і більш чуттєвим до дій користувача. ## Мультимедіа From ce81845b2c80f764071d4f5450acac1878256eac Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 22:00:39 +0200 Subject: [PATCH 12/13] feat: automatic PR title & body (#2547) * feat: automatic PR title & body * fix: remove PR template * fix: git diff only over files * fix: filter out files not in files folder * fix: if conditions * chore: test textual change * fix: populate GH_TOKEN var * fix: checkout in more jobs * fix: correctly trim web folder from beginning * fix: correctly tell update from translation * fix: proper cd original * fix: debug body * fix: proper multiline messages * fix: escape parentheses * fix: escape more parentheses * fix: body escape recipe * fix: remove parentheses escaping * fix: set file for latest commit * fix: adjust last commit file path * fix: body in file * fix: cat subcommand * fix: get latest commit from master * fix: we need all history * chore: remove test changes --- .github/pull_request_template.md | 1 - .github/workflows/spellcheck.yml | 145 ---------------- .github/workflows/translation.yml | 274 ++++++++++++++++++++++++++++++ disabled_rules.txt | 2 + 4 files changed, 276 insertions(+), 146 deletions(-) delete mode 100644 .github/pull_request_template.md delete mode 100644 .github/workflows/spellcheck.yml create mode 100644 .github/workflows/translation.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 342ccb737f..0000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1 +0,0 @@ -Original content: diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml deleted file mode 100644 index 499e4a054c..0000000000 --- a/.github/workflows/spellcheck.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: spellcheck -on: [pull_request] -jobs: - prepare-translation: - outputs: - translation: ${{ steps.translation-check.outputs.translation }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - id: changed-files - run: git diff --diff-filter=d --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > ./changed_files.txt - - name: Check translation - # Check there is only one translation change - # If there are more than one, the workflow will fail - id: translation-changes - run: | - changed_files=$(cat ./changed_files.txt) - if [ -z "$changed_files" ]; then - echo "No files changed" - else - translation_files=$(echo "$changed_files" | grep -E ".*\.md" || ./pass.sh) - echo "$translation_files" - echo "$translation_files" > ./translation_files.txt - fi - - id: translation-check - run: | - translation_files=$(cat ./translation_files.txt) - if [ -z "$translation_files" ]; then - echo "No translation files changed" - else - if [ $(echo "$translation_files" | wc -l) -gt 1 ]; then - echo "More than one translation file changed" - exit 1 - else - echo "translation=$translation_files" >> $GITHUB_OUTPUT - fi - fi - languagetool: - if: ${{ needs.prepare-translation.outputs.translation != '' }} - name: runner / languagetool - needs: [prepare-translation] - outputs: - has_matches: ${{ steps.check-spelling.outputs.has_matches }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Remove code blocks - run: | - file=${{ needs.prepare-translation.outputs.translation }} - sed -i '/```/,/```/d' $file - # Strip all macros - - id: strip-macros - run: | - file=${{ needs.prepare-translation.outputs.translation }} - # Remove all macros with no arguments - sed -i 's/{{[a-zA-Z_-]*}}//' $file - # Replace macros with one argument - sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\))}}/\1/g' $file - # Replace macros with two arguments - sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\))}}/\2/g' $file - # Replace macros with more than two arguments - sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\))}}/\2/g' $file - # Reduce markdown to plain text - - run: sudo apt install pandoc -y - - id: md2txt - name: Convert markdown to plain text - run: | - file=${{ needs.prepare-translation.outputs.translation }} - tmpHtmlFile=$(echo $file | sed 's/\.md/\.html/') - pandoc -f markdown -t html -o $tmpHtmlFile $file - newFileName=$(echo $file | sed 's/\.md/\.txt/') - pandoc -f html -t plain -o $newFileName $tmpHtmlFile - echo "translation=$newFileName" >> $GITHUB_OUTPUT - echo $newFileName - - if: steps.md2txt.outputs.translation == '' - name: Check translation is found - run: echo "No translation file found" && exit 1 - - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: "8" - - name: Download LanguageTool - run: wget -q https://languagetool.org/download/LanguageTool-6.3.zip - - name: Unzip LanguageTool - run: unzip -qq LanguageTool-6.3.zip - - name: Add spelling additions - run: | - cat uk_spelling_additions.txt >> ./LanguageTool-6.3/org/languagetool/resource/uk/hunspell/spelling.txt - cat uk_ignore_additions.txt >> ./LanguageTool-6.3/org/languagetool/resource/uk/hunspell/ignore.txt - - id: disabled-rules - name: Determine disabled rules - run: echo "disabled_rules=$(cat disabled_rules.txt | tr '\n' ',')" >> $GITHUB_OUTPUT - - id: check-spelling - name: Check spelling - run: | - cd LanguageTool-6.3 - java -jar languagetool-commandline.jar -d ${{steps.disabled-rules.outputs.disabled_rules}} -l uk --json ../${{ steps.md2txt.outputs.translation }} > ../result.json - cat ../result.json - matches=$(cat ../result.json | jq '.matches') - # Check if matches equal [] - echo "has_matches=$(if [ "$matches" == "[]" ]; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT - - name: Upload result.json - uses: actions/upload-artifact@v3 - with: - name: result - path: result.json - - name: Upload text file - uses: actions/upload-artifact@v3 - with: - name: text - path: ${{ steps.md2txt.outputs.translation }} - report-spelling: - if: ${{ needs.languagetool.outputs.has_matches != 'false' }} - name: Report spelling - needs: [prepare-translation, languagetool] - permissions: - contents: read - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 - with: - name: result - path: . - - uses: actions/setup-node@v4 - with: - node-version: "16" - - uses: actions/download-artifact@v3 - with: - name: text - path: . - - name: Create mapping - run: node scripts/create-file-mapping.js ./index.txt ${{ needs.prepare-translation.outputs.translation }} > ./mapping.json && cat ./mapping.json - - env: - COMMIT_ID: ${{ github.event.pull_request.head.sha }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} - name: Send results - run: node scripts/send-comments.js ${{ needs.prepare-translation.outputs.translation }} - timeout-minutes: 5 - - name: Exit with error - run: echo "Spelling errors found" && cat result.json && exit 1 diff --git a/.github/workflows/translation.yml b/.github/workflows/translation.yml new file mode 100644 index 0000000000..d6ace71d36 --- /dev/null +++ b/.github/workflows/translation.yml @@ -0,0 +1,274 @@ +name: spellcheck +on: [pull_request] +jobs: + prepare: + outputs: + status: ${{ steps.translation-check.outputs.status }} + translation: ${{ steps.translation-check.outputs.translation }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: changed-files + run: git diff --diff-filter=d --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > ./changed_files.txt + - name: Check translation + # Check there is only one translation change + # If there are more than one, the workflow will fail + id: translation-changes + run: | + changed_files=$(cat ./changed_files.txt) + if [ -z "$changed_files" ]; then + echo "No files changed" + else + translation_files=$(echo "$changed_files" | grep -E ".*\.md" || ./pass.sh) + # Filter out files not in "files/uk" folder + translation_files=$(echo "$translation_files" | grep -E "^files/uk/.*\.md" || ./pass.sh) + echo "$translation_files" + echo "$translation_files" > ./translation_files.txt + fi + - id: translation-check + run: | + translation_files=$(cat ./translation_files.txt) + if [ -z "$translation_files" ]; then + echo "No translation files changed" + else + if [ $(echo "$translation_files" | wc -l) -gt 1 ]; then + echo "More than one translation file changed" + exit 1 + else + echo "translation=$translation_files" >> $GITHUB_OUTPUT + # Does this file exist in the commit ${{ github.event.pull_request.head.sha }}? + if $(git show ${{ github.event.pull_request.head.sha }}:$translation_files > /dev/null 2>&1); then + echo "status=update" >> $GITHUB_OUTPUT + else + echo "status=translation" >> $GITHUB_OUTPUT + fi + fi + fi + languagetool: + if: ${{ needs.prepare.outputs.translation != '' }} + name: runner / languagetool + needs: [prepare] + outputs: + has_mistakes: ${{ steps.check-spelling.outputs.has_mistakes }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Remove code blocks + run: | + file=${{ needs.prepare.outputs.translation }} + sed -i '/```/,/```/d' $file + # Strip all macros + - id: strip-macros + run: | + file=${{ needs.prepare.outputs.translation }} + # Remove all macros with no arguments + sed -i 's/{{[a-zA-Z_-]*}}//' $file + # Replace macros with one argument + sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\))}}/\1/g' $file + # Replace macros with two arguments + sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\))}}/\2/g' $file + # Replace macros with more than two arguments + sed -i 's/{{[[:alnum:]_-]*(\("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\), \("[[:alnum:]_-]*"\))}}/\2/g' $file + # Reduce markdown to plain text + - run: sudo apt install pandoc -y + - id: md2txt + name: Convert markdown to plain text + run: | + file=${{ needs.prepare.outputs.translation }} + tmpHtmlFile=$(echo $file | sed 's/\.md/\.html/') + pandoc -f markdown -t html -o $tmpHtmlFile $file + newFileName=$(echo $file | sed 's/\.md/\.txt/') + pandoc -f html -t plain -o $newFileName $tmpHtmlFile + echo "translation=$newFileName" >> $GITHUB_OUTPUT + echo $newFileName + - if: steps.md2txt.outputs.translation == '' + name: Check translation is found + run: echo "No translation file found" && exit 1 + - uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: "8" + - name: Download LanguageTool + run: wget -q https://languagetool.org/download/LanguageTool-6.3.zip + - name: Unzip LanguageTool + run: unzip -qq LanguageTool-6.3.zip + - name: Add spelling additions + run: | + cat uk_spelling_additions.txt >> ./LanguageTool-6.3/org/languagetool/resource/uk/hunspell/spelling.txt + cat uk_ignore_additions.txt >> ./LanguageTool-6.3/org/languagetool/resource/uk/hunspell/ignore.txt + - id: disabled-rules + name: Determine disabled rules + run: echo "disabled_rules=$(cat disabled_rules.txt | tr '\n' ',')" >> $GITHUB_OUTPUT + - id: check-spelling + name: Check spelling + run: | + cd LanguageTool-6.3 + java -jar languagetool-commandline.jar -d ${{steps.disabled-rules.outputs.disabled_rules}} -l uk --json ../${{ steps.md2txt.outputs.translation }} > ../result.json + cat ../result.json + matches=$(cat ../result.json | jq '.matches') + # Check if matches equal [] + echo "has_mistakes=$(if [ "$matches" == "[]" ]; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT + - name: Upload result.json + uses: actions/upload-artifact@v3 + with: + name: result + path: result.json + - name: Upload text file + uses: actions/upload-artifact@v3 + with: + name: text + path: ${{ steps.md2txt.outputs.translation }} + report-spelling: + if: ${{ needs.languagetool.outputs.has_mistakes != 'false' }} + name: Report spelling + needs: [prepare, languagetool] + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v3 + with: + name: result + path: . + - uses: actions/setup-node@v4 + with: + node-version: "16" + - uses: actions/download-artifact@v3 + with: + name: text + path: . + - name: Create mapping + run: node scripts/create-file-mapping.js ./index.txt ${{ needs.prepare.outputs.translation }} > ./mapping.json && cat ./mapping.json + - env: + COMMIT_ID: ${{ github.event.pull_request.head.sha }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + name: Send results + run: node scripts/send-comments.js ${{ needs.prepare.outputs.translation }} + timeout-minutes: 5 + - name: Exit with error + run: echo "Spelling errors found" && cat result.json && exit 1 + set-title: + if: ${{ needs.prepare.outputs.translation != '' }} + name: Set title + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - id: determine + run: | + translation=${{ needs.prepare.outputs.translation }} + # Trim files/uk/ from the beginning of the path + translation=${translation#files/uk/} + # Trim index.md from the end of the path + translation=${translation%/index.md} + echo "slug=$translation" >> $GITHUB_OUTPUT + # Set the topmost folder as a section + section=$(echo $translation | cut -d'/' -f1) + # if section is "web", switch to the second folder + section=$(if [ "$section" == "web" ]; then echo $(echo $translation | cut -d'/' -f2); else echo "$section"; fi) + # if section is "javascript", set it to "JS" + section=$(if [ "$section" == "javascript" ]; then echo "JS"; else echo "$section"; fi) + # if section is "css", set it to "CSS" + section=$(if [ "$section" == "css" ]; then echo "CSS"; else echo "$section"; fi) + # if section is "html", set it to "HTML" + section=$(if [ "$section" == "html" ]; then echo "HTML"; else echo "$section"; fi) + # if section is "svg", set it to "SVG" + section=$(if [ "$section" == "svg" ]; then echo "SVG"; else echo "$section"; fi) + # otherwise, just capitalize the first letter + section=$(echo $section | sed 's/\b\(.\)/\u\1/g') + echo "section=$section" >> $GITHUB_OUTPUT + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit ${{ github.event.pull_request.number }} --title "${{ needs.prepare.outputs.status }}(${{ steps.determine.outputs.section }}): ${{ steps.determine.outputs.slug }}" + set-translation-body: + if: ${{ needs.prepare.outputs.translation != '' && needs.prepare.outputs.status == 'translation' }} + name: Set translation body + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # set the last section of slug as name + - id: create-body + run: | + translation=${{ needs.prepare.outputs.translation }} + # get "slug" frontmatter value + slug=$(cat $translation | grep -E "^slug: " | sed 's/slug: //') + # get "title" frontmatter value + title=$(cat $translation | grep -E "^title: " | sed 's/title: //') + # escape HTML entities from title + title=$(echo $title | sed 's//\>/g') + # replace "/uk/" with "/en-us/" in translation + original=$(echo $translation | sed 's/\/uk\//\/en-us\//') + body="Оригінальний вміст: [$title@MDN](https://developer.mozilla.org/en-us/docs/$slug), [сирці $title@GitHub](https://github.com/mdn/content/blob/main/$original)" + echo $body + echo "body=$body" >> $GITHUB_OUTPUT + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit ${{ github.event.pull_request.number }} --body "${{ steps.create-body.outputs.body }}" + set-update-body: + if: ${{ needs.prepare.outputs.translation != '' && needs.prepare.outputs.status == 'update' }} + name: Set update body + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # We need latest commit in master, not PR commit + ref: master + - id: get-latest-commit-time + name: Get latest commit time + run: | + latest_commit_time=$(git log -1 --format=%ct -- ${{ needs.prepare.outputs.translation }}) + echo "latest_commit_time=$latest_commit_time" >> $GITHUB_OUTPUT + - name: Checkout original content + uses: actions/checkout@v4 + with: + repository: mdn/content + path: original + fetch-depth: 0 + - id: get-new-commits + name: Get new commits + # Get new commits sha for $translation file + run: | + original=${{ needs.prepare.outputs.translation }} + # replace /uk/ with /en-us/ in original + original=$(echo $original | sed 's/\/uk\//\/en-us\//') + cd ./original + git log --pretty=format:"%H" --since=${{steps.get-latest-commit-time.outputs.latest_commit_time}} -- $original > ../new_commits.txt + cat ../new_commits.txt + - id: create-body + run: | + translation=${{ needs.prepare.outputs.translation }} + # get "slug" frontmatter value + slug=$(cat $translation | grep -E "^slug: " | sed 's/slug: //') + # get "title" frontmatter value + title=$(cat $translation | grep -E "^title: " | sed 's/title: //') + # escape HTML entities from title + title=$(echo $title | sed 's//\>/g') + # replace "/uk/" with "/en-us/" in translation + original=$(echo $translation | sed 's/\/uk\//\/en-us\//') + echo "Оригінальний вміст: [$title@MDN](https://developer.mozilla.org/en-us/docs/$slug), [сирці $title@GitHub](https://github.com/mdn/content/blob/main/$original)" > ./body.md + echo "" >> ./body.md + echo "Нові зміни:" >> ./body.md + # Add commits from ./new_commits.txt to body as links + commits=$(cat ./new_commits.txt) + for commit in $commits + do + echo "- [$(cd ./original && git log -1 --format=%s $commit)](https://github.com/mdn/content/commit/$commit)" >> ./body.md + done + cat ./body.md + + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit ${{ github.event.pull_request.number }} --body "$(cat ./body.md)" diff --git a/disabled_rules.txt b/disabled_rules.txt index dc91204c14..cfa68267e9 100644 --- a/disabled_rules.txt +++ b/disabled_rules.txt @@ -3,3 +3,5 @@ UK_SIMPLE_REPLACE_SOFT WHITESPACE_RULE COMMA_PARENTHESIS_WHITESPACE UK_MIXED_ALPHABETS +PRY_PORIVNYANNI +UPPERCASE_SENTENCE_START From 68cc60947f80cafdaa423e8be73e6b80f7b6146c Mon Sep 17 00:00:00 2001 From: Vitalii Perehonchuk Date: Sun, 26 Nov 2023 22:09:20 +0200 Subject: [PATCH 13/13] fix: save body in file --- .github/workflows/translation.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/translation.yml b/.github/workflows/translation.yml index d6ace71d36..8594793422 100644 --- a/.github/workflows/translation.yml +++ b/.github/workflows/translation.yml @@ -38,8 +38,8 @@ jobs: exit 1 else echo "translation=$translation_files" >> $GITHUB_OUTPUT - # Does this file exist in the commit ${{ github.event.pull_request.head.sha }}? - if $(git show ${{ github.event.pull_request.head.sha }}:$translation_files > /dev/null 2>&1); then + # Does this file exist in the commit ${{ github.event.pull_request.base.sha }}? + if $(git show ${{ github.event.pull_request.base.sha }}:$translation_files > /dev/null 2>&1); then echo "status=update" >> $GITHUB_OUTPUT else echo "status=translation" >> $GITHUB_OUTPUT @@ -208,11 +208,11 @@ jobs: original=$(echo $translation | sed 's/\/uk\//\/en-us\//') body="Оригінальний вміст: [$title@MDN](https://developer.mozilla.org/en-us/docs/$slug), [сирці $title@GitHub](https://github.com/mdn/content/blob/main/$original)" echo $body - echo "body=$body" >> $GITHUB_OUTPUT + echo $body > ./body.md - env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh pr edit ${{ github.event.pull_request.number }} --body "${{ steps.create-body.outputs.body }}" + gh pr edit ${{ github.event.pull_request.number }} --body "$(cat ./body.md)" set-update-body: if: ${{ needs.prepare.outputs.translation != '' && needs.prepare.outputs.status == 'update' }} name: Set update body