PR Benchmark reaction #1870
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
name: PR Benchmark reaction | |
# read-write repo token | |
# access to secrets | |
on: | |
workflow_run: | |
workflows: ["PR Benchmarks"] | |
types: | |
- completed | |
jobs: | |
upload: | |
name: Comment and upload | |
runs-on: ubuntu-latest | |
if: > | |
${{ github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Download artifact | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "benchmark-pr-html" | |
})[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/benchmark-pr-html.zip', Buffer.from(download.data)); | |
- name: Unzip PR Benchmark results | |
run: | | |
unzip benchmark-pr-html.zip | |
rm benchmark-pr-html.zip | |
- name: Show tree | |
run: tree -a . | |
- name: Set PR comment | |
id: bench_diff | |
shell: python | |
run: | | |
import os | |
from pathlib import Path | |
with open(os.getenv("GITHUB_OUTPUT"), "a", encoding="utf8") as f: | |
comment_file_path = Path("pr-diff-comment.txt") | |
f.write(f"comment<<EOF\n{comment_file_path.read_text().lstrip().rstrip()}\nEOF\n") | |
comment_file_path.unlink() | |
origin_pr_nr_file_path = Path("origin_pr_nr.txt") | |
f.writelines([f"pr_nr={origin_pr_nr_file_path.read_text()}"]) | |
origin_pr_nr_file_path.unlink() | |
- name: Show PR Number and Comment | |
shell: python | |
run: | | |
print(f"PR Number:\n{ ${{ steps.bench_diff.outputs.pr_nr }} }") | |
print("Comment Body:") | |
print("""${{ steps.bench_diff.outputs.comment }}""") | |
- name: Comment on PR | |
uses: hasura/comment-progress@v2 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
repository: "glotaran/pyglotaran" | |
number: ${{ steps.bench_diff.outputs.pr_nr }} | |
id: benchmark-comment | |
message: ${{ steps.bench_diff.outputs.comment }} | |
- name: Commit PR results | |
env: | |
PR_RESULT_BRANCH: pr-${{steps.bench_diff.outputs.pr_nr}} | |
run: | | |
git init | |
git checkout --orphan $PR_RESULT_BRANCH | |
git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
git config user.name 'github-actions[bot]' | |
git add . | |
git commit -m "🧪 PR benchmark" | |
- name: Push result repo | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.BENCHMARK_PUSH_TOKEN }} | |
repository: "glotaran/pyglotaran-benchmarks" | |
branch: pr-${{steps.bench_diff.outputs.pr_nr}} | |
force: true |