Skip to content

Post handler of korean checker #209

Post handler of korean checker

Post handler of korean checker #209

# This workflow will make a comment on the pull request
# about the part where Korean was found.
name: Post handler of korean checker
on:
workflow_run:
workflows: ["Korean checker"]
types:
- completed
env:
ARTIFACT_NAME: results-to-check-korean
FILE_KOREAN_CHECKING_RESULT: "korean-check-results.md"
FILE_REPORT: "checking-report.md"
jobs:
make-comment-on-the-pr:
name: Make a comment on the PR
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
# Permissions for the GITHUB_TOKEN
# Ref. https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
# issues: write
pull-requests: write
actions: read
steps:
- name: Download results
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Display structure of downloaded files for debugging
shell: bash
run: ls -R
- name: Check and make a report
id: check-and-make-report
shell: bash
run: |
REPORT="${FILE_REPORT}"
if [ -s "${FILE_KOREAN_CHECKING_RESULT}" ]; then
echo "(DEBUG) Korean texts are detected."
echo "**Could you please check and revise Korean texts?**" > $REPORT
echo "Note - All output of print and log statements should be in English. :wink:" >> $REPORT
echo "" >> $REPORT
cat "${FILE_KOREAN_CHECKING_RESULT}" >> "$REPORT"
echo "KOREAN_EXISTS=true" >> $GITHUB_OUTPUT
fi
# else
# echo "(DEBUG) No Korean texts are detected."
#
# echo "Good news! All print and log statements are in English, as per our guidelines. :blush:" > $REPORT
# echo "KOREAN_EXISTS=false" >> $GITHUB_OUTPUT
# fi
- name: Comment PR with results
if: steps.check-and-make-report.outputs.KOREAN_EXISTS == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const path = require('path');
// Read PR number
const prNumberPath = path.join(process.env.GITHUB_WORKSPACE, 'pr-number.txt');
let prNumber = '';
if (fs.existsSync(prNumberPath)) {
prNumber = fs.readFileSync(prNumberPath, 'utf8').trim();
}
// Read results to check Korean
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, '${{env.FILE_REPORT}}');
if (fs.existsSync(resultsPath)) {
const results = fs.readFileSync(resultsPath, 'utf8');
if (results.trim().length > 0 && prNumber.length > 0) {
github.rest.issues.createComment({
issue_number: parseInt(prNumber, 10),
owner: context.repo.owner,
repo: context.repo.repo,
body: results
});
}
}