-
Notifications
You must be signed in to change notification settings - Fork 14
65 lines (58 loc) · 2.23 KB
/
Copy pathvisual-comment.yml
File metadata and controls
65 lines (58 loc) · 2.23 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
name: Visual comment
# Posts visual.yml's PR summary as a sticky comment. Runs from the base repository so it can
# write to PRs from forks; it never checks out PR code and treats the artifact as untrusted.
on:
workflow_run:
workflows: [ Visual ]
types: [ completed ]
permissions: {}
jobs:
comment:
if: >-
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion != 'cancelled' &&
github.event.workflow_run.conclusion != 'skipped'
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
steps:
- uses: actions/download-artifact@v8
id: download
continue-on-error: true
with:
name: visual-comment
path: comment
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Validate
id: pr
if: steps.download.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
pr=$(cat comment/pr)
notable=$(cat comment/notable)
[[ "$pr" =~ ^[0-9]+$ ]] || { echo "invalid PR number"; exit 1; }
[[ "$notable" == true || "$notable" == false ]] || { echo "invalid notable flag"; exit 1; }
pr_head=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .head.sha)
[[ "$pr_head" == "$HEAD_SHA" ]] || { echo "PR #$pr is not at $HEAD_SHA; skipping"; exit 0; }
echo "number=$pr" >> "$GITHUB_OUTPUT"
echo "notable=$notable" >> "$GITHUB_OUTPUT"
- name: Post comment
if: steps.pr.outputs.notable == 'true'
uses: marocchino/sticky-pull-request-comment@v3.0.5
with:
header: visual-regression
number_force: ${{ steps.pr.outputs.number }}
path: comment/comment.md
# A clean run only refreshes an earlier comment, so passing PRs stay quiet.
- name: Update comment
if: steps.pr.outputs.notable == 'false'
uses: marocchino/sticky-pull-request-comment@v3.0.5
with:
header: visual-regression
number_force: ${{ steps.pr.outputs.number }}
path: comment/comment.md
only_update: true