Repository navigation
fix(registry): invalidate stale documentation builds automatically #178
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
Open
TheRealBecks
wants to merge
1
commit into
neuledge:main
Choose a base branch
from
TheRealBecks:TheRealBecks/issues144
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@neuledge/context": patch | ||
| --- | ||
|
|
||
| Allow package builders to store build fingerprints and automatic ingestion revisions in package metadata for registry freshness checks. |
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 |
|---|---|---|
|
|
@@ -8,22 +8,25 @@ | |
| * (clone default branch) definitions. Supports git, zip and HTML index sources. | ||
| */ | ||
|
|
||
| import { execSync } from "node:child_process"; | ||
| import { execFileSync } from "node:child_process"; | ||
| import { join } from "node:path"; | ||
| import { | ||
| type BuildResult, | ||
| buildPackage, | ||
| cloneRepository, | ||
| initDatabase, | ||
| readLocalDocsFiles, | ||
| } from "@neuledge/context"; | ||
| import { | ||
| constructTag, | ||
| isGitVersionEntry, | ||
| type PackageDefinition, | ||
| resolveUrl, | ||
| resolveVersionEntry, | ||
| type UnversionedDefinition, | ||
| type VersionedDefinition, | ||
| } from "./definition.js"; | ||
| import { createBuildFingerprint, getIngestionRevision } from "./fingerprint.js"; | ||
| import { excludeFiles } from "./glob.js"; | ||
| import { downloadHtmlIndex } from "./html-index.js"; | ||
| import { downloadAndExtractZip } from "./zip.js"; | ||
|
|
@@ -44,19 +47,52 @@ export function getHeadCommit(url: string, ref?: string): string { | |
| // Must match the ref the package is built from. Asking for HEAD while building | ||
| // a branch compares two unrelated commits, so the skip-if-unchanged check never | ||
| // fires and the package is rebuilt and republished on every run. | ||
| const output = execSync(`git ls-remote ${url} ${ref ?? "HEAD"}`, { | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| }).trim(); | ||
| const requested = ref ?? "HEAD"; | ||
| const output = execFileSync( | ||
| "git", | ||
| ["ls-remote", url, requested, `${requested}^{}`], | ||
| { | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| }, | ||
| ).trim(); | ||
|
|
||
| // Format: "<sha>\tHEAD" | ||
| const sha = output.split("\t")[0]; | ||
| const refs = new Map( | ||
| output.split("\n").map((line) => { | ||
| const [sha, name] = line.split("\t"); | ||
| return [name, sha]; | ||
| }), | ||
| ); | ||
| // Match clone --branch: prefer a branch, and peel annotated tags to commits. | ||
| const sha = | ||
| refs.get(`refs/heads/${requested}`) ?? | ||
| refs.get(`${requested}^{}`) ?? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maintainability · comment: This codebase is managed by Human0. |
||
| refs.get(`refs/tags/${requested}^{}`) ?? | ||
| refs.get(requested) ?? | ||
| refs.get(`refs/tags/${requested}`); | ||
| if (!sha) { | ||
| throw new Error(`Failed to get HEAD commit for ${url}`); | ||
| throw new Error(`Git reference ${requested} not found in upstream ${url}`); | ||
| } | ||
| return sha; | ||
| } | ||
|
|
||
| function fingerprintOptions( | ||
| definition: PackageDefinition, | ||
| version: string, | ||
| sourceCommit?: string, | ||
| ) { | ||
| const ingestionRevision = getIngestionRevision(); | ||
| return { | ||
| ingestionRevision, | ||
| buildFingerprint: createBuildFingerprint( | ||
| definition, | ||
| version, | ||
| sourceCommit, | ||
| ingestionRevision, | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Build a .db package for a specific version of a versioned definition. | ||
| */ | ||
|
|
@@ -65,6 +101,7 @@ export async function buildFromDefinition( | |
| version: string, | ||
| outputDir: string, | ||
| ): Promise<RegistryBuildResult> { | ||
| await initDatabase(); | ||
| const entry = resolveVersionEntry(definition, version); | ||
| if (!entry) { | ||
| throw new Error( | ||
|
|
@@ -115,6 +152,7 @@ export async function buildFromDefinition( | |
| version, | ||
| description: definition.description, | ||
| sourceUrl: definition.repository ?? url, | ||
| ...fingerprintOptions(definition, version), | ||
| }); | ||
|
|
||
| return { | ||
|
|
@@ -134,6 +172,7 @@ export async function buildUnversioned( | |
| definition: UnversionedDefinition, | ||
| outputDir: string, | ||
| ): Promise<RegistryBuildResult> { | ||
| await initDatabase(); | ||
| const version = "latest"; | ||
| const { source } = definition; | ||
| const safeName = definition.name.replace(/\//g, "-"); | ||
|
|
@@ -157,6 +196,7 @@ export async function buildUnversioned( | |
| version, | ||
| description: definition.description, | ||
| sourceUrl: definition.repository ?? source.url, | ||
| ...fingerprintOptions(definition, version), | ||
| }); | ||
|
|
||
| return { | ||
|
|
@@ -172,7 +212,7 @@ export async function buildUnversioned( | |
|
|
||
| try { | ||
| // Get the commit SHA of the cloned HEAD | ||
| const sourceCommit = execSync("git rev-parse HEAD", { | ||
| const sourceCommit = execFileSync("git", ["rev-parse", "HEAD"], { | ||
| cwd: tempDir, | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
|
|
@@ -201,6 +241,7 @@ export async function buildUnversioned( | |
| description: definition.description, | ||
| sourceUrl: definition.repository ?? source.url, | ||
| sourceCommit, | ||
| ...fingerprintOptions(definition, version, sourceCommit), | ||
| }); | ||
|
|
||
| return { | ||
|
|
@@ -229,6 +270,11 @@ function buildFromGit( | |
| const { tempDir, cleanup } = cloneRepository(url, tag); | ||
|
|
||
| try { | ||
| const sourceCommit = execFileSync("git", ["rev-parse", "HEAD"], { | ||
| cwd: tempDir, | ||
| encoding: "utf-8", | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| }).trim(); | ||
| // Filter before the emptiness check, so an over-broad exclude_paths fails | ||
| // loudly here instead of publishing an empty package. | ||
| const files = excludeFiles( | ||
|
|
@@ -246,13 +292,16 @@ function buildFromGit( | |
| version, | ||
| description: definition.description, | ||
| sourceUrl: definition.repository ?? url, | ||
| sourceCommit, | ||
| ...fingerprintOptions(definition, version, sourceCommit), | ||
| }); | ||
|
|
||
| return { | ||
| ...result, | ||
| name: definition.name, | ||
| registry: definition.registry, | ||
| version, | ||
| sourceCommit, | ||
| }; | ||
| } finally { | ||
| cleanup(); | ||
|
|
||
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.
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.
Data & state · comment: The freshness check depends on the server copying
build_fingerprintandingestion_revisionfrom the uploaded database into metadata on every upload and replacement. This checkout has no server implementation, and the test is a mock; track or verify server adoption before relying on automatic invalidation.This codebase is managed by Human0.