7
7
inputs :
8
8
url :
9
9
description : ' Site to check for broken links'
10
- required : true
11
10
type : string
12
- default : ' https://docs.platform.sh/ '
11
+ default : ' '
13
12
14
13
jobs :
14
+ determine-urls :
15
+ name : determine which urls to use
16
+ runs-on : ubuntu-latest
17
+ outputs :
18
+ urls : ${{ steps.determine-url.outputs.urls }}
19
+ steps :
20
+ - id : determine-url
21
+ run : |
22
+ # default URLs we want to check
23
+ # todo: replace this with a vars.VAL ?
24
+ urls="[\"https://docs.platform.sh\",\"https://docs.upsun.com\"]"
25
+ if [ "workflow_dispatch" = "${{ github.event_name }}" ]; then
26
+ # make sure there's no extra spaces in what we were given
27
+ inputURL=$(echo "${{ inputs.url }}" | xargs)
28
+ if [ -n "${inputURL}" ]; then
29
+ urls="[\"${inputURL}\"]"
30
+ fi
31
+ fi
32
+ echo "urls=${urls}" >> $GITHUB_OUTPUT
15
33
check-links :
16
34
name : Check links
17
35
runs-on : ubuntu-latest
36
+ strategy :
37
+ matrix :
38
+ url : ${{ fromJSON(needs.determine-urls.outputs.urls) }}
39
+ needs :
40
+ - determine-urls
18
41
steps :
19
42
- uses : actions/setup-python@v4
20
43
with :
@@ -26,38 +49,29 @@ jobs:
26
49
pip3 install linkchecker
27
50
28
51
- name : checkout xml to markdown
29
- uses : actions/checkout@v3
52
+ uses : actions/checkout@v4
30
53
with :
31
54
repository : platformsh/linkchecker-xml2md
32
55
56
+ - name : checkout linkchecker config
57
+ uses : actions/checkout@v4
58
+ with :
59
+ sparse-checkout : |
60
+ linkcheckerrc
61
+ sparse-checkout-cone-mode : false
62
+ path : linkchecker
33
63
- name : install-parser
34
64
run : |
35
65
pip3 install -r requirements.txt
36
66
37
- - name : Set URL to scan
38
- id : set-url
39
- shell : bash
40
- run : |
41
- # If this is a workflow dispatch, then use what was entered.
42
- # If not, then use the repository variable SCAN_URL if it is set
43
- # if not, fall back to the hard-coded default
44
- scanURL="https://docs.platform.sh/"
45
- if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
46
- scanURL="${{ inputs.url }}"
47
- elif [[ -n "${{ vars.SCAN_URL }}" ]]; then
48
- scanURL="${{ vars.SCAN_URL }}"
49
- fi
50
-
51
- echo "scanURL=${scanURL}" >> "$GITHUB_ENV"
52
-
53
67
- name : Run linkchecker
54
68
id : run-link-checker
55
69
continue-on-error : true
56
70
shell : bash
57
71
run : |
58
- echo "::notice::Scanning ${{ inputs .url }} for broken links."
72
+ echo "::notice::Scanning ${{ matrix .url }} for broken links."
59
73
# if linkchecker exits with a non-zero then it means broken links were found.
60
- scan=$(linkchecker ${{ env.scanURL }} -F xml/utf_8/brokenlinks.xml --check-extern --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" --ignore-url="^https://github.com/platformsh*" --ignore-url="console.platform.sh/projects/*" --ignore-url="support.blackfire.io/*" --ignore-url="cloud.orange-business.com/*" --ignore-url="developers.cloudflare.com/*" --ignore-url="discord.com/*" --ignore-url="pptr.dev/*" --ignore-url="mvnrepository.com/*" --ignore-url="https://dev.mysql.com/doc/refman/en/" --ignore-url="https://www.microsoft.com/en-us/trust-center/privacy/data-management" )
74
+ scan=$(linkchecker ${{ matrix.url }} -f ./linkchecker/linkcheckerrc -F xml/utf_8/brokenlinks.xml )
61
75
result=$?
62
76
if [[ $result -ne 0 ]]; then
63
77
echo "::notice::Broken links detected."
@@ -74,14 +88,21 @@ jobs:
74
88
run : |
75
89
echo "::notice::No broken links were detected"
76
90
91
+ - name : get domain name
92
+ if : ${{ steps.run-link-checker.outcome == 'failure' }}
93
+ id : get-domain-name
94
+ run : |
95
+ domainName=$(basename ${{ matrix.url }})
96
+ echo "domain=${domainName}" >> $GITHUB_OUTPUT
77
97
- name : check message size
78
98
id : check-msg-size
79
99
if : ${{ steps.run-link-checker.outcome == 'failure' }}
80
100
run : |
81
101
artifact="false"
82
102
sizeOfMessage=$(cat broken_links.md | wc -c)
103
+ echo "::notice::Size of report: ${sizeOfMessage}"
83
104
# the size of a comment in an issue is 65536
84
- if [ "${sizeOfMessage}" -gt 650000 ]; then
105
+ if [ "${sizeOfMessage}" -gt 65000 ]; then
85
106
# we'll need to store the broken_links.md file as an aritifact
86
107
artifact="true"
87
108
fi
@@ -93,26 +114,27 @@ jobs:
93
114
if : ${{ steps.run-link-checker.outcome == 'failure' && env.artifact == 'true' }}
94
115
uses : actions/upload-artifact@v4
95
116
with :
96
- name : broken-links
117
+ name : broken-links-${{ steps.get-domain-name.outputs.domain }}
97
118
path : |
98
- ${{ github.action_path }} /broken_links.md
119
+ . /broken_links.md
99
120
100
121
- name : Create issue
101
122
id : create-issue
102
123
if : ${{ steps.run-link-checker.outcome == 'failure' }}
103
124
env :
104
125
ARTIFACT : ${{ env.artifact }}
126
+ DOMAIN : ${{ steps.get-domain-name.outputs.domain }}
105
127
uses : actions/github-script@v6
106
128
with :
107
129
script : |
108
- const { ARTIFACT } = process.env
130
+ const { ARTIFACT, DOMAIN } = process.env
109
131
var fs = require('fs');
110
132
//
111
- failMsg = ':bug: Broken links detected'
133
+ failMsg = ':bug: Broken links detected on ' + DOMAIN
112
134
113
135
if ('true' == ARTIFACT) {
114
136
address = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}#artifacts`
115
- var bodyMsg = `Visual Regression Testing failed . Please view the report artifact at ${address}`
137
+ var bodyMsg = `Broken links found . Please view the report artifact at ${address}`
116
138
} else {
117
139
var bodyMsg = fs.readFileSync('broken_links.md','utf8');
118
140
}
0 commit comments