Skip to content

Comment PR with Evolution Plot #1

Comment PR with Evolution Plot

Comment PR with Evolution Plot #1

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 "![](./evolution-plot/${ARTIFACT_NAME})" >> 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