Skip to content

Commit 34b4908

Browse files
authored
Add ignore-not-found option for feature-flagged docs URLs (#56273)
1 parent fc8500c commit 34b4908

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.github/workflows/validate-github-github-docs-urls.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
# do other things in other steps.
5151
npm run validate-github-github-docs-urls -- validate \
5252
--output checks.json \
53+
--ignore-not-found \
5354
github/config/docs-urls.json
5455
5556
- name: Update config/docs-urls.json in github/github (possibly)

src/links/scripts/validate-github-github-docs-urls/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ program
1313
.description('Validate config/docs-urls.json in github/github')
1414
.option('--fail-on-warning', 'Any warning will make the process exit with a non-zero code')
1515
.option('--fail-on-error', 'Any error will make the process exit with a non-zero code')
16+
.option(
17+
'--ignore-not-found',
18+
'Do not fail validation on 404 errors (pages not found) - useful for feature-flagged content',
19+
)
1620
.option('-o, --output <output-file>', 'Output file')
1721
.argument('<docs-urls-json-filepath>', 'path to the docs-urls JSON file')
1822
.action(validate)

src/links/scripts/validate-github-github-docs-urls/validate.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Options = {
77
failOnWarning?: boolean
88
failOnError?: boolean
99
output?: string
10+
ignoreNotFound?: boolean
1011
}
1112

1213
export async function validate(filePath: string, options: Options) {
@@ -26,8 +27,13 @@ export async function validate(filePath: string, options: Options) {
2627
console.log(prefix, `✅ ${check.url} (${check.identifier})`)
2728
}
2829
} else {
29-
if (options.failOnError) exitCode++
30-
console.log(prefix, `❌ ${check.url} (${check.identifier})`)
30+
// This is a 404 - page not found
31+
if (options.ignoreNotFound) {
32+
console.log(prefix, `⚠️ ${check.url} (${check.identifier})`)
33+
} else {
34+
if (options.failOnError) exitCode++
35+
console.log(prefix, `❌ ${check.url} (${check.identifier})`)
36+
}
3137
}
3238
if (check.fragment) {
3339
if (check.fragmentFound) {
@@ -58,7 +64,16 @@ export async function validate(filePath: string, options: Options) {
5864
chalk.yellow(T('Redirects')),
5965
checks.filter((check) => check.found && check.redirect).length,
6066
)
61-
console.log(chalk.red(T('Failures')), checks.filter((check) => !check.found).length)
67+
const notFoundChecks = checks.filter((check) => !check.found)
68+
69+
if (options.ignoreNotFound) {
70+
console.log(chalk.red(T('Failures')), 0)
71+
if (notFoundChecks.length > 0) {
72+
console.log(chalk.yellow(T('Ignored (404s)')), notFoundChecks.length)
73+
}
74+
} else {
75+
console.log(chalk.red(T('Failures')), notFoundChecks.length)
76+
}
6277
console.log(
6378
chalk.red(T('Failing fragments')),
6479
checks.filter((check) => check.found && check.fragment && !check.fragmentFound).length,

0 commit comments

Comments
 (0)