Benchmarks - Report #4
This file contains 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
# Report benchmark results to the PR | |
# We need a dual workflow to make sure the token has the needed permissions to post comments | |
# See https://stackoverflow.com/a/71683208 for more details | |
# When this workflow is triggered, it pulls the latest version of this file on | |
# the default branch. Changes to this file won't be reflected until after the | |
# PR is merged. | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run | |
name: "Benchmarks - Report" | |
on: | |
workflow_run: | |
workflows: [Benchmarks] | |
types: | |
- completed | |
permissions: | |
pull-requests: write | |
issues: write | |
jobs: | |
download: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Download artifact" | |
uses: actions/github-script@v7 | |
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 artifactName = `asv-benchmark-results-${context.payload.workflow_run.id}-${context.payload.workflow_run.run_number}-${context.payload.workflow_run.run_attempt}` | |
console.log(`Artifact name: ${artifactName}`); | |
console.log(`All artifacts: ${JSON.stringify(allArtifacts.data.artifacts)}`); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == artifactName | |
})[0]; | |
if (matchArtifact === undefined) { | |
throw TypeError('Build Artifact not found!'); | |
} | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/asv_results.zip`, Buffer.from(download.data)); | |
- name: Unzip and prepare data | |
run: | | |
unzip asv_results.zip | |
# combine the Qt and non-Qt messages | |
cat message_Qt.txt message_non-Qt.txt > message.txt | |
- name: Replace URLs | |
run: | | |
sed -i 's@||BENCHMARK_CI_LOGS_URL||@${{ github.event.workflow_run.html_url }}@g' message.txt | |
- name: Collect PR number if available | |
run: | | |
if [[ -f pr_number ]]; then | |
echo "PR_NUMBER=$(cat pr_number)" >> "$GITHUB_ENV" | |
fi | |
- name: "Comment on PR" | |
if: env.PR_NUMBER != '' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
let fs = require('fs'); | |
let issue_number = Number(process.env.PR_NUMBER); | |
let body = fs.readFileSync('message.txt', 'utf8'); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: body, | |
}); | |
- name: "Remove run-benchmarks label" | |
if: env.PR_NUMBER != '' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
let fs = require('fs'); | |
let issue_number = Number(process.env.PR_NUMBER); | |
await github.rest.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
name: 'run-benchmarks', | |
}); |