Skip to content

Commit e09843f

Browse files
authored
Merge branch 'main' into patch-3
2 parents 215d8dc + e72a394 commit e09843f

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ concurrency:
2222
cancel-in-progress: true
2323

2424
jobs:
25-
build:
25+
check-links:
2626
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
2727
steps:
2828
- name: Checkout
@@ -37,26 +37,15 @@ jobs:
3737
- name: Install
3838
run: npm ci
3939

40+
# Creates file "${{ env.HOME }}/files.json", among others
4041
- name: Gather files changed
4142
uses: trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b
42-
id: get_diff_files
43-
44-
# Necessary because trilom/file-changes-action can't escape each file
45-
# name for using in bash. So, we do it ourselves.
46-
# trilom/file-changes-action will, by default produce outputs
47-
# in JSON format. We consume that and set a new output where each
48-
# filename is wrapped in quotation marks.
49-
# Perhaps some day we can rely on this directly based on;
50-
# https://github.com/trilom/file-changes-action/issues/130
51-
- name: Escape each diff file name
52-
id: get_diff_files_escaped
53-
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
5443
with:
55-
github-token: ${{ secrets.DOCUBOT_READORG_REPO_WORKFLOW_SCOPES }}
56-
script: |
57-
const input = JSON.parse('${{ steps.get_diff_files.outputs.files }}')
58-
const files = input.map(filename => `"${filename}"`)
59-
core.setOutput('files', files.join(' '))
44+
fileOutput: 'json'
45+
46+
# For verification
47+
- name: Show files changed
48+
run: cat $HOME/files.json
6049

6150
- name: Link check (warnings, changed files)
6251
run: |
@@ -66,7 +55,7 @@ jobs:
6655
--check-anchors \
6756
--check-images \
6857
--verbose \
69-
${{ steps.get_diff_files_escaped.outputs.files }}
58+
--list $HOME/files.json
7059
7160
- name: Link check (critical, all files)
7261
run: |

script/rendered-content-link-checker.mjs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { languageKeys } from '../lib/languages.js'
1919
import warmServer from '../lib/warm-server.js'
2020
import renderContent from '../lib/render-content/index.js'
2121
import { deprecated } from '../lib/enterprise-server-releases.js'
22+
import readFileAsync from '../lib/readfile-async.js'
2223

2324
const STATIC_PREFIXES = {
2425
assets: path.resolve('assets'),
@@ -65,13 +66,33 @@ program
6566
}
6667
return parsed
6768
})
69+
.option(
70+
'--list <file>.json',
71+
'JSON file containing an array of specific files to check (default: none)',
72+
(filePath) => {
73+
const resolvedPath = path.resolve(filePath)
74+
75+
let stats
76+
try {
77+
stats = fs.statSync(resolvedPath)
78+
} catch (error) {
79+
// Ignore
80+
}
81+
82+
if (!stats || !stats.isFile()) {
83+
throw new InvalidArgumentError('Not an existing file.')
84+
}
85+
86+
return resolvedPath
87+
}
88+
)
6889
.arguments('[files...]', 'Specific files to check')
6990
.parse(process.argv)
7091

7192
main(program.opts(), program.args)
7293

7394
async function main(opts, files) {
74-
const { random, language, filter, exit, debug, max, verbose } = opts
95+
const { random, language, filter, exit, debug, max, verbose, list } = opts
7596

7697
// Note! The reason we're using `warmServer()` in this script,
7798
// even though there's no server involved, is because
@@ -89,6 +110,19 @@ async function main(opts, files) {
89110
const filters = filter || []
90111
console.assert(Array.isArray(filters), `${filters} is not an array`)
91112

113+
if (list && Array.isArray(files) && files.length > 0) {
114+
throw new InvalidArgumentError('Cannot specify both --list and a file list.')
115+
}
116+
117+
if (list) {
118+
const fileList = JSON.parse(await readFileAsync(list))
119+
if (Array.isArray(fileList) && fileList.length > 0) {
120+
files = fileList
121+
} else {
122+
throw new InvalidArgumentError('No files found in --list.')
123+
}
124+
}
125+
92126
if (random) {
93127
shuffle(pageList)
94128
}

0 commit comments

Comments
 (0)