-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
99 lines (92 loc) · 2.91 KB
/
action.yaml
File metadata and controls
99 lines (92 loc) · 2.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Check links
description: Check the links of the provided site and upload a helpful CSV of results.
author: 'DAKLabb'
inputs:
url:
description: The url of the site to check.
required: true
site-name:
description: The name of the site being checked.
required: false
default: ''
report-name:
required: false
default: Report
check-external:
description: Whether to check external links.
required: false
default: 'false'
include-warnings:
description: Whether to include warnings.
required: false
default: 'true'
debug-config:
description: Set to true to log the contents of the linkchecker config.
required: false
default: 'false'
runs:
using: "composite"
steps:
- name: Confirm site is accessible
shell: bash
run: |
set +e
wget --server-response -q --delete-after ${{ inputs.url }}
if [ $? -ne 0 ]; then
echo "::error::URL: ${{ inputs.url }} not accessible."
exit 1
fi
- name: Install link checker
shell: bash
run: pip install linkchecker
- name: Setup config file
shell: bash
run: echo -e "[csv]\nseparator=,\n[output]\nstatus=0" > lcconfig
- name: Configure warnings
if: inputs.include-warnings == 'false'
shell: bash
run: echo "warnings=0" >> lcconfig
- name: Configure external checks
if: inputs.check-external == 'true'
shell: bash
run: echo -e "[filtering]\ncheckextern=1" >> lcconfig
- name: Log config for testing
if: inputs.debug-config == 'true'
shell: bash
run: cat lcconfig
- name: Check ${{ inputs.site-name }} Links
shell: bash
id: check
run: |
set +e
linkchecker https://${{ inputs.url }} --config lcconfig -F csv/utf-8/link_report.csv
if [ $? -ne 0 ]; then
echo "The link check failed, there should be a report"
echo "report-generated=true" >> $GITHUB_OUTPUT
fi
echo "Scan done, generating summary"
started=false
while read p; do
let "ln++"
# skip comments (top and bottom)
if [[ $p == \#* ]]; then
continue
fi
# make sure first line after comments is skipped
if [[ "$started" = false ]]; then
started=true
continue
fi
IFS=',' read -r -a array <<< "$p"
if [[ ${array[10]} == '' ]]; then
echo "::error::URL: ${array[0]} on page:${array[1]} is returning a ${array[3]}"
else
echo "::error::URL: ${array[0]} linked from '${array[10]}' on page:${array[1]} is returning a ${array[3]}"
fi
done < link_report.csv
- name: Upload report
if: always() && steps.check.outputs.report-generated == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.report-name }}
path: link_report.csv