Skip to content

Commit e21cd24

Browse files
chore: Fix the html checker (#488)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it The current htmlcheck is not able to successfully scan links on the real website, so it produces quite a bunch of false positives. This PR adds the link check using [`linkinator`](https://github.com/JustinBeckwith/linkinator). Both together should now really guarantee that there are no broken links as we always scan the real website generated as deploy preview by Netlify. --------- Signed-off-by: Gerald Morrison (SAP) <[email protected]> Co-authored-by: Gerald Morrison (SAP) <[email protected]>
1 parent acefe72 commit e21cd24

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

.github/config/htmltest.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
DirectoryPath: ./public
55

66
# Checks to ignore
7+
CheckExternal: false
78
CheckInternalHash: false
89
CheckDoctype: false
910
IgnoreInternalEmptyHash: true
@@ -21,11 +22,6 @@ ExternalTimeout: 10
2122

2223
# URLs to ignore
2324
IgnoreURLs:
24-
# Skip all SAP legal pages (appears in footer, so on every page)
25-
- "^https://www\\.sap\\.com/.*/legal/.*"
2625
- "^mailto:"
27-
# Skip local pages from secure delivery demo
28-
- "^https?://(www\\.)?gitea\\.ocm\\.dev(/|$)"
29-
- "^https://.*\\.ocm\\.dev(/|$)"
30-
# Skip Google calendar entries
31-
- "^https://calendar\\.google\\.com(/|$)"
26+
# Skip OCM software pages because they are not yet live in a PR
27+
- "^https://ocm\\.software(/|$)"

.github/config/linkinator.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"concurrency": 20,
3+
"recurse": true,
4+
"verbosity": "warning",
5+
"timeout": 20000,
6+
"retry": true,
7+
"skip": ["https://www\\.sap\\.com/.*/legal/.*","^https?://(www\\.)?gitea\\.ocm\\.dev(/|$)","^https://.*\\.ocm\\.dev(/|$)","^https://calendar\\.google\\.com(/|$)","^https://github\\.com/open-component-model(/|$)"]
8+
}

.github/workflows/verify-html.yml

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow verifies that all links in the HTML files are valid.
2-
# GitHub repo: https://github.com/wjdp/htmltest
3-
41
name: Verify HTML Links
52

63
on:
@@ -10,14 +7,74 @@ on:
107

118
permissions:
129
contents: read
10+
checks: read
1311

1412
jobs:
1513
check-links:
16-
name: Check external and internal links
14+
name: Check external and internal links (Netlify Deploy Preview)
1715
runs-on: ubuntu-latest
1816
steps:
1917
- uses: actions/checkout@v4
2018

19+
- name: Wait for Netlify Deploy Preview
20+
id: wait_for_preview
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
echo "Waiting up to 10 minutes for Netlify deploy preview..."
25+
export REPO="${{ github.repository }}"
26+
export SHA="${{ github.event.pull_request.head.sha }}"
27+
28+
timeout 600 bash -c '
29+
while true; do
30+
# Get check suite for Netlify app
31+
SUITE_JSON=$(
32+
gh api repos/"$REPO"/commits/"$SHA"/check-suites \
33+
--jq "[ .check_suites[] | select(.app.slug == \"netlify\") ]" 2>/dev/null
34+
)
35+
36+
# no suite available? sleep and retry
37+
if [ "$(echo "$SUITE_JSON" | jq length)" -eq 0 ]; then
38+
sleep 5
39+
continue
40+
fi
41+
42+
# Read suite ID, status and conclusion
43+
SUITE_ID=$(echo "$SUITE_JSON" | jq -r ".[0].id")
44+
STATUS=$(echo "$SUITE_JSON" | jq -r ".[0].status")
45+
CONCLUSION=$(echo "$SUITE_JSON" | jq -r ".[0].conclusion")
46+
47+
echo "Netlify suite status: $STATUS, conclusion: $CONCLUSION"
48+
49+
if [ "$STATUS" = "completed" ]; then
50+
if [[ "$CONCLUSION" = "success" || "$CONCLUSION" = "neutral" ]]; then
51+
# Get deploy preview URL from status
52+
STATUS_JSON=$(gh api repos/"$REPO"/commits/"$SHA"/status \
53+
--jq ".statuses[] | select(.context==\"netlify/open-component-model/deploy-preview\")" 2>/dev/null
54+
)
55+
56+
PREVIEW_URL=$(echo "$STATUS_JSON" | jq -r '.target_url')
57+
58+
echo "✅ Deploy Preview ready: $PREVIEW_URL"
59+
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
60+
exit 0
61+
else
62+
echo "❌ Deploy failed: $CONCLUSION"
63+
exit 1
64+
fi
65+
fi
66+
67+
# still pending?
68+
sleep 15
69+
done
70+
'
71+
72+
# timeout returns 124 if command times out
73+
if [ $? -eq 124 ]; then
74+
echo "❌ Timeout after 10 minutes"
75+
exit 1
76+
fi
77+
2178
- name: Setup Node.js
2279
uses: actions/setup-node@v4
2380
with:
@@ -26,12 +83,20 @@ jobs:
2683
- name: Install Dependencies
2784
run: npm install
2885

29-
- name: Build Site
30-
run: npm run build
86+
- name: Build Site using Netlify Preview URL
87+
id: build_site
88+
run: |
89+
npm run build -- --baseURL="$PREVIEW_URL"
3190
3291
- name: Verify HTML links
33-
# Download binary to ./bin. Execute it with log level 1 (INFO) and config file
3492
run: |
3593
curl https://htmltest.wjdp.uk | bash
3694
chmod +x ./bin/htmltest
37-
./bin/htmltest -l 1 -c .github/config/htmltest.yml
95+
./bin/htmltest -l 1 -c .github/config/htmltest.yml
96+
97+
- name: Verify links with linkinator
98+
run: |
99+
npm install linkinator
100+
echo "Verifying links at ${{ steps.wait_for_preview.outputs.preview_url }}"
101+
npx linkinator "${{ steps.wait_for_preview.outputs.preview_url }}" --config .github/config/linkinator.json \
102+
&& echo "✅ Linkinator: No broken links found."

0 commit comments

Comments
 (0)