Skip to content

Commit

Permalink
run link checker against localhost:4000 instead of prod (#27757)
Browse files Browse the repository at this point in the history
* run link checker against localhost:4000 instead of prod

* exclude docs.github.com

* print output if possible

* upload broken_links.md as artifact

* debug broken_links.md
  • Loading branch information
peterbe committed May 19, 2022
1 parent 3c5a4ea commit d5cef9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
32 changes: 29 additions & 3 deletions .github/workflows/check-all-english-links.yml
Expand Up @@ -32,15 +32,32 @@ jobs:
with:
node-version: 16.14.x
cache: npm
- name: npm ci

- name: Install dependencies
run: npm ci

- name: Cache nextjs build
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09
with:
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}
- name: npm run build

- name: Build server
run: npm run build

- name: Start server in the background
env:
NODE_ENV: production
PORT: 4000
DISABLE_OVERLOAD_PROTECTION: true
DISABLE_RENDER_CACHING: true
# We don't want or need the changelog entries in this context.
CHANGELOG_DISABLED: true
run: |
node server.mjs &
sleep 5
curl --retry-connrefused --retry 3 -I http://localhost:4000/
- name: Run script
run: |
script/check-english-links.js > broken_links.md
Expand All @@ -53,6 +70,16 @@ jobs:
#
# https://docs.github.com/actions/reference/context-and-expression-syntax-for-github-actions#job-status-check-functions

- if: ${{ failure() }}
name: Debug broken_links.md
run: |
ls -lh broken_links.md
wc -l broken_links.md
- uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
if: ${{ failure() }}
with:
name: broken_links
path: ./broken_links.md
- if: ${{ failure() }}
name: Get title for issue
id: check
Expand All @@ -63,7 +90,6 @@ jobs:
uses: peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77e
with:
token: ${{ env.GITHUB_TOKEN }}

title: ${{ steps.check.outputs.title }}
content-filepath: ./broken_links.md
repository: ${{ env.REPORT_REPOSITORY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/check-broken-links-github-github.yml
Expand Up @@ -57,6 +57,8 @@ jobs:
env:
NODE_ENV: production
PORT: 4000
DISABLE_OVERLOAD_PROTECTION: true
DISABLE_RENDER_CACHING: true
run: |
node server.mjs &
Expand Down
10 changes: 8 additions & 2 deletions script/check-english-links.js
Expand Up @@ -25,7 +25,7 @@ import libLanguages from '../lib/languages.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const checker = new LinkChecker()
const root = 'https://docs.github.com'
const root = 'http://localhost:4000'
const englishRoot = `${root}/en`

// Links with these codes may or may not really be broken.
Expand Down Expand Up @@ -66,7 +66,13 @@ const config = {
recurse: !program.opts().dryRun,
silent: true,
// The values in this array are treated as regexes.
linksToSkip: linksToSkipFactory([enterpriseReleasesToSkip, ...languagesToSkip, ...excludedLinks]),
linksToSkip: linksToSkipFactory([
enterpriseReleasesToSkip,
...languagesToSkip,
...excludedLinks,
// Don't leak into the production site
/https:\/\/docs\.github\.com/,
]),
}

// Return a function that can as quickly as possible check if a certain
Expand Down

0 comments on commit d5cef9c

Please sign in to comment.