Skip to content

Commit

Permalink
ci: generate score comment
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Sep 10, 2024
1 parent 241833a commit 4b60ac3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/benchmark-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,15 @@ jobs:

- name: Run Benchmarks
run: cargo run -- --project ${{ github.event.pull_request.head.repo.owner.login }}

- name: Generate comment
run: ./comment.sh $( cat results/${{ github.event.pull_request.head.repo.owner.login }}/score.out )

- name: Show comment body
run: cat body.md

- name: "Upload Artifact"
uses: actions/upload-artifact@v4
with:
name: body
path: body.md
55 changes: 55 additions & 0 deletions .github/workflows/comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Comment on pull-request

on:
workflow_run:
workflows: ["Benchmark PR"]
types:
- completed

jobs:
macro_benchmarks_comment:
name: Benchmark comment
runs-on: ubuntu-latest
if: >
github.event.workflow_run.conclusion == 'success'
steps:
- name: Find associated pull request
id: pr
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
per_page: 1,
})
const items = response.data.items
if (items.length < 1) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
console.info("Pull request number is", pullRequestNumber)
return pullRequestNumber
- name: Find Hackathon PR comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.pr.outputs.result }}
comment-author: 'github-actions[bot]'
body-includes: '## Hackathon Score Report'

- name: Download artifact with body message
uses: actions/download-artifact@v4
with:
name: body
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.result }}
body-path: body.md
edit-mode: replace
2 changes: 1 addition & 1 deletion .github/workflows/generate-baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: cargo run --bin generate-baseline

- name: Commit & Push changes
uses: actions-js/push@master
uses: actions-js/push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: "reference/results"
20 changes: 20 additions & 0 deletions comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

score=$1

markdown_content=$(cat <<EOF
## Hackathon Score Report
The score is: **$score**
---
More detailed stats can be found inside the ci run for Benchmark.
Thank you for your submission!
EOF
)

echo "$markdown_content" > body.md

0 comments on commit 4b60ac3

Please sign in to comment.