add comments to successful config #62
This file contains 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: CSpell Check | ||
on: | ||
issue_comment: | ||
types: [created] | ||
jobs: | ||
spellcheck: | ||
if: github.event.comment.body == '/check-ru' && github.event.issue.pull_request != null | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # ensures the full git history is available | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- name: Install CSpell | ||
run: | | ||
npm install -g cspell | ||
npm install -g @cspell/dict-ru_ru | ||
cspell link add @cspell/dict-ru_ru | ||
npm install -g @cspell/dict-en-common-misspellings | ||
cspell link add @cspell/dict-en-common-misspellings | ||
- name: Get PR number | ||
id: pr | ||
run: echo "::set-output name=number::${{ github.event.issue.number }}" | ||
- name: Fetch all added and modified files | ||
id: files | ||
uses: jitterbit/get-changed-files@v1 | ||
with: | ||
format: 'space-delimited' | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run CSpell on all added and modified files | ||
id: cspell_check | ||
run: | | ||
output="" | ||
for file in ${{ steps.files.outputs.all_added_modified }}; do | ||
echo "Checking $file for spelling errors..." | ||
result=$(cspell "$file" --config cspell.json --show-suggestions) | ||
if [ -n "$result" ]; then | ||
output+="### Errors in $file:\n\\\\n$result\n\\\\n\n" | ||
fi | ||
done | ||
echo "::set-output name=results::${output}" | ||
- name: Post results as a PR comment | ||
if: steps.cspell_check.outputs.results != '' | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const output = ${{ steps.cspell_check.outputs.results }}; | ||
const prNumber = ${{ steps.pr.outputs.number }}; | ||
const repoName = context.repo.repo; | ||
const ownerName = context.repo.owner; | ||
github.rest.issues.createComment({ | ||
owner: ownerName, | ||
repo: repoName, | ||
issue_number: prNumber, | ||
body: output | ||
}); | ||