Comment PR with Evolution Plot #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | | |
| set -e | |
| mkdir -p evolution-plot | |
| unzip -o evolution-plot.zip -d evolution-plot | |
| test -f "evolution-plot/${ARTIFACT_NAME}" | |
| - name: Post PR comment | |
| env: | |
| REPO_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: | | |
| set -e | |
| cat <<EOF > report.md | |
| ## ✅ COMPAS Build Successful! | |
| | Item | Value | | |
| |------|-------| | |
| | **Commit** | [\`$(echo "$HEAD_SHA" | cut -c1-7)\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$HEAD_SHA) | | |
| | **Logs** | [View workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$RUN_ID) | | |
| ### Detailed Evolution Plot | |
| <details><summary>Click to view evolution plot</summary> | |
|  | |
| </details> | |
| --- | |
| <sub>Generated by COMPAS CI</sub> | |
| EOF | |
| npx -y @dvcorg/cml@0.20.6 comment create --target=pr/"$PR_NUMBER" report.md |