-
Notifications
You must be signed in to change notification settings - Fork 0
[] Add CI pipeline for docs site: static build, dead-link check, frontmatter validation, Pagefind index #261
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e22073e
chore: Add CI pipeline for docs site: static build, dead-link check, …
364a232
Merge branch 'main' into feature/019f0d7d8817-019f0d7d8817
red-codens[bot] 9645993
chore: Add CI pipeline for docs site: static build, dead-link check, …
aa2e0f9
Merge remote-tracking branch 'origin/main' into pr261
zoetaka38 22a356b
Merge remote-tracking branch 'origin/main' into pr261
zoetaka38 4579c11
ci(docs): reconcile docs CI job to be green on current main
zoetaka38 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import fs from "fs"; | ||
| import os from "os"; | ||
| import path from "path"; | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { | ||
| validateFrontmatter, | ||
| validateFrontmatterOrThrow, | ||
| } from "../../scripts/validate-frontmatter"; | ||
|
|
||
| const tempDirs: string[] = []; | ||
|
|
||
| function createTempPagesDir(): string { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mdx-frontmatter-")); | ||
| tempDirs.push(dir); | ||
| return dir; | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| for (const dir of tempDirs.splice(0)) { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| describe("validateFrontmatter", () => { | ||
| it("returns an error when title is missing", () => { | ||
| const pagesDir = createTempPagesDir(); | ||
| fs.writeFileSync( | ||
| path.join(pagesDir, "missing-title.mdx"), | ||
| "---\ndescription: test\n---\n# Hello", | ||
| ); | ||
|
|
||
| const result = validateFrontmatter(pagesDir); | ||
|
|
||
| expect(result.errors).toHaveLength(1); | ||
| expect(result.errors[0]?.message).toMatch(/title/i); | ||
| expect(() => validateFrontmatterOrThrow(pagesDir)).toThrow(/title/i); | ||
| }); | ||
|
|
||
| it("succeeds when title is present", () => { | ||
| const pagesDir = createTempPagesDir(); | ||
| fs.writeFileSync( | ||
| path.join(pagesDir, "valid.mdx"), | ||
| "---\ntitle: Hello World\n---\n# Hello", | ||
| ); | ||
|
|
||
| const result = validateFrontmatter(pagesDir); | ||
|
|
||
| expect(result.errors).toHaveLength(0); | ||
| expect(result.successCount).toBe(1); | ||
| expect(validateFrontmatterOrThrow(pagesDir).successCount).toBe(1); | ||
| }); | ||
|
|
||
| it("flags draft pages in production mode", () => { | ||
| const pagesDir = createTempPagesDir(); | ||
| fs.writeFileSync( | ||
| path.join(pagesDir, "draft.mdx"), | ||
| "---\ntitle: Draft Page\ndraft: true\n---\n# Draft", | ||
| ); | ||
|
|
||
| const devResult = validateFrontmatter(pagesDir, { production: false }); | ||
| const prodResult = validateFrontmatter(pagesDir, { production: true }); | ||
|
|
||
| expect(devResult.errors).toHaveLength(0); | ||
| expect(devResult.successCount).toBe(1); | ||
| expect(prodResult.errors).toHaveLength(1); | ||
| expect(prodResult.errors[0]?.message).toMatch(/draft/i); | ||
| expect(() => | ||
| validateFrontmatterOrThrow(pagesDir, { production: true }), | ||
| ).toThrow(/draft/i); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import { useConfig } from 'nextra-theme-docs'; | ||
|
|
||
| type EditPageLinkProps = { | ||
| filePath: string; | ||
| }; | ||
|
|
||
| const DOCS_REPOSITORY_BASE = | ||
| 'https://github.com/Corevice/open-git/blob/main/docs'; | ||
|
|
||
| export function EditPageLink({ filePath }: EditPageLinkProps) { | ||
| const { docsRepositoryBase } = useConfig(); | ||
| const href = `${docsRepositoryBase}/tree/main/${filePath}`; | ||
| const href = `${DOCS_REPOSITORY_BASE}/${filePath}`; | ||
|
|
||
| return <a href={href}>このページを編集</a>; | ||
| } |
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,115 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import matter from "gray-matter"; | ||
|
|
||
| export interface ValidationError { | ||
| file: string; | ||
| message: string; | ||
| } | ||
|
|
||
| export interface ValidationResult { | ||
| errors: ValidationError[]; | ||
| successCount: number; | ||
| } | ||
|
|
||
| export interface ValidateOptions { | ||
| production?: boolean; | ||
| } | ||
|
|
||
| function isProduction(options: ValidateOptions): boolean { | ||
| if (options.production !== undefined) { | ||
| return options.production; | ||
| } | ||
| return process.env.NODE_ENV === "production"; | ||
| } | ||
|
|
||
| function walkMdxFiles(dir: string, files: string[] = []): string[] { | ||
| if (!fs.existsSync(dir)) { | ||
| return files; | ||
| } | ||
|
|
||
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { | ||
| const fullPath = path.join(dir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| walkMdxFiles(fullPath, files); | ||
| } else if (entry.isFile() && entry.name.endsWith(".mdx")) { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
|
|
||
| return files; | ||
| } | ||
|
|
||
| export function validateFrontmatter( | ||
| pagesDir: string, | ||
| options: ValidateOptions = {}, | ||
| ): ValidationResult { | ||
| const production = isProduction(options); | ||
| const errors: ValidationError[] = []; | ||
| let successCount = 0; | ||
|
|
||
| for (const filePath of walkMdxFiles(pagesDir)) { | ||
| const content = fs.readFileSync(filePath, "utf8"); | ||
| const { data } = matter(content); | ||
|
|
||
| const title = data.title; | ||
| if (typeof title !== "string" || title.trim() === "") { | ||
| errors.push({ | ||
| file: filePath, | ||
| message: 'Missing required "title" in frontmatter', | ||
| }); | ||
| continue; | ||
| } | ||
|
|
||
| if (production && data.draft === true) { | ||
| errors.push({ | ||
| file: filePath, | ||
| message: "Draft pages are not allowed in production builds", | ||
| }); | ||
| continue; | ||
| } | ||
|
|
||
| successCount++; | ||
| } | ||
|
|
||
| return { errors, successCount }; | ||
| } | ||
|
|
||
| export function validateFrontmatterOrThrow( | ||
| pagesDir: string, | ||
| options: ValidateOptions = {}, | ||
| ): ValidationResult { | ||
| const result = validateFrontmatter(pagesDir, options); | ||
| if (result.errors.length > 0) { | ||
| const details = result.errors | ||
| .map((error) => `${error.file}: ${error.message}`) | ||
| .join("\n"); | ||
| throw new Error(`Frontmatter validation failed:\n${details}`); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function main(): void { | ||
| const pagesDir = path.join(process.cwd(), "pages"); | ||
| const result = validateFrontmatter(pagesDir); | ||
|
|
||
| if (result.errors.length > 0) { | ||
| console.error("Frontmatter validation failed:"); | ||
| for (const error of result.errors) { | ||
| console.error(` ${error.file}: ${error.message}`); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log( | ||
| `Frontmatter validation passed: ${result.successCount} file(s) checked`, | ||
| ); | ||
| } | ||
|
|
||
| const isMainModule = | ||
| process.argv[1] !== undefined && | ||
| path.resolve(process.argv[1]) === path.resolve(__filename); | ||
|
|
||
| if (isMainModule) { | ||
| main(); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [high]
--offlineフラグにより外部リンクが検査されない該当箇所:
lycheeの--offlineオプションは HTTP/HTTPS リクエストを発行せず、ローカルファイル参照のみを検証する。ドキュメントサイトに外部 URL が含まれる場合、それらは一切チェックされない。タスク要件では「dead link detection」が求められているが、外部リンク切れをこのジョブでは検出できない。--offlineを除去し、--max-concurrencyで並列数を制限する。code.ci.dead_link_offline_only| confidence: 0.90