Skip to content

PR Comment

PR Comment #6

Workflow file for this run

name: PR Comment
on:
workflow_run:
workflows: ["PR Check"]
types: [completed]
permissions:
pull-requests: write
actions: read
jobs:
comment:
runs-on: ubuntu-24.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Post PR comment with artifact links
uses: actions/github-script@v9
with:
script: |
const runId = context.payload.workflow_run.id;
const headSha = context.payload.workflow_run.head_sha;
// Look up the PR by head SHA — works for fork PRs too
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
per_page: 20,
});
const pr = prs.data.find(p => p.head.sha === headSha);
if (!pr) {
console.log(`No open PR found for SHA ${headSha}, skipping.`);
return;
}
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
});
const baseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts`;
const artifact = artifacts.data.artifacts.find(
a => a.name === `rendered-book-pr-${pr.number}`
);
const body = artifact
? `📖 **Quarto render succeeded!**\n\n📦 [Download rendered book](${baseUrl}/${artifact.id}) _(contains HTML site + PDF; unzip and open \`index.html\` locally)_\n\n> _Updated on every push to this PR. Links expire after 14 days._`
: `📖 **Quarto render succeeded!** (artifact unavailable)`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});
const existing = comments.data.find(
c => c.user.login === 'github-actions[bot]' && c.body.includes('Quarto render succeeded')
);
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: pr.number,
body,
});
}