-
Notifications
You must be signed in to change notification settings - Fork 126
88 lines (80 loc) · 3.5 KB
/
comment-on-pr.yaml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Comment on PR
on:
# This workflow doesn't show up in the PR, only in the actions tab. We need to use this
# separated workflow because pull_request events from forks are not allowed to have a
# write-token, and we need that to comment on the incoming PR. Changes to this file will
# not take place during the PR, this workflow runs using the version of this file on the
# default branch.
workflow_run:
workflows:
- Link Checking
types:
- completed
jobs:
comment-on-pr:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'skipped'
permissions:
pull-requests: write
steps:
- name: Download Report
uses: actions/download-artifact@v4
id: report
with:
name: report
path: ${{ github.workspace }}/reports
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Read PR number
id: pr-number
# Glob the downloaded folder for reports, should only be one in the artifact;
# Then extract the PR number from the report name and write it to the output file.
run: |
reports=( "${{ steps.report.outputs.download-path }}/*.md" )
if [ ${#reports[@]} -ne 1 ]; then
echo "Expected 1 report, found ${#reports[@]}"
exit 1
fi
echo "number=$(basename -- ${reports[0]} .md)" >> "$GITHUB_OUTPUT"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
if: github.event.workflow_run.event == 'pull_request'
with:
issue-number: ${{ steps.pr-number.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: <!-- link-checker -->
# An comment exists here already, and now there's no issues from the link checker
- name: Clear report
if: ${{ github.event.workflow_run.conclusion == 'success' && steps.fc.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
<!-- link-checker -->
Link checker still sees no broken links, all good! :tada:
# No comment exists here, and link checking found no issues
- name: No issues
if: ${{ github.event.workflow_run.conclusion == 'success' && steps.fc.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.pr-number.outputs.number }}
body: |
<!-- link-checker -->
Link checker found no broken links! :sparkles:
# No comment exists here, and the link checker has found issues
- name: Create new report
if: ${{ github.event.workflow_run.conclusion != 'success' && steps.fc.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.pr-number.outputs.number }}
body-path: "reports/${{ steps.pr-number.outputs.number }}.md"
# Update existing comment with new report
- name: Update report
if: ${{ github.event.workflow_run.conclusion != 'success' && steps.fc.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-path: "reports/${{ steps.pr-number.outputs.number }}.md"
edit-mode: replace