Skip to content

Commit 75e8f1f

Browse files
author
Peter Bengtsson
authored
more patient in nightly link checker (github#32019)
1 parent c0859e5 commit 75e8f1f

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

.github/actions/lib/get-env-inputs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ export function getEnvInputs(options) {
1616
})
1717
)
1818
}
19+
20+
/*
21+
* Given an environment variable key, return `true` or `false` if the
22+
* value is recognizable.
23+
* Turn 'true' or '1' into `true`. And '', '0', or 'false' into `false`.
24+
* All other values are invalid.
25+
* Now you can't accidentally set `export FOO=falsee` which as string `'falsee'`
26+
* could have been interpreted as a truthy value.
27+
*
28+
* @param {string} key - name of the environment variable
29+
*
30+
* @returns {boolean}
31+
*/
32+
export function boolEnvVar(key) {
33+
const value = process.env[key] || ''
34+
if (value === '' || value === 'false' || value === '0') return false
35+
if (value === 'true' || value === '1') return true
36+
throw new Error(`Invalid value for set environment variable ${key}: '${value}'`)
37+
}

.github/actions/rendered-content-link-checker.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import warmServer from '../../lib/warm-server.js'
1414
import renderContent from '../../lib/render-content/index.js'
1515
import { deprecated } from '../../lib/enterprise-server-releases.js'
1616
import excludedLinks from '../../lib/excluded-links.js'
17-
import { getEnvInputs } from './lib/get-env-inputs.js'
17+
import { getEnvInputs, boolEnvVar } from './lib/get-env-inputs.js'
1818
import { debugTimeEnd, debugTimeStart } from './lib/debug-time-taken.js'
1919
import { uploadArtifact as uploadArtifactLib } from './lib/upload-artifact.js'
2020
import github from '../../script/helpers/github.js'
@@ -52,19 +52,8 @@ const deprecatedVersionPrefixesRegex = new RegExp(
5252
// When this file is invoked directly from action as opposed to being imported
5353
if (import.meta.url.endsWith(process.argv[1])) {
5454
// Optional env vars
55-
const {
56-
ACTION_RUN_URL,
57-
CREATE_REPORT,
58-
CHECK_EXTERNAL_LINKS,
59-
LEVEL,
60-
SHOULD_COMMENT,
61-
COMMENT_LIMIT_TO_EXTERNAL_LINKS,
62-
FAIL_ON_FLAW,
63-
FILES_CHANGED,
64-
REPORT_REPOSITORY,
65-
REPORT_AUTHOR,
66-
REPORT_LABEL,
67-
} = process.env
55+
const { ACTION_RUN_URL, LEVEL, FILES_CHANGED, REPORT_REPOSITORY, REPORT_AUTHOR, REPORT_LABEL } =
56+
process.env
6857

6958
const octokit = github()
7059

@@ -86,15 +75,15 @@ if (import.meta.url.endsWith(process.argv[1])) {
8675
verbose: true,
8776
linkReports: true,
8877
checkImages: true,
89-
patient: true,
78+
patient: boolEnvVar('PATIENT'),
9079
random: false,
9180
language: 'en',
9281
actionUrl: ACTION_RUN_URL,
93-
checkExternalLinks: CHECK_EXTERNAL_LINKS === 'true',
94-
shouldComment: Boolean(JSON.parse(SHOULD_COMMENT)),
95-
commentLimitToExternalLinks: COMMENT_LIMIT_TO_EXTERNAL_LINKS === 'true',
96-
failOnFlaw: FAIL_ON_FLAW === 'true',
97-
createReport: CREATE_REPORT === 'true',
82+
checkExternalLinks: boolEnvVar('CHECK_EXTERNAL_LINKS'),
83+
shouldComment: boolEnvVar('SHOULD_COMMENT'),
84+
commentLimitToExternalLinks: boolEnvVar('COMMENT_LIMIT_TO_EXTERNAL_LINKS'),
85+
failOnFlaw: boolEnvVar('FAIL_ON_FLAW'),
86+
createReport: boolEnvVar('CREATE_REPORT'),
9887
reportRepository: REPORT_REPOSITORY,
9988
reportLabel: REPORT_LABEL,
10089
reportAuthor: REPORT_AUTHOR,
@@ -839,7 +828,7 @@ async function innerFetch(core, url, config = {}) {
839828
// So there's no point in trying more attempts than 3 because it would
840829
// just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000)
841830
const retry = {
842-
limit: patient ? 5 : 2,
831+
limit: patient ? 6 : 2,
843832
}
844833
const timeout = { request: patient ? 10000 : 2000 }
845834

.github/workflows/link-check-daily.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
REPORT_REPOSITORY: github/docs-content
4646
CREATE_REPORT: true
4747
CHECK_EXTERNAL_LINKS: true
48+
PATIENT: true
4849
timeout-minutes: 30
4950
run: node .github/actions/rendered-content-link-checker.js
5051

0 commit comments

Comments
 (0)