From 7e7705c76aa5372975a7f4c25c0b81f00f78c55d Mon Sep 17 00:00:00 2001 From: rahul Date: Sat, 30 Mar 2024 20:02:46 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A5=20ci(Spell=20check):=20Github=20ac?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PULL_REQUEST_TEMPLATE.md | 17 +++++++ .github/workflows/spell-check.yml | 75 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/spell-check.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..39e2d0e8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +# Checklist + +- [ ] Review changes to ensure there are no typos. + + \ No newline at end of file diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml new file mode 100644 index 00000000..a3ba1a7e --- /dev/null +++ b/.github/workflows/spell-check.yml @@ -0,0 +1,75 @@ +name: 🥢 Spell check + +on: + pull_request: + branches: + - main + +jobs: + typo_check: + name: 🥢 Spell check + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + env: + TYPOS: "" + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 2 + + - name: Install aspell + run: sudo apt-get update && sudo apt-get install -y aspell + + - name: Find and check typos in Markdown files + id: find_typos + run: | + echo "Checking for typos..." + for file in $(find . -name "*.md" ); do + output="$(aspell --lang=en_US --mode=markdown --home-dir=. --personal=wordlist.txt --ignore-case=true list <$file | sed 's/^/ 1. /')" + if [[ -n "$output" ]]; then + TYPOS+="- 📄 $file:" + TYPOS+=$'\n' + TYPOS+="$output" + TYPOS+=$'\n' + fi + done + { + echo 'TYPOS<> "$GITHUB_ENV" + + - name: Comment on pull request + if: env.TYPOS != '' + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const author = '${{github.event.pull_request.user.login}}'; + const typos = `${{ env.TYPOS }}`; + const body = ` + Hi @${author}, + + Following typos were found in the pull request: + + ${typos} + + ## ℹ️ Here's how to fix them: + - **Fix typos:** Open the relevant files and fix any identified typos. + - **Update wordlist:** If a flagged word is actually a project-specific term add it to \`wordlist.txt\` in the project root. + Each word should be listed on a separate line and must not have any spaces before or after it. + `; + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + + core.setFailed('🥢 Spell check: Typos found in docs. Please fix them.'); \ No newline at end of file