From 4b60ac349b0b24910d9fc698125ef5f480012b15 Mon Sep 17 00:00:00 2001 From: meskill <8974488+meskill@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:23:24 +0000 Subject: [PATCH] ci: generate score comment --- .github/workflows/benchmark-pull-request.yaml | 12 ++++ .github/workflows/comment.yaml | 55 +++++++++++++++++++ .github/workflows/generate-baseline.yaml | 2 +- comment.sh | 20 +++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/comment.yaml create mode 100755 comment.sh diff --git a/.github/workflows/benchmark-pull-request.yaml b/.github/workflows/benchmark-pull-request.yaml index 526f29d..8bff8c5 100644 --- a/.github/workflows/benchmark-pull-request.yaml +++ b/.github/workflows/benchmark-pull-request.yaml @@ -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 diff --git a/.github/workflows/comment.yaml b/.github/workflows/comment.yaml new file mode 100644 index 0000000..f81e4d1 --- /dev/null +++ b/.github/workflows/comment.yaml @@ -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 diff --git a/.github/workflows/generate-baseline.yaml b/.github/workflows/generate-baseline.yaml index fd26ed9..651b09f 100644 --- a/.github/workflows/generate-baseline.yaml +++ b/.github/workflows/generate-baseline.yaml @@ -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" diff --git a/comment.sh b/comment.sh new file mode 100755 index 0000000..2158737 --- /dev/null +++ b/comment.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +score=$1 + +markdown_content=$(cat < body.md