Skip to content

Commit 9d1c821

Browse files
committed
⚡ cache DeepWiki repository inventory
1 parent 2afc662 commit 9d1c821

1 file changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/sync-deepwiki.yaml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
env:
2222
DEEPWIKI_RAW_DIR: ${{ runner.temp }}/deepwiki-raw
2323
DEEPWIKI_GENERATED_DIR: ${{ runner.temp }}/deepwiki-generated
24+
DEEPWIKI_REPOSITORY_FILES: ${{ runner.temp }}/deepwiki-repository-files.json
2425
DEEPWIKI_VALIDATION: ${{ runner.temp }}/deepwiki-validation.json
2526
DEEPWIKI_DECISION: ${{ runner.temp }}/deepwiki-decision.json
2627
DEEPWIKI_REPORT: ${{ runner.temp }}/deepwiki-report.json
@@ -612,6 +613,7 @@ jobs:
612613
613614
const RAW_DIR = path.resolve(process.env.DEEPWIKI_RAW_DIR ?? ".deepwiki-raw");
614615
const GENERATED_DIR = path.resolve(process.env.DEEPWIKI_GENERATED_DIR ?? ".deepwiki-generated");
616+
const REPOSITORY_FILES = path.resolve(process.env.DEEPWIKI_REPOSITORY_FILES ?? ".deepwiki-repository-files.json");
615617
const VALIDATION_FILE = path.resolve(process.env.DEEPWIKI_VALIDATION ?? ".deepwiki-validation.json");
616618
const DECISION_FILE = path.resolve(process.env.DEEPWIKI_DECISION ?? ".deepwiki-decision.json");
617619
@@ -626,6 +628,43 @@ jobs:
626628
await writeFile(filename, `${JSON.stringify(value, null, 2)}\n`, "utf8");
627629
}
628630
631+
async function writeRepositoryFiles(files, repositoryRoot) {
632+
await writeJson(REPOSITORY_FILES, {
633+
version: 1,
634+
root: path.resolve(repositoryRoot),
635+
revision: process.env.GITHUB_SHA ?? null,
636+
files: [...files],
637+
});
638+
}
639+
640+
async function loadRepositoryFiles(repositoryRoot) {
641+
let inventory;
642+
try {
643+
inventory = JSON.parse(await readFile(REPOSITORY_FILES, "utf8"));
644+
} catch (error) {
645+
throw new Error(`cannot load repository file inventory ${REPOSITORY_FILES}: ${error.message}`);
646+
}
647+
if (
648+
inventory?.version !== 1 ||
649+
inventory.root !== path.resolve(repositoryRoot) ||
650+
inventory.revision !== (process.env.GITHUB_SHA ?? null) ||
651+
!Array.isArray(inventory.files) ||
652+
new Set(inventory.files).size !== inventory.files.length ||
653+
inventory.files.some(
654+
(file) =>
655+
typeof file !== "string" ||
656+
!file ||
657+
path.isAbsolute(file) ||
658+
file === ".." ||
659+
file.startsWith("../") ||
660+
path.posix.normalize(file) !== file
661+
)
662+
) {
663+
throw new Error(`repository file inventory is malformed: ${REPOSITORY_FILES}`);
664+
}
665+
return new Set(inventory.files);
666+
}
667+
629668
async function fetchCommand() {
630669
const repository = repositoryName();
631670
const { structure, contents } = await loadWiki(repository);
@@ -643,7 +682,9 @@ jobs:
643682
644683
async function analyzeCommand() {
645684
const repository = repositoryName();
646-
const repositoryFiles = await collectRepositoryFiles(process.cwd());
685+
const repositoryRoot = process.cwd();
686+
const repositoryFiles = await collectRepositoryFiles(repositoryRoot);
687+
await writeRepositoryFiles(repositoryFiles, repositoryRoot);
647688
const structure = await readFile(path.join(RAW_DIR, "structure.md"), "utf8");
648689
const contents = await readFile(path.join(RAW_DIR, "contents.md"), "utf8");
649690
const { entries, pages, files } = buildSnapshot(structure, contents, repositoryFiles);
@@ -653,6 +694,7 @@ jobs:
653694
`- Structure pages: ${entries.length}`,
654695
`- Contents pages: ${pages.length}`,
655696
`- Generated Markdown files: ${files.size}`,
697+
`- Repository file inventory: ${repositoryFiles.size} files saved once for later steps`,
656698
`- Generated snapshot staged at: ${GENERATED_DIR}`,
657699
]);
658700
console.log(`DeepWiki response analyzed and split into ${files.size} files.`);
@@ -661,7 +703,7 @@ jobs:
661703
async function validateCommand() {
662704
const repository = repositoryName();
663705
const repositoryRoot = process.cwd();
664-
const repositoryFiles = await collectRepositoryFiles(repositoryRoot);
706+
const repositoryFiles = await loadRepositoryFiles(repositoryRoot);
665707
const structure = await readFile(path.join(RAW_DIR, "structure.md"), "utf8");
666708
const contents = await readFile(path.join(RAW_DIR, "contents.md"), "utf8");
667709
const entries = parseWikiStructure(structure);
@@ -682,6 +724,7 @@ jobs:
682724
`- Structure pages: ${entries.length}`,
683725
`- Contents pages: ${pages.length}`,
684726
`- Generated page files: ${validation.writtenFiles.length}`,
727+
`- Repository file inventory: ${repositoryFiles.size} files reused from ${REPOSITORY_FILES}`,
685728
`- Problems found: ${validation.problems.length}`,
686729
`- Warnings found: ${validation.warnings.length}`,
687730
];
@@ -722,7 +765,7 @@ jobs:
722765
}
723766
724767
const repositoryRoot = process.cwd();
725-
const repositoryFiles = await collectRepositoryFiles(repositoryRoot);
768+
const repositoryFiles = await loadRepositoryFiles(repositoryRoot);
726769
const validation = JSON.parse(await readFile(VALIDATION_FILE, "utf8"));
727770
const entries = validation.structureEntries;
728771
const pages = validation.contentPageTitles.map((title) => ({ title }));

0 commit comments

Comments
 (0)