name: Post PR Comment
on:
workflow_run:
workflows: [CI]
types: [completed]
permissions:
pull-requests: write
actions: read
jobs:
comment:
name: Post or update PR comment
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Download PR comment artifact
uses: actions/download-artifact@v4
with:
name: crap-pr-comment
path: .
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Post or update PR comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
if (!fs.existsSync('crap-comment.md') || !fs.existsSync('pr-number.txt')) return;
const body = fs.readFileSync('crap-comment.md', 'utf8');
const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim(), 10);
if (!prNumber) return;
const marker = '<!-- cargo-crap-report -->';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.startsWith(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}