Skip to content

Commit 64d22e8

Browse files
authored
Merge branch 'main' into error_brnahc
Signed-off-by: Minh Nguyen <[email protected]>
2 parents 9f7cba7 + e06bece commit 64d22e8

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

.github/workflows/ci-comment.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Metrics Comparison and Post Comment
2+
on:
3+
workflow_run:
4+
workflows: ["E2E Tests"]
5+
types: [completed]
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
jobs:
10+
metrics-comparison:
11+
name: Compare Metrics
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
ref: ${{ github.event.repository.default_branch }}
18+
19+
- name: Download all metrics artifacts from triggering workflow
20+
id: download-artifacts
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const { owner, repo } = context.repo;
25+
const workflowRunId = context.payload.workflow_run.id;
26+
27+
// List all artifacts from the triggering workflow run
28+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
29+
owner,
30+
repo,
31+
run_id: workflowRunId,
32+
});
33+
34+
// Download and extract each artifact
35+
const fs = require('fs');
36+
const path = require('path');
37+
const AdmZip = require('adm-zip');
38+
39+
for (const artifact of artifacts.data.artifacts) {
40+
const download = await github.rest.actions.downloadArtifact({
41+
owner,
42+
repo,
43+
artifact_id: artifact.id,
44+
archive_format: 'zip',
45+
});
46+
47+
const zip = new AdmZip(Buffer.from(download.data));
48+
zip.extractAllTo(path.join(process.env.GITHUB_WORKSPACE, '.metrics', artifact.name), true);
49+
console.log(`Extracted artifact: ${artifact.name}`);
50+
}
51+
52+
// Extract PR number (adapted from PDF logic)
53+
let prNumber = null;
54+
const pullRequest = await github.rest.pulls.list({
55+
owner,
56+
repo,
57+
head: `${context.payload.workflow_run.head_repository.full_name}:${context.payload.workflow_run.head_branch}`,
58+
});
59+
60+
if (pullRequest.data.length > 0) {
61+
prNumber = pullRequest.data[0].number;
62+
} else {
63+
// Fallback to commit SHA if needed
64+
const commitSha = context.payload.workflow_run.head_sha;
65+
const prsForCommit = await github.rest.repos.listPullRequestsAssociatedWithCommit({
66+
owner,
67+
repo,
68+
commit_sha: commitSha,
69+
});
70+
if (prsForCommit.data.length > 0) {
71+
prNumber = prsForCommit.data[0].number;
72+
}
73+
}
74+
75+
if (prNumber) {
76+
console.log(`Found PR Number: ${prNumber}`);
77+
core.setOutput('pr_number', prNumber);
78+
} else {
79+
console.log('Could not determine PR number. Skipping comment.');
80+
core.setFailed('Could not determine PR number for commenting.');
81+
}
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Install dependencies
86+
if: success() && steps.download-artifacts.outputs.pr_number
87+
run: |
88+
python3 -m pip install prometheus-client
89+
npm install @actions/core @actions/github
90+
91+
- name: Compare metrics and generate summary
92+
if: success() && steps.download-artifacts.outputs.pr_number
93+
id: compare-metrics
94+
shell: bash
95+
run: |
96+
bash ./scripts/e2e/metrics_summary.sh
97+
98+
- name: Debug PR number
99+
if: success()
100+
run: |
101+
echo "Event JSON: ${{ toJSON(github.event) }}"
102+
echo "Extracted PR: ${{ steps.download-artifacts.outputs.pr_number }}"
103+
104+
- name: Post PR comment with combined metrics summary
105+
if: steps.compare-metrics.outputs.DIFF_FOUND == 'true' && steps.download-artifacts.outputs.pr_number
106+
uses: thollander/actions-comment-pull-request@v3
107+
with:
108+
file-path: ./.metrics/combined_summary.md
109+
github-token: '${{ secrets.GITHUB_TOKEN }}'
110+
comment-tag: "## Metrics Comparison Summary"
111+
pr-number: ${{ steps.download-artifacts.outputs.pr_number }}

0 commit comments

Comments
 (0)