-
Notifications
You must be signed in to change notification settings - Fork 81
98 lines (84 loc) · 3.43 KB
/
comment-evolution-plot.yml
File metadata and controls
98 lines (84 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Comment PR with Evolution Plot
on:
workflow_run:
workflows:
- COMPAS compile test
types:
- completed
permissions:
actions: read
contents: read
issues: write
pull-requests: write
jobs:
comment-with-plot:
name: Post evolution plot comment
runs-on: ubuntu-22.04
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.pull_requests[0].number
env:
ARTIFACT_NAME: detailedEvolutionPlot.png
steps:
- name: Download evolution plot artifact from triggering run
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const runId = context.payload.workflow_run.id;
const runNumber = context.payload.workflow_run.run_number;
const artifactName = `evolution-plot-${runNumber}`;
const { owner, repo } = context.repo;
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts,
{ owner, repo, run_id: runId, per_page: 100 }
);
const artifact = artifacts.find((entry) => entry.name === artifactName);
if (!artifact) {
core.setFailed(`Artifact '${artifactName}' not found for workflow run ${runId}`);
return;
}
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.writeFileSync(
path.join(process.env.GITHUB_WORKSPACE, 'evolution-plot.zip'),
Buffer.from(download.data)
);
- name: Unpack evolution plot artifact
run: |
mkdir -p evolution-plot
unzip -o evolution-plot.zip -d evolution-plot
test -f "evolution-plot/${ARTIFACT_NAME}"
- name: Create report with evolution plot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
echo "## ✅ COMPAS Build Successful!" >> report.md
echo "" >> report.md
echo "| Item | Value |" >> report.md
echo "|------|-------|" >> report.md
echo "| **Commit** | [\`$(echo "$HEAD_SHA" | cut -c1-7)\`](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${HEAD_SHA}) |" >> report.md
echo "| **Logs** | [View workflow](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}) |" >> report.md
echo "" >> report.md
if [ -f "evolution-plot/${ARTIFACT_NAME}" ]; then
echo "### Detailed Evolution Plot" >> report.md
echo "<details><summary>Click to view evolution plot</summary>" >> report.md
echo "" >> report.md
echo "" >> report.md
echo "</details>" >> report.md
else
echo "### ⚠️ Evolution plot not found" >> report.md
fi
echo "" >> report.md
echo "---" >> report.md
echo "<sub>Generated by COMPAS CI </sub>" >> report.md
npx -y @dvcorg/cml comment create --pr "$PR_NUMBER" report.md