Post Spell Check Result #54043
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: Post Spell Check Result | |
on: | |
workflow_run: | |
workflows: ["Text Changes Analyzer"] | |
types: | |
- completed | |
jobs: | |
post-spell-check-result: | |
runs-on: ubuntu-latest | |
if: > | |
${{ github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Download pr id artifact | |
uses: dawidd6/[email protected] | |
with: | |
workflow: ${{ github.event.workflow_run.name }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pull_request_id | |
allow_forks: false | |
- name: Download spell check retcode artifact | |
uses: dawidd6/[email protected] | |
with: | |
workflow: ${{ github.event.workflow_run.name }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: spell_check_retcode | |
allow_forks: false | |
- name: set-spell-check-retcode | |
id: set-spell-check-retcode | |
run: echo "spell-check-retcode=$( cat spell_check_retcode )" >> $GITHUB_OUTPUT | |
- name: Download spell check output artifact | |
if: steps.set-spell-check-retcode.outputs.spell-check-retcode >= 1 | |
uses: dawidd6/[email protected] | |
with: | |
workflow: ${{ github.event.workflow_run.name }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: spell_check_output | |
allow_forks: false | |
- name: 'Comment on PR' | |
if: steps.set-spell-check-retcode.outputs.spell-check-retcode >= 1 | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
var fs = require('fs'); | |
var issue_number = Number(fs.readFileSync('./pull_request_id')); | |
var body = fs.readFileSync('./spell_check_output', 'utf8'); | |
console.log("Fetching comments of pull request %d of repository %s/%s.", issue_number, context.repo.owner, context.repo.repo); | |
const comments = await github.paginate(github.rest.issues.listComments, | |
{ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number | |
} | |
); | |
const prev_spell_checks = comments.slice(0).reverse() | |
.filter(comment => comment.user.type === 'Bot' && comment.user.login === 'github-actions[bot]') | |
.filter(comment => comment.body.startsWith("Spell checker")); | |
if (prev_spell_checks.some(comment => comment.body === body)) { | |
console.log("The exact same spell checker comment already exists. Exiting."); | |
return; | |
} | |
for (const comment of prev_spell_checks) { | |
console.log("Deleting previous spell checker comment (comment id: %i)", comment.id); | |
await github.rest.issues.deleteComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: comment.id, | |
}); | |
} | |
console.log("Posting comment."); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: body | |
}); |