Skip to content

Commit 1947eae

Browse files
authored
Update reporting functionality (#32)
* Update CML syntax for link check diff report * Add new reports and options * Add remaining needed inputs, replace lychee hard-codes, add workflow_dispatch * Add pull_request for testing * Add useful test * Fix useful test * Add @latest * Remove failure clause on issue creation * Fix pattern * Re-add failure check for report creation * Fix rootURL option * Remove rootURL option in favor of config * Use different failure flow * Fix default labels field * Add a title * Remove failing link for test purposes * Remove test file and reset test fixture
1 parent 52b2ccf commit 1947eae

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

.github/workflows/link-check-all.yml

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,50 @@ name: Check all links in the repository
22
on:
33
workflow_call:
44
inputs:
5+
failsOnly:
6+
type: "boolean"
7+
required: false
8+
description: "If true, only reports failed links"
9+
default: true
10+
outputFile:
11+
type: "string"
12+
required: false
13+
description: "The file the link check report will be written to before publishing"
14+
default: "link-check-report.md"
515
config:
616
type: 'string'
717
description: 'The path to the link-check config file'
818
default: 'config/link-check/config.yml'
19+
owner:
20+
description:
21+
The owner of repository to operate on if the event doesn't include it
22+
required: false
23+
type: string
24+
default: '${{ github.event.repository.owner.login }}'
25+
repo:
26+
description:
27+
The repository to operate on if the event doesn't include it
28+
required: false
29+
type: string
30+
default: '${{ github.event.repository.name }}'
31+
label:
32+
description:
33+
The label that will be used to identify existing link-check reports to
34+
edit
35+
required: false
36+
type: string
37+
default: link-check-all
38+
labels:
39+
description:
40+
The labels that will be assigned to issues created by this workflow
41+
required: false
42+
type: string
43+
default: link-check-all
44+
title:
45+
description: The title of the issue created by this workflow
46+
required: false
47+
type: string
48+
default: 'Link Checker Report'
949
jobs:
1050
run:
1151
name: Link Check All
@@ -14,6 +54,53 @@ jobs:
1454
NODE_OPTIONS: '--max-http-header-size=65536'
1555
steps:
1656
- uses: actions/checkout@v3
57+
- run: echo "# Link Check Report" > ${{ inputs.outputFile }}
1758
- name: Run Link Check
1859
id: check
19-
run: npx repo-link-check -c ${{ inputs.config }}
60+
run: |
61+
npx repo-link-check@latest \
62+
${{ inputs.failsOnly && '-f' || '' }} \
63+
-c ${{ inputs.config }} \
64+
>> ${{ inputs.outputFile }}
65+
66+
- name: Find latest open Link Check issue
67+
uses: actions/github-script@v6
68+
id: find-existing-comment
69+
if: always()
70+
env:
71+
OWNER: ${{ inputs.owner }}
72+
REPO: ${{ inputs.repo }}
73+
LABEL: ${{ inputs.label }}
74+
with:
75+
script: |
76+
const { OWNER, REPO, LABEL } = process.env
77+
const options = {
78+
owner: OWNER,
79+
repo: REPO,
80+
labels: LABEL,
81+
state: "open",
82+
creator: "github-actions[bot]",
83+
sort: "created"
84+
}
85+
const issues = await github.rest.issues.listForRepo(options)
86+
if(issues && issues.data && issues.data[0]) {
87+
return issues.data[0].number
88+
}
89+
90+
- name: Create or Update Issue
91+
uses: peter-evans/create-issue-from-file@v4
92+
if: failure()
93+
with:
94+
issue-number: ${{ steps.find-existing-comment.outputs.result }}
95+
title: ${{ inputs.title }}
96+
content-filepath: ${{ inputs.outputFile }}
97+
labels: ${{ inputs.labels }}
98+
99+
- name: Close if Check Passes
100+
uses: peter-evans/close-issue@v2.2.0
101+
if: >-
102+
success() &&
103+
steps.find-existing-comment.outputs.result
104+
with:
105+
issue-number: ${{ steps.find-existing-comment.outputs.result }}
106+
comment: The most recent link check passed!

.github/workflows/link-check-deployment-status.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ on:
1717
required: false
1818
description: "The file the link check report will be written to before publishing"
1919
default: "link-check-report.md"
20+
config:
21+
type: 'string'
22+
description: 'The path to the link-check config file'
23+
default: 'config/link-check/config.yml'
2024
jobs:
2125
run:
2226
name: Run
@@ -37,11 +41,10 @@ jobs:
3741
npx repo-link-check \
3842
${{ inputs.failsOnly && '-f' || '' }} \
3943
-d ${{ inputs.branch }} \
40-
-c config/link-check/config.yml \
44+
-c ${{ inputs.config }} \
4145
-r ${{ github.event.deployment.payload.web_url }} \
4246
>> ${{ inputs.outputFile }}
43-
4447
- name: Create or update comment
45-
run: cml send-comment --pr --update ${{ inputs.outputFile }}
48+
run: cml comment update --watermark-title="Link Check Report" ${{ inputs.outputFile }}
4649
env:
4750
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

config/link-check/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fileIncludePatterns:
2+
- ./test/*
3+

0 commit comments

Comments
 (0)