From 470ca5b9354b3c9a9cce9e7e806ac3988468dff8 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Fri, 13 Nov 2026 17:30:17 -0600 Subject: [PATCH 01/10] Add a tested script that checks a release image's tags Layer: check-release-image-publish --- .github/scripts/releaseImage.test.ts | 330 +++++++++++++++++++++++++++ .github/scripts/releaseImage.ts | 243 ++++++++++++++++++++ .github/scripts/tsconfig.json | 8 + .github/scripts/vite.config.ts | 8 + docs/agents/testing.md | 2 +- vite.config.ts | 2 +- 6 files changed, 591 insertions(+), 2 deletions(-) create mode 100644 .github/scripts/releaseImage.test.ts create mode 100644 .github/scripts/releaseImage.ts create mode 100644 .github/scripts/tsconfig.json create mode 100644 .github/scripts/vite.config.ts diff --git a/.github/scripts/releaseImage.test.ts b/.github/scripts/releaseImage.test.ts new file mode 100644 index 000000000..37488d64d --- /dev/null +++ b/.github/scripts/releaseImage.test.ts @@ -0,0 +1,330 @@ +import { afterEach, describe, expect, it, vi } from "vite-plus/test"; + +import { + checkOneDigest, + fetchDigests, + fetchPublishedTags, + planRelease, +} from "./releaseImage.ts"; + +const publishedTags = [ + "latest", + "sagemaker-latest", + "latest-SNAPSHOT", + "sagemaker-latest-SNAPSHOT", + "3.3.0", + "sagemaker-3.3.0", + "3.3.2", + "sagemaker-3.3.2", + "1.10.0", + "2.0.0", +]; + +describe("planRelease", () => { + it("pushes the version tags and moves latest for the newest version", () => { + expect( + planRelease({ + ref: "refs/tags/v3.4.0", + version: "3.4.0", + publishedTags, + }), + ).toStrictEqual(["3.4.0", "sagemaker-3.4.0", "latest", "sagemaker-latest"]); + }); + + it("leaves latest alone for a version older than one already published", () => { + expect( + planRelease({ + ref: "refs/tags/v3.3.3", + version: "3.3.3", + publishedTags: [...publishedTags, "3.4.0", "sagemaker-3.4.0"], + }), + ).toStrictEqual(["3.3.3", "sagemaker-3.3.3"]); + }); + + it("compares versions numerically, not as text", () => { + expect( + planRelease({ + ref: "refs/tags/v3.10.0", + version: "3.10.0", + publishedTags: ["3.9.0", "3.3.2"], + }), + ).toContain("latest"); + expect( + planRelease({ + ref: "refs/tags/v3.9.1", + version: "3.9.1", + publishedTags: ["3.10.0"], + }), + ).not.toContain("latest"); + }); + + it("ranks non-numeric tags lowest, as the notebook script does", () => { + expect( + planRelease({ + ref: "refs/tags/v0.0.1", + version: "0.0.1", + publishedTags: [ + "latest", + "sagemaker-9.9.9", + "9.9.9-rc1", + "v9.9.9", + "latest-SNAPSHOT", + ], + }), + ).toContain("latest"); + }); + + it("ranks a shorter numeric tag below its longer form", () => { + expect( + planRelease({ + ref: "refs/tags/v3.4.0", + version: "3.4.0", + publishedTags: ["3.4"], + }), + ).toContain("latest"); + }); + + it("leaves latest alone when a published tag has more numeric parts", () => { + expect( + planRelease({ + ref: "refs/tags/v3.4.0", + version: "3.4.0", + publishedTags: ["3.4.0.1"], + }), + ).not.toContain("latest"); + }); + + it("fails when the run is not on a tag", () => { + expect(() => + planRelease({ + ref: "refs/heads/main", + version: "3.4.0", + publishedTags, + }), + ).toThrow( + "Release runs must start from the tag v3.4.0, but this run is on refs/heads/main.", + ); + }); + + it("fails when the tag does not match the package.json version", () => { + expect(() => + planRelease({ + ref: "refs/tags/v3.4.1", + version: "3.4.0", + publishedTags, + }), + ).toThrow( + "Release runs must start from the tag v3.4.0, but this run is on refs/tags/v3.4.1.", + ); + }); + + it("fails when the version is already published", () => { + expect(() => + planRelease({ + ref: "refs/tags/v3.3.2", + version: "3.3.2", + publishedTags: ["latest", "3.3.2"], + }), + ).toThrow("3.3.2 is already published."); + }); + + it("fails when only the sagemaker tag of the version is published", () => { + expect(() => + planRelease({ + ref: "refs/tags/v3.5.0", + version: "3.5.0", + publishedTags: ["sagemaker-3.5.0"], + }), + ).toThrow("sagemaker-3.5.0 is already published."); + }); + + it.each(["3.4.0-beta.1", "3.4", "v3.4.0", "03.4.0", "3.4.0.1", ""])( + "fails when the version %j is not a plain X.Y.Z", + version => { + expect(() => + planRelease({ ref: `refs/tags/v${version}`, version, publishedTags }), + ).toThrow(`The package.json version "${version}" is not X.Y.Z.`); + }, + ); +}); + +describe("checkOneDigest", () => { + it("returns the digest every tag points to", () => { + expect( + checkOneDigest( + new Map([ + ["3.4.0", "sha256:aaa"], + ["sagemaker-3.4.0", "sha256:aaa"], + ]), + ), + ).toBe("sha256:aaa"); + }); + + it("fails when tags point to different digests", () => { + expect(() => + checkOneDigest( + new Map([ + ["3.4.0", "sha256:aaa"], + ["latest", "sha256:bbb"], + ]), + ), + ).toThrow( + "The pushed tags point to more than one image: 3.4.0 sha256:aaa, latest sha256:bbb.", + ); + }); + + it("fails when a tag is missing", () => { + expect(() => + checkOneDigest( + new Map([ + ["3.4.0", "sha256:aaa"], + ["sagemaker-3.4.0", null], + ]), + ), + ).toThrow("sagemaker-3.4.0 is not in the registry."); + }); +}); + +describe("registry reads", () => { + afterEach(() => { + vi.useRealTimers(); + }); + + function stubRegistry( + routes: Record Response>, + ): ReturnType { + const fetchMock = vi.fn((input: string | URL) => { + const url = String(input); + const route = routes[url]; + if (!route) { + throw new Error(`Unexpected request to ${url}`); + } + return Promise.resolve(route()); + }); + vi.stubGlobal("fetch", fetchMock); + return fetchMock; + } + + const tokenRoute = { + "https://public.ecr.aws/token/": () => Response.json({ token: "anon" }), + }; + + it("reads every tag, following the next page", async () => { + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + Response.json( + { tags: ["3.3.2", "latest"] }, + { + headers: { + Link: '; rel="next"', + }, + }, + ), + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000&last=latest": + () => Response.json({ tags: ["sagemaker-3.3.2"] }), + }); + + await expect(fetchPublishedTags()).resolves.toStrictEqual([ + "3.3.2", + "latest", + "sagemaker-3.3.2", + ]); + }); + + it("fails on a tag list it can't read", async () => { + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + Response.json({ tags: [3] }), + }); + + await expect(fetchPublishedTags()).rejects.toThrow( + "The registry returned a tag list without a list of tags.", + ); + }); + + it("fails when the registry refuses the tag list", async () => { + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + new Response("busy", { status: 503 }), + }); + + await expect(fetchPublishedTags()).rejects.toThrow( + "GET https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000 returned 503.", + ); + }); + + it("reads each tag's digest, or null when the tag is absent", async () => { + const fetchMock = stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/manifests/3.3.2": () => + new Response(null, { + headers: { "Docker-Content-Digest": "sha256:aaa" }, + }), + "https://public.ecr.aws/v2/neptune/graph-explorer/manifests/3.3.3": () => + new Response(null, { status: 404 }), + }); + + await expect(fetchDigests(["3.3.2", "3.3.3"])).resolves.toStrictEqual( + new Map([ + ["3.3.2", "sha256:aaa"], + ["3.3.3", null], + ]), + ); + expect(fetchMock).toHaveBeenCalledWith( + "https://public.ecr.aws/v2/neptune/graph-explorer/manifests/3.3.2", + expect.objectContaining({ + method: "HEAD", + headers: expect.objectContaining({ Authorization: "Bearer anon" }), + }), + ); + }); + + it("fails when the registry refuses a digest read", async () => { + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/manifests/latest": () => + new Response(null, { status: 500 }), + }); + + await expect(fetchDigests(["latest"])).rejects.toThrow( + "HEAD https://public.ecr.aws/v2/neptune/graph-explorer/manifests/latest returned 500.", + ); + }); + + it("waits out throttling and asks again", async () => { + vi.useFakeTimers(); + const statuses = [429, 429, 200]; + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + Response.json({ tags: ["3.3.2"] }, { status: statuses.shift() }), + }); + + const tags = fetchPublishedTags(); + await vi.runAllTimersAsync(); + + await expect(tags).resolves.toStrictEqual(["3.3.2"]); + expect(statuses).toStrictEqual([]); + }); + + it("gives up when throttling lasts", async () => { + vi.useFakeTimers(); + stubRegistry({ + ...tokenRoute, + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + new Response(null, { status: 429 }), + }); + + const failure = fetchPublishedTags().catch((error: unknown) => error); + await vi.runAllTimersAsync(); + + expect(await failure).toStrictEqual( + new Error( + "GET https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000 returned 429.", + ), + ); + }); +}); diff --git a/.github/scripts/releaseImage.ts b/.github/scripts/releaseImage.ts new file mode 100644 index 000000000..e6a64b829 --- /dev/null +++ b/.github/scripts/releaseImage.ts @@ -0,0 +1,243 @@ +/** + * Decides which tags a release run of build_docker.yml pushes, and checks + * them afterwards. It has no dependencies, so the workflow runs it with plain + * Node and no install. + * + * node .github/scripts/releaseImage.ts plan + * node .github/scripts/releaseImage.ts verify ... + */ +import { appendFileSync, readFileSync } from "node:fs"; + +const registry = "https://public.ecr.aws"; +const repository = "neptune/graph-explorer"; + +/** + * Checks a release's inputs and returns the tags to push, in push order. + * Throws when the run must not publish. + */ +export function planRelease({ + ref, + version, + publishedTags, +}: { + ref: string; + version: string; + publishedTags: readonly string[]; +}): string[] { + if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) { + throw new Error(`The package.json version "${version}" is not X.Y.Z.`); + } + if (ref !== `refs/tags/v${version}`) { + throw new Error( + `Release runs must start from the tag v${version}, but this run is on ${ref}.`, + ); + } + + const tags = [version, `sagemaker-${version}`]; + const published = new Set(publishedTags); + for (const tag of tags) { + if (published.has(tag)) { + throw new Error(`${tag} is already published.`); + } + } + + const key = notebookSortKey(version); + const isNewest = publishedTags.every( + tag => compareSortKeys(key, notebookSortKey(tag)) > 0, + ); + return isNewest ? [...tags, "latest", "sagemaker-latest"] : tags; +} + +// SageMaker notebooks pull `sagemaker-`, ranked by the +// jq in Neptune's lifecycle script, so `latest` must follow that same order: +// sort_by(split(".") | try map(tonumber) catch [0,0,0]) +function notebookSortKey(tag: string): number[] { + const parts = tag.split("."); + return parts.every(part => /^\d+$/.test(part)) + ? parts.map(Number) + : [0, 0, 0]; +} + +function compareSortKeys(a: number[], b: number[]): number { + for (let i = 0; i < Math.min(a.length, b.length); i++) { + if (a[i] !== b[i]) { + return a[i] - b[i]; + } + } + return a.length - b.length; +} + +/** + * Returns the one digest every tag points to. Throws when a tag is missing + * (`null`) or the tags point to different images. + */ +export function checkOneDigest( + digests: ReadonlyMap, +): string { + const found = new Set(); + for (const [tag, digest] of digests) { + if (digest === null) { + throw new Error(`${tag} is not in the registry.`); + } + found.add(digest); + } + const [digest, ...others] = found; + if (digest === undefined) { + throw new Error("No tags to check."); + } + if (others.length > 0) { + const list = [...digests].map(([tag, d]) => `${tag} ${d}`).join(", "); + throw new Error(`The pushed tags point to more than one image: ${list}.`); + } + return digest; +} + +/** Every tag in the public repository, read anonymously. */ +export async function fetchPublishedTags(): Promise { + const headers = await anonymousAuth(); + const tags: string[] = []; + let url: string | null = `${registry}/v2/${repository}/tags/list?n=1000`; + while (url) { + const response = await request(url, { headers }); + const body: unknown = await response.json(); + tags.push(...parseTagList(body)); + url = nextPage(response.headers.get("Link")); + } + return tags; +} + +/** + * The digest each tag points to, or `null` for a tag that doesn't exist. Asks + * one tag at a time, since the registry throttles bursts of anonymous reads. + */ +export async function fetchDigests( + tags: readonly string[], +): Promise> { + const headers = { + ...(await anonymousAuth()), + Accept: [ + "application/vnd.oci.image.index.v1+json", + "application/vnd.oci.image.manifest.v1+json", + "application/vnd.docker.distribution.manifest.list.v2+json", + "application/vnd.docker.distribution.manifest.v2+json", + ].join(", "), + }; + const digests = new Map(); + for (const tag of tags) { + const url = `${registry}/v2/${repository}/manifests/${tag}`; + const response = await request(url, { method: "HEAD", headers }, [404]); + if (response.status === 404) { + digests.set(tag, null); + continue; + } + const digest = response.headers.get("Docker-Content-Digest"); + if (!digest) { + throw new Error(`HEAD ${url} returned no digest.`); + } + digests.set(tag, digest); + } + return digests; +} + +async function anonymousAuth(): Promise<{ Authorization: string }> { + const response = await request(`${registry}/token/`, {}); + const body: unknown = await response.json(); + if ( + typeof body !== "object" || + body === null || + !("token" in body) || + typeof body.token !== "string" + ) { + throw new Error("The registry returned no anonymous token."); + } + return { Authorization: `Bearer ${body.token}` }; +} + +const throttleRetryDelaysMs = [1000, 2000, 4000, 8000]; + +/** Fetches `url`, waiting out throttling, and throws on an unexpected status. */ +async function request( + url: string, + init: RequestInit, + allowedStatuses: readonly number[] = [], +): Promise { + let response = await fetch(url, init); + for (const delayMs of throttleRetryDelaysMs) { + if (response.status !== 429) { + break; + } + await new Promise(resolve => setTimeout(resolve, delayMs)); + response = await fetch(url, init); + } + if (!response.ok && !allowedStatuses.includes(response.status)) { + throw new Error( + `${init.method ?? "GET"} ${url} returned ${response.status}.`, + ); + } + return response; +} + +function parseTagList(body: unknown): string[] { + if ( + typeof body === "object" && + body !== null && + "tags" in body && + Array.isArray(body.tags) && + body.tags.every(tag => typeof tag === "string") + ) { + return body.tags; + } + throw new Error("The registry returned a tag list without a list of tags."); +} + +function nextPage(link: string | null): string | null { + const match = link?.match(/<([^>]+)>;\s*rel="next"/); + return match ? new URL(match[1], registry).href : null; +} + +function readPackageVersion(): string { + const body: unknown = JSON.parse(readFileSync("package.json", "utf8")); + if ( + typeof body !== "object" || + body === null || + !("version" in body) || + typeof body.version !== "string" + ) { + throw new Error("package.json has no version."); + } + return body.version; +} + +function writeOutput(name: string, value: string): void { + process.stdout.write(`${name}=${value}\n`); + const file = process.env.GITHUB_OUTPUT; + if (file) { + appendFileSync(file, `${name}=${value}\n`); + } +} + +async function main([command, ...args]: string[]): Promise { + if (command === "plan") { + const ref = process.env.GITHUB_REF; + if (!ref) { + throw new Error("GITHUB_REF is not set."); + } + const tags = planRelease({ + ref, + version: readPackageVersion(), + publishedTags: await fetchPublishedTags(), + }); + writeOutput("tags", tags.join(" ")); + return; + } + if (command === "verify" && args.length > 0) { + const digest = checkOneDigest(await fetchDigests(args)); + process.stdout.write(`${args.join(", ")} all point to ${digest}\n`); + return; + } + throw new Error("Usage: releaseImage.ts plan | verify ..."); +} + +if (import.meta.main) { + await main(process.argv.slice(2)); +} diff --git a/.github/scripts/tsconfig.json b/.github/scripts/tsconfig.json new file mode 100644 index 000000000..cf13caf50 --- /dev/null +++ b/.github/scripts/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["."], + "compilerOptions": { + "allowImportingTsExtensions": true, + "types": ["node"] + } +} diff --git a/.github/scripts/vite.config.ts b/.github/scripts/vite.config.ts new file mode 100644 index 000000000..e98e29e58 --- /dev/null +++ b/.github/scripts/vite.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from "vite-plus"; + +export default defineConfig({ + test: { + environment: "node", + unstubGlobals: true, + }, +}); diff --git a/docs/agents/testing.md b/docs/agents/testing.md index 7c03ca922..773523ccf 100644 --- a/docs/agents/testing.md +++ b/docs/agents/testing.md @@ -4,7 +4,7 @@ Vitest. Tests co-locate with source as `*.test.ts` (or `*.test.tsx` for componen ## Where tests live -Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*` and `scripts`, the repository's own Node scripts. A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. +Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*`, `scripts` (the repository's own Node scripts), and `.github/scripts` (the workflow helper scripts). A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. Each project sets up its own environment. `setupTests.ts` below is registered by `packages/graph-explorer` only. `packages/graph-explorer-proxy-server` has its own setup file, and `packages/shared` has no setup file, so any tests added there must reset their own mocks. diff --git a/vite.config.ts b/vite.config.ts index 7163373a8..2b3aab209 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -16,7 +16,7 @@ const deepRelativeImports = { export default defineConfig({ test: { - projects: ["packages/*", "scripts"], + projects: ["packages/*", "scripts", ".github/scripts"], }, staged: { "*": "vp check --fix", From 392d9cd8e1286982506bfcae52afce6c8f35de0a Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Fri, 13 Nov 2026 17:30:17 -0600 Subject: [PATCH 02/10] Check the tag, version, and latest tags before publishing a release image Layer: check-release-image-publish --- .github/workflows/build_docker.yml | 69 ++++++++++++++++++------------ 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index ac7a73727..e28038b15 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -1,5 +1,13 @@ name: Build Docker image and publish to ECR +# A push to main publishes latest-SNAPSHOT. To publish a release, dispatch on +# its tag once the tag exists: +# +# gh workflow run build_docker.yml --ref v -f image_tag=release +# +# The release check fails the run unless the tag matches package.json and the +# version is new, and it moves latest only for the highest version. + on: workflow_dispatch: inputs: @@ -28,25 +36,35 @@ jobs: build-and-push-image: runs-on: ubuntu-latest timeout-minutes: 15 + env: + IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }} steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Get package version - id: package-version - run: echo "version=$(node -p 'require("./package.json").version')" >> $GITHUB_OUTPUT + - name: Set up Node.js + if: ${{ env.IS_RELEASE == 'true' }} + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .node-version + package-manager-cache: false + + # Runs before anything is pushed. + - name: Check the release and choose its tags + id: release + if: ${{ env.IS_RELEASE == 'true' }} + run: node .github/scripts/releaseImage.ts plan - - name: Get image tag - id: get-image-tag + - name: Get image tags + id: get-image-tags env: - IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }} - VERSION: ${{ steps.package-version.outputs.version }} + RELEASE_TAGS: ${{ steps.release.outputs.tags }} run: | if [ "$IS_RELEASE" = "true" ]; then - echo "image_tag=$VERSION" >> $GITHUB_OUTPUT + echo "tags=$RELEASE_TAGS" >> "$GITHUB_OUTPUT" else - echo "image_tag=latest-SNAPSHOT" >> $GITHUB_OUTPUT + echo "tags=latest-SNAPSHOT sagemaker-latest-SNAPSHOT" >> "$GITHUB_OUTPUT" fi - name: Configure AWS Credentials @@ -67,25 +85,22 @@ jobs: - name: Build, tag, and push Docker image env: - REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} - REGISTRY_ALIAS: neptune - REPOSITORY: graph-explorer - IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }} + IMAGE: ${{ steps.login-ecr-public.outputs.registry }}/neptune/graph-explorer + TAGS: ${{ steps.get-image-tags.outputs.tags }} + # TAGS is a space-separated list, split on purpose. run: | - docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG . - docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG - docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG - docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG + # shellcheck disable=SC2086 + set -- $TAGS + docker build -t "$IMAGE:$1" . + for tag in "$@"; do + docker tag "$IMAGE:$1" "$IMAGE:$tag" + docker push "$IMAGE:$tag" + done - - name: Update latest tag for release - if: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }} + - name: Check every pushed tag points to one image + if: ${{ env.IS_RELEASE == 'true' }} env: - REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} - REGISTRY_ALIAS: neptune - REPOSITORY: graph-explorer - IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }} + TAGS: ${{ steps.get-image-tags.outputs.tags }} run: | - docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest - docker tag $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-latest - docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest - docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:sagemaker-latest + # shellcheck disable=SC2086 + node .github/scripts/releaseImage.ts verify $TAGS From 046e6d3ca71e43548ce8d4c058ab8bdbcc0e4958 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 18:16:00 -0600 Subject: [PATCH 03/10] Give the image publish 20 minutes A two-platform build with the arm64 stages under emulation takes about 5 to 7 minutes, so 20 minutes leaves 3x headroom. --- .github/workflows/build_docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index e28038b15..a62714682 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -35,7 +35,7 @@ concurrency: jobs: build-and-push-image: runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 env: IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }} From 0545909b725a29029cb4e22907f494eb9264f882 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 19:42:09 -0600 Subject: [PATCH 04/10] Keep the release scripts in one folder The release image checks join the version script in scripts/, with one test project. The runtime image copies only named paths, so scripts/ stays out of it. --- .github/scripts/tsconfig.json | 8 -------- .github/scripts/vite.config.ts | 8 -------- .github/workflows/build_docker.yml | 4 ++-- docs/agents/testing.md | 2 +- {.github/scripts => scripts}/releaseImage.test.ts | 0 {.github/scripts => scripts}/releaseImage.ts | 4 ++-- scripts/vite.config.ts | 7 ++++++- vite.config.ts | 2 +- 8 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 .github/scripts/tsconfig.json delete mode 100644 .github/scripts/vite.config.ts rename {.github/scripts => scripts}/releaseImage.test.ts (100%) rename {.github/scripts => scripts}/releaseImage.ts (98%) diff --git a/.github/scripts/tsconfig.json b/.github/scripts/tsconfig.json deleted file mode 100644 index cf13caf50..000000000 --- a/.github/scripts/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["."], - "compilerOptions": { - "allowImportingTsExtensions": true, - "types": ["node"] - } -} diff --git a/.github/scripts/vite.config.ts b/.github/scripts/vite.config.ts deleted file mode 100644 index e98e29e58..000000000 --- a/.github/scripts/vite.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from "vite-plus"; - -export default defineConfig({ - test: { - environment: "node", - unstubGlobals: true, - }, -}); diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index a62714682..9b23b94b7 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -54,7 +54,7 @@ jobs: - name: Check the release and choose its tags id: release if: ${{ env.IS_RELEASE == 'true' }} - run: node .github/scripts/releaseImage.ts plan + run: node scripts/releaseImage.ts plan - name: Get image tags id: get-image-tags @@ -103,4 +103,4 @@ jobs: TAGS: ${{ steps.get-image-tags.outputs.tags }} run: | # shellcheck disable=SC2086 - node .github/scripts/releaseImage.ts verify $TAGS + node scripts/releaseImage.ts verify $TAGS diff --git a/docs/agents/testing.md b/docs/agents/testing.md index 773523ccf..a423bfcca 100644 --- a/docs/agents/testing.md +++ b/docs/agents/testing.md @@ -4,7 +4,7 @@ Vitest. Tests co-locate with source as `*.test.ts` (or `*.test.tsx` for componen ## Where tests live -Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*`, `scripts` (the repository's own Node scripts), and `.github/scripts` (the workflow helper scripts). A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. +Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*` and `scripts`, the repository's own Node scripts, including the ones the release workflows run. A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. Each project sets up its own environment. `setupTests.ts` below is registered by `packages/graph-explorer` only. `packages/graph-explorer-proxy-server` has its own setup file, and `packages/shared` has no setup file, so any tests added there must reset their own mocks. diff --git a/.github/scripts/releaseImage.test.ts b/scripts/releaseImage.test.ts similarity index 100% rename from .github/scripts/releaseImage.test.ts rename to scripts/releaseImage.test.ts diff --git a/.github/scripts/releaseImage.ts b/scripts/releaseImage.ts similarity index 98% rename from .github/scripts/releaseImage.ts rename to scripts/releaseImage.ts index e6a64b829..56e21ea0e 100644 --- a/.github/scripts/releaseImage.ts +++ b/scripts/releaseImage.ts @@ -3,8 +3,8 @@ * them afterwards. It has no dependencies, so the workflow runs it with plain * Node and no install. * - * node .github/scripts/releaseImage.ts plan - * node .github/scripts/releaseImage.ts verify ... + * node scripts/releaseImage.ts plan + * node scripts/releaseImage.ts verify ... */ import { appendFileSync, readFileSync } from "node:fs"; diff --git a/scripts/vite.config.ts b/scripts/vite.config.ts index 600ed22de..e98e29e58 100644 --- a/scripts/vite.config.ts +++ b/scripts/vite.config.ts @@ -1,3 +1,8 @@ import { defineConfig } from "vite-plus"; -export default defineConfig({ test: { environment: "node" } }); +export default defineConfig({ + test: { + environment: "node", + unstubGlobals: true, + }, +}); diff --git a/vite.config.ts b/vite.config.ts index 2b3aab209..7163373a8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -16,7 +16,7 @@ const deepRelativeImports = { export default defineConfig({ test: { - projects: ["packages/*", "scripts", ".github/scripts"], + projects: ["packages/*", "scripts"], }, staged: { "*": "vp check --fix", From 8cfa669d62502c9eafedbd7f3cce21eb92ca2392 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:03:34 -0600 Subject: [PATCH 05/10] Split the image tags into an array read -ra splits TAGS explicitly, so the push and verify steps quote every use and need no ShellCheck exception. --- .github/workflows/build_docker.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 9b23b94b7..942cd8427 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -87,13 +87,12 @@ jobs: env: IMAGE: ${{ steps.login-ecr-public.outputs.registry }}/neptune/graph-explorer TAGS: ${{ steps.get-image-tags.outputs.tags }} - # TAGS is a space-separated list, split on purpose. + # TAGS is a space-separated list. run: | - # shellcheck disable=SC2086 - set -- $TAGS - docker build -t "$IMAGE:$1" . - for tag in "$@"; do - docker tag "$IMAGE:$1" "$IMAGE:$tag" + read -ra tags <<< "$TAGS" + docker build -t "$IMAGE:${tags[0]}" . + for tag in "${tags[@]}"; do + docker tag "$IMAGE:${tags[0]}" "$IMAGE:$tag" docker push "$IMAGE:$tag" done @@ -102,5 +101,5 @@ jobs: env: TAGS: ${{ steps.get-image-tags.outputs.tags }} run: | - # shellcheck disable=SC2086 - node scripts/releaseImage.ts verify $TAGS + read -ra tags <<< "$TAGS" + node scripts/releaseImage.ts verify "${tags[@]}" From abd27ac885d10bfb9761ae427185f254f3c4ccc5 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:10:40 -0600 Subject: [PATCH 06/10] Name the release image once The workflow sets IMAGE for the whole job, and scripts/releaseImage.ts reads it instead of its own copy. testing.md goes back to main's wording, which already lists scripts. --- .github/workflows/build_docker.yml | 3 +- docs/agents/testing.md | 2 +- scripts/releaseImage.test.ts | 40 +++++++++++++++++++---- scripts/releaseImage.ts | 51 +++++++++++++++++++++++------- 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 942cd8427..366d8580a 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -38,6 +38,8 @@ jobs: timeout-minutes: 20 env: IS_RELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.image_tag == 'release' }} + # Where every step pushes and reads, including scripts/releaseImage.ts. + IMAGE: public.ecr.aws/neptune/graph-explorer steps: - name: Checkout @@ -85,7 +87,6 @@ jobs: - name: Build, tag, and push Docker image env: - IMAGE: ${{ steps.login-ecr-public.outputs.registry }}/neptune/graph-explorer TAGS: ${{ steps.get-image-tags.outputs.tags }} # TAGS is a space-separated list. run: | diff --git a/docs/agents/testing.md b/docs/agents/testing.md index a423bfcca..7c03ca922 100644 --- a/docs/agents/testing.md +++ b/docs/agents/testing.md @@ -4,7 +4,7 @@ Vitest. Tests co-locate with source as `*.test.ts` (or `*.test.tsx` for componen ## Where tests live -Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*` and `scripts`, the repository's own Node scripts, including the ones the release workflows run. A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. +Vitest collects only the projects listed in `test.projects` of the root `vite.config.ts`, currently `packages/*` and `scripts`, the repository's own Node scripts. A test file outside those is never collected, and `vp test` still reports green, so adding a new top-level test directory means giving it a `vite.config.ts` and adding it to that list. Each project sets up its own environment. `setupTests.ts` below is registered by `packages/graph-explorer` only. `packages/graph-explorer-proxy-server` has its own setup file, and `packages/shared` has no setup file, so any tests added there must reset their own mocks. diff --git a/scripts/releaseImage.test.ts b/scripts/releaseImage.test.ts index 37488d64d..58df91b67 100644 --- a/scripts/releaseImage.test.ts +++ b/scripts/releaseImage.test.ts @@ -4,9 +4,12 @@ import { checkOneDigest, fetchDigests, fetchPublishedTags, + parseImage, planRelease, } from "./releaseImage.ts"; +const image = "public.ecr.aws/neptune/graph-explorer"; + const publishedTags = [ "latest", "sagemaker-latest", @@ -185,6 +188,27 @@ describe("checkOneDigest", () => { }); }); +describe("parseImage", () => { + it("splits an image into the registry URL and repository", () => { + expect(parseImage(image)).toStrictEqual({ + registry: "https://public.ecr.aws", + repository: "neptune/graph-explorer", + }); + }); + + it.each([ + "", + "graph-explorer", + "public.ecr.aws/", + "/neptune/graph-explorer", + "public.ecr.aws/neptune/graph-explorer:latest", + ])("rejects %j", value => { + expect(() => parseImage(value)).toThrow( + "IMAGE must be / with no tag", + ); + }); +}); + describe("registry reads", () => { afterEach(() => { vi.useRealTimers(); @@ -225,7 +249,7 @@ describe("registry reads", () => { () => Response.json({ tags: ["sagemaker-3.3.2"] }), }); - await expect(fetchPublishedTags()).resolves.toStrictEqual([ + await expect(fetchPublishedTags(image)).resolves.toStrictEqual([ "3.3.2", "latest", "sagemaker-3.3.2", @@ -239,7 +263,7 @@ describe("registry reads", () => { Response.json({ tags: [3] }), }); - await expect(fetchPublishedTags()).rejects.toThrow( + await expect(fetchPublishedTags(image)).rejects.toThrow( "The registry returned a tag list without a list of tags.", ); }); @@ -251,7 +275,7 @@ describe("registry reads", () => { new Response("busy", { status: 503 }), }); - await expect(fetchPublishedTags()).rejects.toThrow( + await expect(fetchPublishedTags(image)).rejects.toThrow( "GET https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000 returned 503.", ); }); @@ -267,7 +291,9 @@ describe("registry reads", () => { new Response(null, { status: 404 }), }); - await expect(fetchDigests(["3.3.2", "3.3.3"])).resolves.toStrictEqual( + await expect( + fetchDigests(image, ["3.3.2", "3.3.3"]), + ).resolves.toStrictEqual( new Map([ ["3.3.2", "sha256:aaa"], ["3.3.3", null], @@ -289,7 +315,7 @@ describe("registry reads", () => { new Response(null, { status: 500 }), }); - await expect(fetchDigests(["latest"])).rejects.toThrow( + await expect(fetchDigests(image, ["latest"])).rejects.toThrow( "HEAD https://public.ecr.aws/v2/neptune/graph-explorer/manifests/latest returned 500.", ); }); @@ -303,7 +329,7 @@ describe("registry reads", () => { Response.json({ tags: ["3.3.2"] }, { status: statuses.shift() }), }); - const tags = fetchPublishedTags(); + const tags = fetchPublishedTags(image); await vi.runAllTimersAsync(); await expect(tags).resolves.toStrictEqual(["3.3.2"]); @@ -318,7 +344,7 @@ describe("registry reads", () => { new Response(null, { status: 429 }), }); - const failure = fetchPublishedTags().catch((error: unknown) => error); + const failure = fetchPublishedTags(image).catch((error: unknown) => error); await vi.runAllTimersAsync(); expect(await failure).toStrictEqual( diff --git a/scripts/releaseImage.ts b/scripts/releaseImage.ts index 56e21ea0e..80e75e334 100644 --- a/scripts/releaseImage.ts +++ b/scripts/releaseImage.ts @@ -3,13 +3,31 @@ * them afterwards. It has no dependencies, so the workflow runs it with plain * Node and no install. * - * node scripts/releaseImage.ts plan - * node scripts/releaseImage.ts verify ... + * IMAGE=/ node scripts/releaseImage.ts plan + * IMAGE=/ node scripts/releaseImage.ts verify ... */ import { appendFileSync, readFileSync } from "node:fs"; -const registry = "https://public.ecr.aws"; -const repository = "neptune/graph-explorer"; +/** + * An image reference without a tag, such as + * `public.ecr.aws/neptune/graph-explorer`, split into the registry's base URL + * and the repository path. + */ +export function parseImage(image: string): { + registry: string; + repository: string; +} { + const slash = image.indexOf("/"); + if (slash <= 0 || slash === image.length - 1 || image.includes(":")) { + throw new Error( + `IMAGE must be / with no tag, but it is "${image}".`, + ); + } + return { + registry: `https://${image.slice(0, slash)}`, + repository: image.slice(slash + 1), + }; +} /** * Checks a release's inputs and returns the tags to push, in push order. @@ -93,15 +111,16 @@ export function checkOneDigest( } /** Every tag in the public repository, read anonymously. */ -export async function fetchPublishedTags(): Promise { - const headers = await anonymousAuth(); +export async function fetchPublishedTags(image: string): Promise { + const { registry, repository } = parseImage(image); + const headers = await anonymousAuth(registry); const tags: string[] = []; let url: string | null = `${registry}/v2/${repository}/tags/list?n=1000`; while (url) { const response = await request(url, { headers }); const body: unknown = await response.json(); tags.push(...parseTagList(body)); - url = nextPage(response.headers.get("Link")); + url = nextPage(response.headers.get("Link"), registry); } return tags; } @@ -111,10 +130,12 @@ export async function fetchPublishedTags(): Promise { * one tag at a time, since the registry throttles bursts of anonymous reads. */ export async function fetchDigests( + image: string, tags: readonly string[], ): Promise> { + const { registry, repository } = parseImage(image); const headers = { - ...(await anonymousAuth()), + ...(await anonymousAuth(registry)), Accept: [ "application/vnd.oci.image.index.v1+json", "application/vnd.oci.image.manifest.v1+json", @@ -139,7 +160,9 @@ export async function fetchDigests( return digests; } -async function anonymousAuth(): Promise<{ Authorization: string }> { +async function anonymousAuth( + registry: string, +): Promise<{ Authorization: string }> { const response = await request(`${registry}/token/`, {}); const body: unknown = await response.json(); if ( @@ -190,7 +213,7 @@ function parseTagList(body: unknown): string[] { throw new Error("The registry returned a tag list without a list of tags."); } -function nextPage(link: string | null): string | null { +function nextPage(link: string | null, registry: string): string | null { const match = link?.match(/<([^>]+)>;\s*rel="next"/); return match ? new URL(match[1], registry).href : null; } @@ -217,6 +240,10 @@ function writeOutput(name: string, value: string): void { } async function main([command, ...args]: string[]): Promise { + const image = process.env.IMAGE; + if (!image) { + throw new Error("IMAGE is not set."); + } if (command === "plan") { const ref = process.env.GITHUB_REF; if (!ref) { @@ -225,13 +252,13 @@ async function main([command, ...args]: string[]): Promise { const tags = planRelease({ ref, version: readPackageVersion(), - publishedTags: await fetchPublishedTags(), + publishedTags: await fetchPublishedTags(image), }); writeOutput("tags", tags.join(" ")); return; } if (command === "verify" && args.length > 0) { - const digest = checkOneDigest(await fetchDigests(args)); + const digest = checkOneDigest(await fetchDigests(image, args)); process.stdout.write(`${args.join(", ")} all point to ${digest}\n`); return; } From 9f247b81813e38ece0317cdfbb0202e423942b6b Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:24:58 -0600 Subject: [PATCH 07/10] Check that the registry retry waits before asking again Layer: check-release-image-publish --- scripts/releaseImage.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/releaseImage.test.ts b/scripts/releaseImage.test.ts index 58df91b67..f154f9318 100644 --- a/scripts/releaseImage.test.ts +++ b/scripts/releaseImage.test.ts @@ -322,18 +322,27 @@ describe("registry reads", () => { it("waits out throttling and asks again", async () => { vi.useFakeTimers(); + const tagListUrl = + "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000"; const statuses = [429, 429, 200]; - stubRegistry({ + const fetchMock = stubRegistry({ ...tokenRoute, - "https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000": () => + [tagListUrl]: () => Response.json({ tags: ["3.3.2"] }, { status: statuses.shift() }), }); + function tagListCalls() { + return fetchMock.mock.calls.filter(([url]) => url === tagListUrl).length; + } const tags = fetchPublishedTags(image); + await vi.advanceTimersByTimeAsync(999); + expect(tagListCalls()).toBe(1); + await vi.advanceTimersByTimeAsync(1); + expect(tagListCalls()).toBe(2); await vi.runAllTimersAsync(); await expect(tags).resolves.toStrictEqual(["3.3.2"]); - expect(statuses).toStrictEqual([]); + expect(tagListCalls()).toBe(3); }); it("gives up when throttling lasts", async () => { From a1007796a6f9f1fdcf4cc4cb354dd4d111b4a922 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:25:20 -0600 Subject: [PATCH 08/10] Assert whole errors in the release image tests Layer: check-release-image-publish --- scripts/releaseImage.test.ts | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/scripts/releaseImage.test.ts b/scripts/releaseImage.test.ts index f154f9318..1190d331f 100644 --- a/scripts/releaseImage.test.ts +++ b/scripts/releaseImage.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it, vi } from "vite-plus/test"; +import { afterEach, describe, expect, it, type Mock, vi } from "vite-plus/test"; import { checkOneDigest, @@ -105,7 +105,9 @@ describe("planRelease", () => { publishedTags, }), ).toThrow( - "Release runs must start from the tag v3.4.0, but this run is on refs/heads/main.", + new Error( + "Release runs must start from the tag v3.4.0, but this run is on refs/heads/main.", + ), ); }); @@ -117,7 +119,9 @@ describe("planRelease", () => { publishedTags, }), ).toThrow( - "Release runs must start from the tag v3.4.0, but this run is on refs/tags/v3.4.1.", + new Error( + "Release runs must start from the tag v3.4.0, but this run is on refs/tags/v3.4.1.", + ), ); }); @@ -128,7 +132,7 @@ describe("planRelease", () => { version: "3.3.2", publishedTags: ["latest", "3.3.2"], }), - ).toThrow("3.3.2 is already published."); + ).toThrow(new Error("3.3.2 is already published.")); }); it("fails when only the sagemaker tag of the version is published", () => { @@ -138,7 +142,7 @@ describe("planRelease", () => { version: "3.5.0", publishedTags: ["sagemaker-3.5.0"], }), - ).toThrow("sagemaker-3.5.0 is already published."); + ).toThrow(new Error("sagemaker-3.5.0 is already published.")); }); it.each(["3.4.0-beta.1", "3.4", "v3.4.0", "03.4.0", "3.4.0.1", ""])( @@ -146,7 +150,9 @@ describe("planRelease", () => { version => { expect(() => planRelease({ ref: `refs/tags/v${version}`, version, publishedTags }), - ).toThrow(`The package.json version "${version}" is not X.Y.Z.`); + ).toThrow( + new Error(`The package.json version "${version}" is not X.Y.Z.`), + ); }, ); }); @@ -172,7 +178,9 @@ describe("checkOneDigest", () => { ]), ), ).toThrow( - "The pushed tags point to more than one image: 3.4.0 sha256:aaa, latest sha256:bbb.", + new Error( + "The pushed tags point to more than one image: 3.4.0 sha256:aaa, latest sha256:bbb.", + ), ); }); @@ -184,7 +192,7 @@ describe("checkOneDigest", () => { ["sagemaker-3.4.0", null], ]), ), - ).toThrow("sagemaker-3.4.0 is not in the registry."); + ).toThrow(new Error("sagemaker-3.4.0 is not in the registry.")); }); }); @@ -204,7 +212,9 @@ describe("parseImage", () => { "public.ecr.aws/neptune/graph-explorer:latest", ])("rejects %j", value => { expect(() => parseImage(value)).toThrow( - "IMAGE must be / with no tag", + new Error( + `IMAGE must be / with no tag, but it is "${value}".`, + ), ); }); }); @@ -214,9 +224,7 @@ describe("registry reads", () => { vi.useRealTimers(); }); - function stubRegistry( - routes: Record Response>, - ): ReturnType { + function stubRegistry(routes: Record Response>): Mock { const fetchMock = vi.fn((input: string | URL) => { const url = String(input); const route = routes[url]; @@ -264,7 +272,7 @@ describe("registry reads", () => { }); await expect(fetchPublishedTags(image)).rejects.toThrow( - "The registry returned a tag list without a list of tags.", + new Error("The registry returned a tag list without a list of tags."), ); }); @@ -276,7 +284,9 @@ describe("registry reads", () => { }); await expect(fetchPublishedTags(image)).rejects.toThrow( - "GET https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000 returned 503.", + new Error( + "GET https://public.ecr.aws/v2/neptune/graph-explorer/tags/list?n=1000 returned 503.", + ), ); }); @@ -316,7 +326,9 @@ describe("registry reads", () => { }); await expect(fetchDigests(image, ["latest"])).rejects.toThrow( - "HEAD https://public.ecr.aws/v2/neptune/graph-explorer/manifests/latest returned 500.", + new Error( + "HEAD https://public.ecr.aws/v2/neptune/graph-explorer/manifests/latest returned 500.", + ), ); }); From 4531cfb47f7da2f48f3b43c6652491f48259bdf0 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:25:49 -0600 Subject: [PATCH 09/10] Share the string field check and find package.json from the script Layer: check-release-image-publish --- scripts/releaseImage.ts | 43 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/scripts/releaseImage.ts b/scripts/releaseImage.ts index 80e75e334..69b4107d8 100644 --- a/scripts/releaseImage.ts +++ b/scripts/releaseImage.ts @@ -7,6 +7,7 @@ * IMAGE=/ node scripts/releaseImage.ts verify ... */ import { appendFileSync, readFileSync } from "node:fs"; +import { join } from "node:path"; /** * An image reference without a tag, such as @@ -164,16 +165,12 @@ async function anonymousAuth( registry: string, ): Promise<{ Authorization: string }> { const response = await request(`${registry}/token/`, {}); - const body: unknown = await response.json(); - if ( - typeof body !== "object" || - body === null || - !("token" in body) || - typeof body.token !== "string" - ) { - throw new Error("The registry returned no anonymous token."); - } - return { Authorization: `Bearer ${body.token}` }; + const token = stringField( + await response.json(), + "token", + "The registry returned no anonymous token.", + ); + return { Authorization: `Bearer ${token}` }; } const throttleRetryDelaysMs = [1000, 2000, 4000, 8000]; @@ -219,16 +216,24 @@ function nextPage(link: string | null, registry: string): string | null { } function readPackageVersion(): string { - const body: unknown = JSON.parse(readFileSync("package.json", "utf8")); - if ( - typeof body !== "object" || - body === null || - !("version" in body) || - typeof body.version !== "string" - ) { - throw new Error("package.json has no version."); + const path = join(import.meta.dirname, "..", "package.json"); + return stringField( + JSON.parse(readFileSync(path, "utf8")), + "version", + "package.json has no version.", + ); +} + +/** The string at `body[key]`, or throws `message` when there isn't one. */ +function stringField(body: unknown, key: string, message: string): string { + const value: unknown = + typeof body === "object" && body !== null + ? Reflect.get(body, key) + : undefined; + if (typeof value === "string") { + return value; } - return body.version; + throw new Error(message); } function writeOutput(name: string, value: string): void { From eccd38f4f09dcbd909522c5815a24f38b0a28687 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Mon, 16 Nov 2026 20:26:04 -0600 Subject: [PATCH 10/10] Take the snapshot tags as the plan's fallback Layer: check-release-image-publish --- .github/workflows/build_docker.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 366d8580a..4d86f6459 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -6,7 +6,9 @@ name: Build Docker image and publish to ECR # gh workflow run build_docker.yml --ref v -f image_tag=release # # The release check fails the run unless the tag matches package.json and the -# version is new, and it moves latest only for the highest version. +# version is new, and it moves latest only for the highest version. Start one +# release at a time: two runs started together can both pass the check before +# either pushes. on: workflow_dispatch: @@ -58,17 +60,6 @@ jobs: if: ${{ env.IS_RELEASE == 'true' }} run: node scripts/releaseImage.ts plan - - name: Get image tags - id: get-image-tags - env: - RELEASE_TAGS: ${{ steps.release.outputs.tags }} - run: | - if [ "$IS_RELEASE" = "true" ]; then - echo "tags=$RELEASE_TAGS" >> "$GITHUB_OUTPUT" - else - echo "tags=latest-SNAPSHOT sagemaker-latest-SNAPSHOT" >> "$GITHUB_OUTPUT" - fi - - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0 with: @@ -87,7 +78,8 @@ jobs: - name: Build, tag, and push Docker image env: - TAGS: ${{ steps.get-image-tags.outputs.tags }} + # Snapshot runs skip the plan, so they push the snapshot tags. + TAGS: ${{ steps.release.outputs.tags || 'latest-SNAPSHOT sagemaker-latest-SNAPSHOT' }} # TAGS is a space-separated list. run: | read -ra tags <<< "$TAGS" @@ -100,7 +92,7 @@ jobs: - name: Check every pushed tag points to one image if: ${{ env.IS_RELEASE == 'true' }} env: - TAGS: ${{ steps.get-image-tags.outputs.tags }} + TAGS: ${{ steps.release.outputs.tags }} run: | read -ra tags <<< "$TAGS" node scripts/releaseImage.ts verify "${tags[@]}"