Skip to content

Comment_PR

Comment_PR #297

Workflow file for this run

name: Comment_PR
on:
workflow_run:
workflows: ["Test_Change"]
types: [completed]
permissions:
pull-requests: write
actions: read
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Download PR comments artifact
id: download
uses: actions/download-artifact@v4
with:
name: pr-comments
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: pr-comments
continue-on-error: true
- name: Post comments on PR
if: steps.download.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const dir = 'pr-comments';
if (!fs.existsSync(dir)) {
core.info('No pr-comments directory, nothing to post.');
return;
}
const prNumberPath = path.join(dir, 'pr-number.txt');
if (!fs.existsSync(prNumberPath)) {
core.info('No pr-number.txt, nothing to post.');
return;
}
const prNumber = Number(fs.readFileSync(prNumberPath, 'utf8').trim());
if (!Number.isInteger(prNumber) || prNumber <= 0) {
core.setFailed(`Invalid PR number in artifact: ${prNumber}`);
return;
}
const files = fs.readdirSync(dir)
.filter(f => f.endsWith('.md'))
.sort();
for (const f of files) {
const body = fs.readFileSync(path.join(dir, f), 'utf8');
if (!body.trim()) continue;
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
}