-
Notifications
You must be signed in to change notification settings - Fork 1.5k
54 lines (48 loc) · 1.77 KB
/
Copy pathcomment-bundle-size.yaml
File metadata and controls
54 lines (48 loc) · 1.77 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
name: Comment Bundle Size
# Runs when Measure Bundle Size workflow completes.
# This will run with full privileges.
on:
workflow_run:
workflows: [Measure Bundle Size]
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download report artifact
uses: actions/download-artifact@v7
with:
name: bundle-report
path: artifact
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.SHAKA_BOT_TOKEN }}
- name: Add or Update PR Comment
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SHAKA_BOT_TOKEN }}
COMMENT_INCLUDES: "Bundle Size Report"
COMMENT_USER: "shaka-bot"
run: |
MESSAGE=$(cat artifact/report.md)
echo "$MESSAGE"
PR_NUMBER=$(echo "$MESSAGE" | head -1 | grep -oE "[0-9]+")
echo "PR_NUMBER: $PR_NUMBER"
# Find existing bot comment
jq_filter=".[] | select((.user.login == \"$COMMENT_USER\") and (.body | startswith(\"$COMMENT_INCLUDES\"))) | .id"
gh api \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
| jq "$jq_filter" > old-comment-id
if [[ -z "$(cat old-comment-id)" ]]; then
echo "Creating new bundle size comment"
gh api \
--method POST \
/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
-f "body=$MESSAGE"
else
echo "Updating existing bundle size comment"
gh api \
--method PATCH \
/repos/${{ github.repository }}/issues/comments/$(cat old-comment-id) \
-f "body=$MESSAGE"
fi