1212
1313jobs :
1414 comment :
15- if : github.event.workflow_run.event == 'pull_request'
15+ if : ${{ github.event.workflow_run.conclusion == 'success' && github. event.workflow_run.event == 'pull_request' }}
1616 runs-on : ubuntu-latest
1717 steps :
18- - name : Check out PR code
19- uses : actions/checkout@v6
20-
21- - name : Download Trivy PR artifacts
22- uses : actions/download-artifact@v4
23- with :
24- run-id : ${{ github.event.workflow_run.id }}
25- name : trivy-pr-report
26- path : trivy-artifacts
27- repository : ${{ github.repository }}
28- github-token : ${{ secrets.GITHUB_TOKEN }}
29-
3018 - name : Determine PR number securely
3119 id : get_pr
3220 env :
@@ -46,29 +34,43 @@ jobs:
4634
4735 echo "PR_NUMBER=$PR_NUM" >> $GITHUB_ENV
4836
49- - name : Publish Trivy test report
50- uses : ctrf-io /github-test-reporter@v1
37+ - name : Comment PR with Trivy summary link
38+ uses : actions /github-script@v8
5139 with :
52- report-path : trivy-artifacts/trivy-junit.xml
53- summary-report : false
54- failed-report : true
55- pull-request : ${{ env.PR_NUMBER }}
56- update-comment : true
57- overwrite-comment : true
58- integrations-config : |
59- {
60- "junit-to-ctrf": {
61- "enabled": true,
62- "action": "convert",
63- "options": {
64- "output": "./ctrf-reports/ctrf-report.json",
65- "toolname": "junit-to-ctrf",
66- "useSuiteName": false,
67- "env": {
68- "appName": "vEcoli"
69- }
70- }
71- }
40+ script : |
41+ const issue_number = Number(process.env.PR_NUMBER);
42+ if (!issue_number) {
43+ core.info('No PR number available.');
44+ return;
45+ }
46+ const header = '## Trivy scan results';
47+ const runUrl = context.payload.workflow_run.html_url;
48+ const comment = `${header}\n\nThe Trivy vulnerability report is available in the workflow summary:\n${runUrl}`;
49+ const { data: comments } = await github.rest.issues.listComments({
50+ owner: context.repo.owner,
51+ repo: context.repo.repo,
52+ issue_number,
53+ per_page: 100,
54+ });
55+ const existing = comments.find((c) => {
56+ if (!c.body) return false;
57+ const isBot = c.user && c.user.type === 'Bot';
58+ return isBot && c.body.startsWith(header);
59+ });
60+ if (existing) {
61+ await github.rest.issues.updateComment({
62+ owner: context.repo.owner,
63+ repo: context.repo.repo,
64+ comment_id: existing.id,
65+ body: comment,
66+ });
67+ } else {
68+ await github.rest.issues.createComment({
69+ owner: context.repo.owner,
70+ repo: context.repo.repo,
71+ issue_number,
72+ body: comment,
73+ });
7274 }
7375 env :
74- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
76+ PR_NUMBER : ${{ env.PR_NUMBER }}
0 commit comments