Repository navigation
71 lines (66 loc) · 2.81 KB
/
Copy pathbenchmarks_comment.yml
File metadata and controls
71 lines (66 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Benchmarks Comment
# Posts the compiler benchmarks report of a pull request's CI run as the
# pull request's one comment, edited in place on each push, also when
# nothing changed, so that it shows the comparison ran.
#
# CI can't comment itself: a pull request from a fork runs it with a token
# that can't write. This workflow runs the default branch's code with a token
# that can. It runs no code of the pull request, and the report it posts is
# only Markdown.
on:
workflow_run:
workflows: [CI]
types: [completed]
jobs:
comment:
if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-26.04
permissions:
actions: read
contents: read
pull-requests: write
steps:
# For the comment action only; on workflow_run this is the default
# branch, not the pull request. First, since a checkout empties the
# directory.
- name: Checkout comment action
uses: actions/checkout@v7
with:
sparse-checkout: .github/actions
persist-credentials: false
# workflow_run names no pull request from a fork, so the pull request
# is the open one whose head is the run's. One that has moved on gets
# its comment from the newer run.
- name: Find the pull request and its report
id: report
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
[[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "Not a commit: $HEAD_SHA" >&2; exit 1; }
pr=$(gh api --method GET "repos/$GITHUB_REPOSITORY/pulls" \
-f state=open -f head="$HEAD_OWNER:$HEAD_BRANCH" \
--jq "first(.[] | select(.head.sha == \"$HEAD_SHA\") | .number) // empty")
if [ -z "$pr" ]; then
echo "No open pull request has head $HEAD_SHA."
exit 0
fi
count=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/artifacts?name=compiler-benchmarks-report" \
--jq .total_count)
if [ "$count" = 0 ]; then
echo "Run $RUN_ID has no benchmarks report."
exit 0
fi
gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" \
--name compiler-benchmarks-report --dir "$RUNNER_TEMP/report"
echo "pr-number=$pr" >> "$GITHUB_OUTPUT"
- name: Comment on the pull request
if: steps.report.outputs.pr-number
uses: ./.github/actions/upsert-comment
with:
pr-number: ${{ steps.report.outputs.pr-number }}
tag: compiler-benchmarks
body-path: ${{ runner.temp }}/report/benchmarks-report.md