diff --git a/.github/actions/lib/get-env-inputs.js b/.github/actions/lib/get-env-inputs.js index 42aa5119fb..df1558d8fc 100644 --- a/.github/actions/lib/get-env-inputs.js +++ b/.github/actions/lib/get-env-inputs.js @@ -16,3 +16,22 @@ export function getEnvInputs(options) { }) ) } + +/* + * Given an environment variable key, return `true` or `false` if the + * value is recognizable. + * Turn 'true' or '1' into `true`. And '', '0', or 'false' into `false`. + * All other values are invalid. + * Now you can't accidentally set `export FOO=falsee` which as string `'falsee'` + * could have been interpreted as a truthy value. + * + * @param {string} key - name of the environment variable + * + * @returns {boolean} + */ +export function boolEnvVar(key) { + const value = process.env[key] || '' + if (value === '' || value === 'false' || value === '0') return false + if (value === 'true' || value === '1') return true + throw new Error(`Invalid value for set environment variable ${key}: '${value}'`) +} diff --git a/.github/actions/rendered-content-link-checker.js b/.github/actions/rendered-content-link-checker.js index f60324e8b5..8bf8cbddd8 100755 --- a/.github/actions/rendered-content-link-checker.js +++ b/.github/actions/rendered-content-link-checker.js @@ -14,7 +14,7 @@ import warmServer from '../../lib/warm-server.js' import renderContent from '../../lib/render-content/index.js' import { deprecated } from '../../lib/enterprise-server-releases.js' import excludedLinks from '../../lib/excluded-links.js' -import { getEnvInputs } from './lib/get-env-inputs.js' +import { getEnvInputs, boolEnvVar } from './lib/get-env-inputs.js' import { debugTimeEnd, debugTimeStart } from './lib/debug-time-taken.js' import { uploadArtifact as uploadArtifactLib } from './lib/upload-artifact.js' import github from '../../script/helpers/github.js' @@ -52,19 +52,8 @@ const deprecatedVersionPrefixesRegex = new RegExp( // When this file is invoked directly from action as opposed to being imported if (import.meta.url.endsWith(process.argv[1])) { // Optional env vars - const { - ACTION_RUN_URL, - CREATE_REPORT, - CHECK_EXTERNAL_LINKS, - LEVEL, - SHOULD_COMMENT, - COMMENT_LIMIT_TO_EXTERNAL_LINKS, - FAIL_ON_FLAW, - FILES_CHANGED, - REPORT_REPOSITORY, - REPORT_AUTHOR, - REPORT_LABEL, - } = process.env + const { ACTION_RUN_URL, LEVEL, FILES_CHANGED, REPORT_REPOSITORY, REPORT_AUTHOR, REPORT_LABEL } = + process.env const octokit = github() @@ -86,15 +75,15 @@ if (import.meta.url.endsWith(process.argv[1])) { verbose: true, linkReports: true, checkImages: true, - patient: true, + patient: boolEnvVar('PATIENT'), random: false, language: 'en', actionUrl: ACTION_RUN_URL, - checkExternalLinks: CHECK_EXTERNAL_LINKS === 'true', - shouldComment: Boolean(JSON.parse(SHOULD_COMMENT)), - commentLimitToExternalLinks: COMMENT_LIMIT_TO_EXTERNAL_LINKS === 'true', - failOnFlaw: FAIL_ON_FLAW === 'true', - createReport: CREATE_REPORT === 'true', + checkExternalLinks: boolEnvVar('CHECK_EXTERNAL_LINKS'), + shouldComment: boolEnvVar('SHOULD_COMMENT'), + commentLimitToExternalLinks: boolEnvVar('COMMENT_LIMIT_TO_EXTERNAL_LINKS'), + failOnFlaw: boolEnvVar('FAIL_ON_FLAW'), + createReport: boolEnvVar('CREATE_REPORT'), reportRepository: REPORT_REPOSITORY, reportLabel: REPORT_LABEL, reportAuthor: REPORT_AUTHOR, @@ -839,7 +828,7 @@ async function innerFetch(core, url, config = {}) { // So there's no point in trying more attempts than 3 because it would // just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000) const retry = { - limit: patient ? 5 : 2, + limit: patient ? 6 : 2, } const timeout = { request: patient ? 10000 : 2000 } diff --git a/.github/workflows/link-check-daily.yml b/.github/workflows/link-check-daily.yml index 846e0a5c78..6e522c96e8 100644 --- a/.github/workflows/link-check-daily.yml +++ b/.github/workflows/link-check-daily.yml @@ -45,6 +45,7 @@ jobs: REPORT_REPOSITORY: github/docs-content CREATE_REPORT: true CHECK_EXTERNAL_LINKS: true + PATIENT: true timeout-minutes: 30 run: node .github/actions/rendered-content-link-checker.js