Skip to content

PR Comment with Performance Results #88

PR Comment with Performance Results

PR Comment with Performance Results #88

Workflow file for this run

name: PR Comment with Performance Results
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
artifact-metadata: read
issues: write
pull-requests: write
jobs:
comment:
if: github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Download performance results artifact
uses: actions/github-script@v8
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == 'performance-results';
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
if (!fs.existsSync(temp)){
fs.mkdirSync(temp);
}
fs.writeFileSync(path.join(temp, 'artifacts.zip'), Buffer.from(download.data));
- name: Extract and read performance results
run: |
unzip ${{ runner.temp }}/artifacts/artifacts.zip -d ${{ runner.temp }}/artifacts/
- name: Post comment on PR
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const path = require('path');
const resultPath = path.join('${{ runner.temp }}/artifacts/', 'performance_results.md');
const performanceResults = fs.readFileSync(resultPath, 'utf8');
const prNumberPath = path.join('${{ runner.temp }}/artifacts/', 'PR_NUMBER.txt');
const prNumber = fs.readFileSync(prNumberPath, 'utf8').trim();
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: performanceResults,
});