Skip to content

Commit ac18d53

Browse files
Merge pull request #278 from sei-protocol/checks/enforce-links-check
Enforce link checks per PR
2 parents 62dd304 + 43b31c2 commit ac18d53

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.github/workflows/link_checker.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Link checker
22

33
on:
4+
pull_request:
45
workflow_dispatch:
56
schedule:
67
- cron: '0 12 * * *'
@@ -27,8 +28,20 @@ jobs:
2728

2829
- name: Run crawler
2930
id: crawler
30-
run: yarn tsx scripts/checkLinks.ts
3131
continue-on-error: true
32+
run: |
33+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
34+
echo "Running PR workflow: Building and starting local server..."
35+
yarn build
36+
sleep 5
37+
yarn start &
38+
sleep 15
39+
export BASE_URL="http://localhost:3000"
40+
else
41+
export BASE_URL="https://www.docs.sei.io/"
42+
fi
43+
echo "Running link checker for ${BASE_URL}"
44+
yarn tsx scripts/checkLinks.ts
3245
3346
- name: Upload broken links artifact
3447
if: steps.crawler.outcome == 'failure'

scripts/checkLinks.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const visitedLinks = new Set<string>();
77

88
async function main() {
99
const browserInstance = await chromium.launch();
10-
const baseUrl = 'https://www.docs.sei.io/';
10+
const baseUrl = process.env.BASE_URL || 'https://www.docs.sei.io/';
1111
await crawlPages(baseUrl, browserInstance, 'main');
12-
1312
fs.writeFileSync('brokenLinks.json', JSON.stringify([...brokenLinks], null, 2));
1413

1514
if (brokenLinks.size > 0) {
@@ -31,7 +30,7 @@ async function crawlPages(url: string, browser: Browser, path: string) {
3130
}
3231

3332
function isInternal(url: string) {
34-
return url.includes('docs.sei');
33+
return url.includes('docs.sei') || url.includes('localhost:3000');
3534
}
3635

3736
async function checkInternalLinks(url: string, page: Page, path: string, browser: Browser) {
@@ -58,7 +57,7 @@ async function checkExternalLinks(url: string, page: Page, path: string, browser
5857

5958
async function isLinkBroken(page: Page, url: string, path: string) {
6059
if (visitedLinks.has(url)) return false;
61-
if (url.includes('localhost') || url.includes('.tar.gz')) return false;
60+
if ((url.includes('localhost') && !url.includes(':3000')) || url.includes('.tar.gz')) return false;
6261

6362
let pageResponse: Response;
6463
try {

0 commit comments

Comments
 (0)