Skip to content

Commit 5f148ce

Browse files
committed
support checking of separate versions via env var
1 parent b4171bf commit 5f148ce

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

script/check-internal-links.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
const linkinator = require('linkinator')
44
const checker = new linkinator.LinkChecker()
5-
const { deprecated } = require('../lib/enterprise-server-releases')
5+
const { deprecated, latest } = require('../lib/enterprise-server-releases')
66
const englishRoot = 'http://localhost:4002/en'
77

88
// [start-readme]
99
//
10-
// This script runs in CI via GitHub Action to check all *internal* links in English content,
11-
// not including deprecated Enterprise Server content. This is different from script/check-english-links.js,
12-
// which checks *all* links in the site, both internal and external, and is much slower.
10+
// This script runs in CI via GitHub Action to check all *internal* links in English content for a
11+
// given version, not including deprecated Enterprise Server content. This is different from
12+
// script/check-english-links.js, which checks *all* links in the site, both internal and external,
13+
// and is much slower.
1314
//
1415
// If you want to run it locally, you must have a local server running. You can use `npm run link-check`.
1516
//
@@ -31,14 +32,34 @@ const config = {
3132
// Skip dist files
3233
'/dist/index.*',
3334
// Skip deprecated Enterprise content
34-
`enterprise(-server@|/)(${deprecated.join('|')})/?`
35+
`enterprise(-server@|/)(${deprecated.join('|')})(/|$)`
3536
]
3637
}
3738

39+
// Customize config for specific versions
40+
if (process.env.VERSION === 'dotcom') {
41+
// If Dotcom, skip Enterprise Server and GitHub AE links
42+
config.linksToSkip.push('^.*/enterprise-server@.*$', '^.*/enterprise/.*$', '^.*/github-ae@latest.*$')
43+
} else if (process.env.VERSION === 'enterprise-server') {
44+
// If Enterprise Server, skip links that are not Enterprise Server links
45+
config.path = `${englishRoot}/enterprise-server@${latest}`
46+
config.linksToSkip.push('^((?!enterprise-server@).)*$')
47+
}else if (process.env.VERSION === 'github-ae') {
48+
// If GitHub AE, skip links that are not GitHub AE links
49+
config.path = `${englishRoot}/github-ae@latest`
50+
config.linksToSkip.push('^((?!github-ae@latest).)*$')
51+
}
52+
3853
main()
3954

4055
async function main () {
56+
process.env.VERSION
57+
? console.log(`Checking internal links for version ${process.env.VERSION}!\n`)
58+
: console.log('Checking internal links for all versions!\n')
59+
60+
console.time('check')
4161
const result = (await checker.check(config)).links
62+
console.timeEnd('check')
4263

4364
const brokenLinks = result
4465
.filter(link => link.state === 'BROKEN')

0 commit comments

Comments
 (0)