Debian Codegraph @

.github/workflows/GnuComment.yml

raw
1 name: GnuComment
2
3 # spell-checker:ignore zizmor backquote
4
5 on:
6 workflow_run:
7 workflows: ["GnuTests"]
8 types:
9 - completed # zizmor: ignore[dangerous-triggers]
10
11 permissions: {}
12 jobs:
13 post-comment:
14 permissions:
15 actions: read # to list workflow runs artifacts
16 pull-requests: write # to comment on pr
17
18 runs-on: ubuntu-latest
19 if: >
20 github.event.workflow_run.event == 'pull_request'
21 steps:
22 - name: 'Download artifact'
23 uses: actions/github-script@v9
24 with:
25 script: |
26 // List all artifacts from GnuTests
27 var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
28 owner: context.repo.owner,
29 repo: context.repo.repo,
30 run_id: ${{ github.event.workflow_run.id }},
31 });
32
33 // Download the "comment" artifact, which contains a PR number (NR) and result.txt
34 var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
35 return artifact.name == "comment"
36 })[0];
37 var download = await github.rest.actions.downloadArtifact({
38 owner: context.repo.owner,
39 repo: context.repo.repo,
40 artifact_id: matchArtifact.id,
41 archive_format: 'zip',
42 });
43 var fs = require('fs');
44 fs.writeFileSync('${{ github.workspace }}/comment.zip', Buffer.from(download.data));
45 - run: unzip comment.zip
46
47 - name: 'Comment on PR'
48 uses: actions/github-script@v9
49 with:
50 github-token: ${{ secrets.GITHUB_TOKEN }}
51 script: |
52 const fs = require('fs');
53 if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) {
54 core.info("No GNU comment payload to post.");
55 return;
56 }
57 const issue_number = Number(fs.readFileSync('./NR'));
58 if (!issue_number) {
59 core.info('No PR number; skipping.');
60 return;
61 }
62 const content = fs.readFileSync('./result.txt').toString();
63
64 const marker = '<!-- gnu-comment-bot -->';
65 const body = `${marker}\nGNU testsuite comparison:\n\`\`\`\n${content}\`\`\``;
66
67 const { data: comments } = await github.rest.issues.listComments({
68 ...context.repo,
69 issue_number
70 });
71
72 const existing = comments.find(c =>
73 c.user.login === 'github-actions[bot]' &&
74 c.body.includes(marker)
75 );
76
77 if (existing) {
78 await github.rest.issues.updateComment({
79 ...context.repo,
80 comment_id: existing.id,
81 body
82 });
83 } else {
84 if (content.trim().length <= 7) { // 7 because we have backquote + \n
85 return;
86 }
87 await github.rest.issues.createComment({
88 ...context.repo,
89 issue_number,
90 body
91 });
92 }