Skip to content

PR E2E Results Comment #548

PR E2E Results Comment

PR E2E Results Comment #548

name: PR E2E Results Comment
on:
workflow_run:
workflows: ['E2E Tests (PR)']
types:
- completed
permissions:
pull-requests: write
actions: read
jobs:
comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Get PR number
id: pr
uses: actions/github-script@v7
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const pullRequests = context.payload.workflow_run.pull_requests;
if (pullRequests.length > 0) {
return pullRequests[0].number;
}
const prNumber = context.payload.workflow_run.head_branch.match(/^refs\/pull\/(\d+)\/merge$/);
if (prNumber) {
return parseInt(prNumber[1]);
}
return null;
- name: Comment PR with results
if: steps.pr.outputs.result != 'null'
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.pr.outputs.result }};
const conclusion = '${{ github.event.workflow_run.conclusion }}';
const runId = '${{ github.event.workflow_run.id }}';
const emoji = conclusion === 'success' ? '✅' : '❌';
const status = conclusion === 'success' ? 'passed' : 'failed';
const comment = `### E2E Test Results ${emoji}
All tests have completed. Tests ${status}.
**Matrix:** 2 OS (Ubuntu, macOS) × 2 Templates (TypeScript, Python) = 4 jobs
[View detailed test results](https://github.com/${{ github.repository }}/actions/runs/${runId})
---
<sub>This comment is automatically posted by the PR E2E Results workflow.</sub>`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('E2E Test Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
}