Repository navigation
Expand file tree
/
Copy pathcodegen-compatibility-comment.yml
More file actions
68 lines (60 loc) · 2.38 KB
/
Copy pathcodegen-compatibility-comment.yml
File metadata and controls
68 lines (60 loc) · 2.38 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
name: Codegen Compatibility Comment
# Fork pull request runs receive read-only tokens, so workflow_run posts the comments.
# Do not execute pull request code in this workflow. It has write permissions.
on:
workflow_run:
workflows: [Codegen Compatibility]
types: [completed]
permissions:
actions: read
pull-requests: write
jobs:
comment:
name: Post report
if: >
github.event.workflow_run.event == 'pull_request'
&& (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Download report
id: download
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: codegen-size-report
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
path: report
- name: Post or update comment
if: steps.download.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
pr=$(tr -cd '0-9' < report/pr-number)
if [ -z "$pr" ]; then
echo "The report does not name a pull request"
exit 1
fi
current=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .head.sha)
if [ "$current" != "$HEAD_SHA" ]; then
echo "PR #$pr moved from $HEAD_SHA to $current; a newer run will post its report"
exit 0
fi
marker='<!-- codegen-size-report -->'
existing=$(gh api "repos/$GITHUB_REPOSITORY/issues/$pr/comments" --paginate \
--jq ".[] | select(.body | startswith(\"$marker\")) | .id" | awk 'NR == 1')
if [ -z "$existing" ] && [ ! -f report/notable ]; then
echo "Nothing changed and no comment exists on PR #$pr; not commenting"
exit 0
fi
{ echo "$marker"; head -c 60000 report/report.md; } > body.md
if [ -n "$existing" ]; then
gh api --silent -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$existing" -F body=@body.md
echo "Updated comment $existing on PR #$pr"
else
gh api --silent -X POST "repos/$GITHUB_REPOSITORY/issues/$pr/comments" -F body=@body.md
echo "Commented on PR #$pr"
fi