This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: registering to aztec registry on deployment #102
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,128 @@ | ||
| import { readFile } from "node:fs/promises"; | ||
|
|
||
| export type ArtifactRegistryUploadResponse = | ||
| | { | ||
| success: true; | ||
| filename?: string; | ||
| classId?: string; | ||
| contractName?: string; | ||
| functionCount?: number; | ||
| [key: string]: unknown; | ||
| } | ||
| | { | ||
| success: false; | ||
| error?: string; | ||
| message?: string; | ||
| [key: string]: unknown; | ||
| }; | ||
|
|
||
| function normalizeBaseUrl(baseUrl: string): string { | ||
| return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`; | ||
| } | ||
|
|
||
| export function getArtifactRegistryBaseUrl(): string { | ||
| return ( | ||
| process.env.AZTEC_ARTIFACT_REGISTRY_URL ?? | ||
| "https://devnet.aztec-registry.xyz/" | ||
| ); | ||
| } | ||
|
|
||
| export function shouldUploadArtifacts(): boolean { | ||
| const v = process.env.AZTEC_ARTIFACT_REGISTRY_UPLOAD ?? ""; | ||
| return v === "1" || v.toLowerCase() === "true"; | ||
| } | ||
|
|
||
| export function isStrictUpload(): boolean { | ||
| const v = process.env.AZTEC_ARTIFACT_REGISTRY_STRICT ?? ""; | ||
| return v === "1" || v.toLowerCase() === "true"; | ||
| } | ||
|
|
||
| export async function uploadArtifactToRegistry(params: { | ||
| artifact: unknown; | ||
| filename: string; | ||
| registryBaseUrl?: string; | ||
| }): Promise<ArtifactRegistryUploadResponse> { | ||
| const base = normalizeBaseUrl( | ||
| params.registryBaseUrl ?? getArtifactRegistryBaseUrl(), | ||
| ); | ||
| const uploadUrl = new URL("api/upload", base).toString(); | ||
|
|
||
| const body = new FormData(); | ||
| const payload = JSON.stringify(params.artifact); | ||
| body.set( | ||
| "file", | ||
| new Blob([payload], { type: "application/json" }), | ||
| params.filename, | ||
| ); | ||
|
|
||
| const res = await fetch(uploadUrl, { method: "POST", body }); | ||
|
|
||
| // The registry commonly returns JSON even on 409; treat duplicates as non-fatal by default. | ||
| const text = await res.text(); | ||
| const parsed: unknown = text ? safeJsonParse(text) : { success: res.ok }; | ||
|
|
||
| if (res.ok) { | ||
| return (parsed as ArtifactRegistryUploadResponse) ?? { success: true }; | ||
| } | ||
|
|
||
| // Duplicate artifact (already uploaded) should not break deploys unless strict mode is enabled. | ||
| if (res.status === 409) { | ||
| return ( | ||
| (parsed as ArtifactRegistryUploadResponse) ?? { | ||
| success: true, | ||
| message: "Artifact already exists in registry", | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| const msg = | ||
| typeof parsed === "object" && parsed | ||
| ? JSON.stringify(parsed) | ||
| : text || `HTTP ${res.status} ${res.statusText}`; | ||
| throw new Error(`Artifact registry upload failed (${res.status}): ${msg}`); | ||
| } | ||
|
|
||
| export async function uploadArtifactFileToRegistry(params: { | ||
| artifactPath: string; | ||
| filename?: string; | ||
| registryBaseUrl?: string; | ||
| }): Promise<ArtifactRegistryUploadResponse> { | ||
| const buf = await readFile(params.artifactPath, "utf8"); | ||
| const artifact = JSON.parse(buf) as unknown; | ||
| const filename = | ||
| params.filename ?? params.artifactPath.split("/").pop() ?? "artifact.json"; | ||
| return await uploadArtifactToRegistry({ | ||
| artifact, | ||
| filename, | ||
| registryBaseUrl: params.registryBaseUrl, | ||
| }); | ||
| } | ||
|
|
||
| export async function maybeUploadArtifactToRegistry(params: { | ||
| artifact: unknown; | ||
| filename: string; | ||
| registryBaseUrl?: string; | ||
| }): Promise<ArtifactRegistryUploadResponse | null> { | ||
| if (!shouldUploadArtifacts()) return null; | ||
| try { | ||
| const resp = await uploadArtifactToRegistry(params); | ||
| return resp; | ||
| } catch (err) { | ||
| if (isStrictUpload()) throw err; | ||
| // Best-effort upload; do not fail deployments by default. | ||
| console.warn( | ||
| `[artifact-registry] Upload failed (continuing): ${ | ||
| err instanceof Error ? err.message : String(err) | ||
| }`, | ||
| ); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function safeJsonParse(text: string): unknown { | ||
| try { | ||
| return JSON.parse(text) as unknown; | ||
| } catch { | ||
| return text; | ||
| } | ||
| } |
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
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.
π Bug - Deployment State Inconsistency: Either move the upload before deployment (if feasible), or catch upload errors and return the contract with a warning/metadata about upload failure instead of throwing. Alternatively, clearly document this behavior and consider returning both the contract and upload result in a structured response.
Is this review accurate? Use π or π to rate it
If you want to tell us more, use
/gs feedbacke.g. /gs feedback this review doesn't make sense, I disagree, and it keeps repeating over and over