Repository navigation
ci(website): fail the build when an advertised markdown copy is missing or names another page #20199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ci(website): fail the build when an advertised markdown copy is missing or names another page #20199
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0caa609
ci(website): fail the build when an advertised markdown copy is missi…
MaanilVerma ec36087
ci(website): check markdown copies on the release build too
MaanilVerma 6e54df6
refactor(website): share the dist HTML walk across build checks
MaanilVerma cbc26de
fix(website): close fail-open gaps in the markdown copy check
MaanilVerma cf3e007
refactor(website): keep the advertised-share floor module-private
MaanilVerma 4fe409d
fix(website): strip only a whole index.html segment from a built route
MaanilVerma e1bc91e
fix(website): count only real same-origin rel=alternate markdown links
MaanilVerma 4d797ae
Merge branch 'main' into maanil/fe-2984-markdown-twin-canonical
MaanilVerma 117d284
Merge remote-tracking branch 'origin/main' into merge-20199-tmp
MaanilVerma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import { beforeAll, afterAll, describe, expect, it } from 'vitest' | ||
|
|
||
| import { htmlFiles, isFileWithExactCase, routeOf } from './dist-html' | ||
|
|
||
| let root: string | ||
|
|
||
| beforeAll(async () => { | ||
| root = await mkdtemp(join(tmpdir(), 'dist-html-')) | ||
| await mkdir(join(root, 'zh-CN', 'about'), { recursive: true }) | ||
| await writeFile(join(root, 'index.html'), '') | ||
| await writeFile(join(root, 'searchindex.html'), '') | ||
| await writeFile(join(root, 'zh-CN', 'about', 'index.html'), '') | ||
| await writeFile(join(root, 'zh-CN', 'cli.md'), '') | ||
| }) | ||
|
|
||
| afterAll(() => rm(root, { recursive: true, force: true })) | ||
|
|
||
| describe('htmlFiles and routeOf', () => { | ||
| it('lists every built page as its route', () => { | ||
| expect( | ||
| htmlFiles(root) | ||
| .map((file) => routeOf(root, file)) | ||
| .sort() | ||
| ).toEqual(['/', '/searchindex.html', '/zh-CN/about/']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('isFileWithExactCase', () => { | ||
| it.for([ | ||
| { path: '/zh-CN/cli.md', exists: true }, | ||
| { path: '/zh-CN/CLI.md', exists: false }, | ||
| { path: '/ZH-cn/cli.md', exists: false }, | ||
| { path: '/zh-CN/missing.md', exists: false }, | ||
| { path: '/zh-CN', exists: false }, | ||
| { path: '/', exists: false } | ||
| ])('$path exists: $exists', ({ path, exists }) => { | ||
| expect(isFileWithExactCase(root, path)).toBe(exists) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { readdirSync } from 'node:fs' | ||
| import { join, relative, sep } from 'node:path' | ||
|
|
||
| /** Every `.html` file under `dir`, recursively. Throws when `dir` is missing. */ | ||
| export function htmlFiles(dir: string): string[] { | ||
| return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { | ||
| const full = join(dir, entry.name) | ||
| if (entry.isDirectory()) return htmlFiles(full) | ||
| return entry.name.endsWith('.html') ? [full] : [] | ||
| }) | ||
| } | ||
|
|
||
| /** `<root>/zh-CN/about/index.html` -> `/zh-CN/about/` */ | ||
| export function routeOf(root: string, file: string): string { | ||
| const rel = relative(root, file).split(sep).join('/') | ||
| const withoutIndex = rel.replace(/(^|\/)index\.html$/, '$1') | ||
| return `/${withoutIndex}`.replace(/\/{2,}/g, '/') | ||
| } | ||
|
|
||
| /** | ||
| * Whether `path` (`/zh-CN/cli.md`) names a file under `root` with this exact | ||
| * case. `existsSync` ignores case on macOS and Windows; the Linux CI and the | ||
| * CDN do not. | ||
| */ | ||
| export function isFileWithExactCase(root: string, path: string): boolean { | ||
| const segments = path.split('/').filter(Boolean) | ||
| return ( | ||
| segments.length > 0 && | ||
| segments.every((segment, index) => { | ||
| const entry = readdirSync(join(root, ...segments.slice(0, index)), { | ||
| withFileTypes: true | ||
| }).find(({ name }) => name === segment) | ||
| return index === segments.length - 1 | ||
| ? entry?.isFile() === true | ||
| : entry?.isDirectory() === true | ||
| }) | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * Fails when too few built pages advertise a markdown copy, or a page | ||
| * advertises one that was not built or whose front matter does not name that | ||
| * page as its canonical. | ||
| */ | ||
| import { existsSync, readFileSync } from 'node:fs' | ||
| import { join } from 'node:path' | ||
|
|
||
| import { | ||
| advertisementShortfall, | ||
| auditMarkdownAlternates | ||
| } from '@/utils/markdownAlternateAudit' | ||
|
|
||
| import { htmlFiles, isFileWithExactCase, routeOf } from './dist-html' | ||
|
|
||
| const DIST = join(process.cwd(), 'dist') | ||
| const ORIGIN = 'https://comfy.org' | ||
|
|
||
| function readTwin(path: string): string | undefined { | ||
| return isFileWithExactCase(DIST, path) | ||
| ? readFileSync(join(DIST, path), 'utf-8') | ||
| : undefined | ||
| } | ||
|
|
||
| if (!existsSync(DIST)) { | ||
| console.error(`[markdown-alternates] ${DIST} does not exist; build first.`) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const pages = htmlFiles(DIST).map((file) => ({ | ||
| route: routeOf(DIST, file), | ||
| html: readFileSync(file, 'utf-8') | ||
| })) | ||
| const { advertised, canonicalChecked, problems } = auditMarkdownAlternates( | ||
| pages, | ||
| readTwin, | ||
| ORIGIN | ||
| ) | ||
|
|
||
| const shortfall = advertisementShortfall(advertised, pages.length) | ||
| if (shortfall !== undefined) { | ||
| console.error(`[markdown-alternates] ${shortfall}`) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| if (problems.length > 0) { | ||
| console.error( | ||
| `[markdown-alternates] ${problems.length} of ${advertised} advertised markdown copies are broken:` | ||
| ) | ||
| for (const problem of problems) console.error(` ${problem}`) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| console.warn( | ||
| `[markdown-alternates] ${advertised} of ${pages.length} pages advertise a markdown copy, and every copy exists. ` + | ||
| `${canonicalChecked} name their page as canonical; ${advertised - canonicalChecked} pages emit no canonical to compare.` | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.