name: GnuComment # spell-checker:ignore zizmor backquote on: workflow_run: workflows: ["GnuTests"] types: - completed # zizmor: ignore[dangerous-triggers] permissions: {} jobs: post-comment: permissions: actions: read # to list workflow runs artifacts pull-requests: write # to comment on pr runs-on: ubuntu-latest if: > github.event.workflow_run.event == 'pull_request' steps: - name: 'Download artifact' uses: actions/github-script@v9 with: script: | // List all artifacts from GnuTests var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{ github.event.workflow_run.id }}, }); // Download the "comment" artifact, which contains a PR number (NR) and result.txt var matchArtifact = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "comment" })[0]; var download = await github.rest.actions.downloadArtifact({ owner: context.repo.owner, repo: context.repo.repo, artifact_id: matchArtifact.id, archive_format: 'zip', }); var fs = require('fs'); fs.writeFileSync('${{ github.workspace }}/comment.zip', Buffer.from(download.data)); - run: unzip comment.zip - name: 'Comment on PR' uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs'); if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) { core.info("No GNU comment payload to post."); return; } const issue_number = Number(fs.readFileSync('./NR')); if (!issue_number) { core.info('No PR number; skipping.'); return; } const content = fs.readFileSync('./result.txt').toString(); const marker = ''; const body = `${marker}\nGNU testsuite comparison:\n\`\`\`\n${content}\n\`\`\``; const { data: comments } = await github.rest.issues.listComments({ ...context.repo, issue_number }); const existing = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.includes(marker) ); if (existing) { await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body }); } else { if (content.trim().length <= 7) { // 7 because we have backquote + \n return; } await github.rest.issues.createComment({ ...context.repo, issue_number, body }); }