1+ # .github/workflows/comment-docs-preview.yml
2+ name : Comment Docs Build Status
3+
4+ on :
5+ workflow_run :
6+ workflows : ["Build Docs Preview"]
7+ types :
8+ - completed
9+
10+ jobs :
11+ comment :
12+ runs-on : ubuntu-latest
13+ permissions :
14+ pull-requests : write
15+
16+ steps :
17+ - name : Download build result
18+ uses : actions/download-artifact@v4
19+ with :
20+ name : build-result
21+ github-token : ${{ secrets.GITHUB_TOKEN }}
22+ run-id : ${{ github.event.workflow_run.id }}
23+
24+ - name : Read PR number
25+ id : pr
26+ run : echo "number=$(cat pr_number.txt)" >> $GITHUB_OUTPUT
27+
28+ - name : Read build log
29+ id : log
30+ run : |
31+ # Grab the last 20 lines so the comment isn't massive
32+ LOG=$(tail -20 build.log)
33+ # GitHub Actions has a specific way to handle multiline strings
34+ echo "content<<EOF" >> $GITHUB_OUTPUT
35+ echo "$LOG" >> $GITHUB_OUTPUT
36+ echo "EOF" >> $GITHUB_OUTPUT
37+
38+ - name : Post comment
39+ uses : actions/github-script@v7
40+ with :
41+ script : |
42+ const success = '${{ github.event.workflow_run.conclusion }}' === 'success';
43+ const icon = success ? '✅' : '❌';
44+ const status = success ? 'succeeded' : 'failed';
45+
46+ const body = `### ${icon} Docs build ${status}
47+
48+ <details>
49+ <summary>Build log (last 20 lines)</summary>
50+
51+ \`\`\`
52+ ${{ steps.log.outputs.content }}
53+ \`\`\`
54+
55+ </details>`;
56+
57+ github.rest.issues.createComment({
58+ owner: context.repo.owner,
59+ repo: context.repo.repo,
60+ issue_number: ${{ steps.pr.outputs.number }},
61+ body: body
62+ });
0 commit comments