Skip to content

Commit 8bb5251

Browse files
authored
fix(link-check): add WAF token to avoid 403 (#26964)
1 parent dabaee7 commit 8bb5251

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

.github/workflows/check-broken-links-github-github.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
run: npm ci
5252

5353
- name: Run broken github/github link check
54+
env:
55+
WAF_TOKEN: ${{ secrets.WAF_TOKEN }}
5456
run: |
5557
script/check-github-github-links.js > broken_github_github_links.md
5658

script/check-github-github-links.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if (!process.env.GITHUB_TOKEN) {
1414
process.exit(1)
1515
}
1616

17+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
18+
1719
main()
1820

1921
async function main() {
@@ -91,16 +93,23 @@ async function main() {
9193
}
9294
}
9395
}
96+
9497
const brokenLinks = []
95-
await Promise.all(
96-
docsLinksFiles.map(async (file) => {
97-
try {
98-
await got(file[0])
99-
} catch {
100-
brokenLinks.push(file)
101-
}
102-
})
103-
)
98+
// Done serially with delay to avoid hitting the rate limiter
99+
for (const file of docsLinksFiles) {
100+
try {
101+
await got(file[0], {
102+
headers: {
103+
'X-WAF-TOKEN': process.env.WAF_TOKEN,
104+
},
105+
})
106+
} catch (e) {
107+
brokenLinks.push(file)
108+
} finally {
109+
await sleep(300)
110+
}
111+
}
112+
104113
if (!brokenLinks.length) {
105114
console.log('All links are good!')
106115
process.exit(0)

0 commit comments

Comments
 (0)