mirror of
https://github.com/supabase/setup-cli.git
synced 2026-06-28 18:06:59 +00:00
Compare commits
1 Commits
v2.0.1
...
claude/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b235d82dcd |
126
src/main.test.ts
126
src/main.test.ts
@@ -156,16 +156,16 @@ function createActionSpies(inputVersion: string, cliDir: string, expectedUrlFrag
|
||||
return path.join(os.tmpdir(), "supabase-cli.tar.gz");
|
||||
}),
|
||||
extractTar: spyOn(tc, "extractTar").mockImplementation(async () => cliDir),
|
||||
extractZip: spyOn(tc, "extractZip").mockImplementation(async () => cliDir),
|
||||
};
|
||||
}
|
||||
|
||||
function mockLatestRelease(version = "v2.99.0") {
|
||||
return spyOn(globalThis, "fetch").mockResolvedValue(
|
||||
new Response(JSON.stringify({ tag_name: version }), {
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
}),
|
||||
function mockLatestRelease(version: string) {
|
||||
const response = new Response(null, {
|
||||
status: 302,
|
||||
headers: { location: `https://github.com/supabase/cli/releases/tag/v${version}` },
|
||||
});
|
||||
return spyOn(globalThis, "fetch").mockImplementation(
|
||||
(async () => response) as unknown as typeof fetch,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -177,55 +177,10 @@ async function getMainModule(): Promise<typeof import("./main.ts")> {
|
||||
return mainModule;
|
||||
}
|
||||
|
||||
test("uses versioned tar archives for Supabase CLI v2.99.0 and later", async () => {
|
||||
const { getDownloadArchive } = await getMainModule();
|
||||
|
||||
const archive = await getDownloadArchive("2.99.0", "linux", "x64");
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: "https://github.com/supabase/cli/releases/download/v2.99.0/supabase_2.99.0_linux_amd64.tar.gz",
|
||||
format: "tar",
|
||||
});
|
||||
});
|
||||
|
||||
test("keeps the unversioned tar archive layout before Supabase CLI v2.99.0", async () => {
|
||||
const { getDownloadArchive } = await getMainModule();
|
||||
|
||||
const archive = await getDownloadArchive("2.98.2", "linux", "x64");
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: "https://github.com/supabase/cli/releases/download/v2.98.2/supabase_linux_amd64.tar.gz",
|
||||
format: "tar",
|
||||
});
|
||||
});
|
||||
|
||||
test("uses versioned zip archives for Windows Supabase CLI v2.99.0 and later", async () => {
|
||||
const { getDownloadArchive } = await getMainModule();
|
||||
|
||||
const archive = await getDownloadArchive("2.99.0", "win32", "x64");
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: "https://github.com/supabase/cli/releases/download/v2.99.0/supabase_2.99.0_windows_amd64.zip",
|
||||
format: "zip",
|
||||
});
|
||||
});
|
||||
|
||||
test("resolves latest before choosing a versioned Supabase CLI archive", async () => {
|
||||
mockLatestRelease("v2.99.0");
|
||||
const { getDownloadArchive } = await getMainModule();
|
||||
|
||||
const archive = await getDownloadArchive("latest", "darwin", "arm64");
|
||||
|
||||
expect(archive).toEqual({
|
||||
url: "https://github.com/supabase/cli/releases/download/v2.99.0/supabase_2.99.0_darwin_arm64.tar.gz",
|
||||
format: "tar",
|
||||
});
|
||||
});
|
||||
|
||||
test("awaits the action entrypoint with omitted version and latest fallback", async () => {
|
||||
process.env.GITHUB_WORKSPACE = repo;
|
||||
mockLatestRelease();
|
||||
const cliDir = createFakeCli("supabase 2.84.2");
|
||||
mockLatestRelease("2.84.2");
|
||||
let startDownload!: () => void;
|
||||
let finishDownload!: () => void;
|
||||
const downloadStarted = new Promise<void>((resolve) => {
|
||||
@@ -241,12 +196,11 @@ test("awaits the action entrypoint with omitted version and latest fallback", as
|
||||
exportVariable: spyOn(core, "exportVariable").mockImplementation(() => {}),
|
||||
setFailed: spyOn(core, "setFailed").mockImplementation(() => {}),
|
||||
downloadTool: spyOn(tc, "downloadTool").mockImplementation(async (url: string) => {
|
||||
expect(url).toContain("/download/v2.99.0/supabase_2.99.0_");
|
||||
expect(url).toContain("/download/v2.84.2/supabase_");
|
||||
startDownload();
|
||||
return downloadFinished;
|
||||
}),
|
||||
extractTar: spyOn(tc, "extractTar").mockImplementation(async () => cliDir),
|
||||
extractZip: spyOn(tc, "extractZip").mockImplementation(async () => cliDir),
|
||||
};
|
||||
const originalArgv1 = process.argv[1];
|
||||
process.argv[1] = defaultEntrypoint;
|
||||
@@ -340,9 +294,9 @@ test("falls back to latest when version is omitted and no supported root lockfil
|
||||
process.env.GITHUB_WORKSPACE = createWorkspace({
|
||||
"README.md": "# app\n",
|
||||
});
|
||||
mockLatestRelease();
|
||||
const cliDir = createFakeCli("supabase 2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
mockLatestRelease("2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.84.2/supabase_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
@@ -354,9 +308,9 @@ test("falls back to latest when version is omitted and no supported root lockfil
|
||||
|
||||
test("falls back to latest when version is omitted and no workspace is available", async () => {
|
||||
delete process.env.GITHUB_WORKSPACE;
|
||||
mockLatestRelease();
|
||||
const cliDir = createFakeCli("supabase 2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
mockLatestRelease("2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.84.2/supabase_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
@@ -419,9 +373,9 @@ test("falls through unreadable bun.lock paths and malformed package-lock files t
|
||||
});
|
||||
mkdirSync(path.join(workspace, "bun.lock"), { recursive: true });
|
||||
process.env.GITHUB_WORKSPACE = workspace;
|
||||
mockLatestRelease();
|
||||
const cliDir = createFakeCli("supabase 2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
mockLatestRelease("2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.84.2/supabase_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
@@ -435,9 +389,9 @@ test("falls back to latest when a pnpm dependency entry has no concrete version"
|
||||
process.env.GITHUB_WORKSPACE = createWorkspace({
|
||||
"pnpm-lock.yaml": createPnpmLock("2.49.0", { includeVersion: false }),
|
||||
});
|
||||
mockLatestRelease();
|
||||
const cliDir = createFakeCli("supabase 2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
mockLatestRelease("2.84.2");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.84.2/supabase_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
@@ -462,6 +416,52 @@ test("explicit version overrides detected root lockfiles", async () => {
|
||||
expect(spies.setFailed).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("downloads the version-prefixed tarball for releases >= 2.99.0", async () => {
|
||||
// Regression for supabase/cli#5257: from v2.99.0 onward the CLI only
|
||||
// publishes supabase_<version>_<platform>_<arch>.tar.gz; the unversioned
|
||||
// alias is gone.
|
||||
delete process.env.GITHUB_WORKSPACE;
|
||||
const cliDir = createFakeCli("supabase 2.99.0");
|
||||
mockLatestRelease("2.99.0");
|
||||
const spies = createActionSpies("", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
|
||||
expect(spies.setOutput).toHaveBeenCalledWith("version", "supabase 2.99.0");
|
||||
expect(spies.exportVariable).toHaveBeenCalledWith(CLI_CONFIG_REGISTRY, "ghcr.io");
|
||||
expect(spies.setFailed).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("downloads the version-prefixed tarball when explicit version >= 2.99.0 is requested", async () => {
|
||||
delete process.env.GITHUB_WORKSPACE;
|
||||
const cliDir = createFakeCli("supabase 2.99.0");
|
||||
const fetchSpy = spyOn(globalThis, "fetch");
|
||||
const spies = createActionSpies("2.99.0", cliDir, "/download/v2.99.0/supabase_2.99.0_");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
expect(spies.setOutput).toHaveBeenCalledWith("version", "supabase 2.99.0");
|
||||
expect(spies.exportVariable).toHaveBeenCalledWith(CLI_CONFIG_REGISTRY, "ghcr.io");
|
||||
expect(spies.setFailed).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("fails when the latest release redirect does not include a version tag", async () => {
|
||||
delete process.env.GITHUB_WORKSPACE;
|
||||
const cliDir = createFakeCli("supabase 2.99.0");
|
||||
const response = new Response(null, { status: 302, headers: { location: "/releases" } });
|
||||
spyOn(globalThis, "fetch").mockImplementation((async () => response) as unknown as typeof fetch);
|
||||
const spies = createActionSpies("", cliDir, "/download/");
|
||||
const { run } = await getMainModule();
|
||||
|
||||
await run();
|
||||
|
||||
expect(spies.downloadTool).not.toHaveBeenCalled();
|
||||
expect(spies.setFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("fails when the installed CLI does not report a version", async () => {
|
||||
process.env.GITHUB_WORKSPACE = createWorkspace({
|
||||
"package-lock.json": createPackageLock("2.46.0"),
|
||||
|
||||
123
src/main.ts
123
src/main.ts
@@ -7,16 +7,12 @@ import { fileURLToPath } from "node:url";
|
||||
|
||||
export const CLI_CONFIG_REGISTRY = "SUPABASE_INTERNAL_IMAGE_REGISTRY";
|
||||
const REGISTRY_VERSION = "1.28.0";
|
||||
// Starting with this release, the CLI publishes only version-prefixed tarballs
|
||||
// (e.g. supabase_2.99.0_linux_amd64.tar.gz); the unversioned aliases that used
|
||||
// to live alongside them are no longer uploaded. See supabase/cli#5257.
|
||||
const VERSIONED_ARCHIVE_VERSION = "2.99.0";
|
||||
const DEFAULT_VERSION = "latest";
|
||||
const GITHUB_RELEASES_API = "https://api.github.com/repos/supabase/cli/releases/latest";
|
||||
|
||||
type ArchiveFormat = "tar" | "zip";
|
||||
|
||||
type DownloadArchive = {
|
||||
url: string;
|
||||
format: ArchiveFormat;
|
||||
};
|
||||
const LATEST_RELEASE_URL = "https://github.com/supabase/cli/releases/latest";
|
||||
|
||||
type BunLock = {
|
||||
workspaces?: {
|
||||
@@ -65,10 +61,6 @@ function extractConcreteVersion(raw: string | undefined): string | null {
|
||||
return match?.[0] ?? null;
|
||||
}
|
||||
|
||||
function normalizeVersion(version: string): string {
|
||||
return version.replace(/^v/i, "");
|
||||
}
|
||||
|
||||
function readWorkspaceLockfile(workspaceRoot: string, filename: string): string | null {
|
||||
const filePath = path.join(workspaceRoot, filename);
|
||||
|
||||
@@ -174,83 +166,40 @@ function resolveVersion(inputVersion: string): string {
|
||||
);
|
||||
}
|
||||
|
||||
async function resolveLatestVersion(): Promise<string> {
|
||||
const response = await fetch(GITHUB_RELEASES_API);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to resolve latest Supabase CLI release: ${response.statusText}`);
|
||||
export async function resolveLatestVersion(): Promise<string> {
|
||||
const response = await fetch(LATEST_RELEASE_URL, { method: "HEAD", redirect: "manual" });
|
||||
const location = response.headers.get("location");
|
||||
const version = extractConcreteVersion(location ?? undefined);
|
||||
|
||||
if (!version) {
|
||||
throw new Error(
|
||||
`Could not resolve latest Supabase CLI version (status ${response.status}, location ${location ?? "<none>"})`,
|
||||
);
|
||||
}
|
||||
|
||||
const release = (await response.json()) as { tag_name?: unknown };
|
||||
if (typeof release.tag_name !== "string") {
|
||||
throw new Error("Failed to resolve latest Supabase CLI release: missing tag name");
|
||||
}
|
||||
|
||||
return normalizeVersion(release.tag_name);
|
||||
return version;
|
||||
}
|
||||
|
||||
function getArchiveFormat(version: string, platform: NodeJS.Platform): ArchiveFormat {
|
||||
if (platform === "win32" && semver.order(version, VERSIONED_ARCHIVE_VERSION) >= 0) {
|
||||
return "zip";
|
||||
export function getDownloadUrl(version: string): string {
|
||||
const platform = getArchivePlatform(process.platform);
|
||||
const arch = getArchiveArch(process.arch);
|
||||
const versionedFilename = `supabase_${version}_${platform}_${arch}.tar.gz`;
|
||||
const unversionedFilename = `supabase_${platform}_${arch}.tar.gz`;
|
||||
|
||||
// v2.99.0+ and the earliest releases (pre-v1.28.0) only publish version-prefixed
|
||||
// tarballs; the intermediate releases publish unversioned aliases.
|
||||
if (
|
||||
semver.order(version, REGISTRY_VERSION) === -1 ||
|
||||
semver.order(version, VERSIONED_ARCHIVE_VERSION) >= 0
|
||||
) {
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${versionedFilename}`;
|
||||
}
|
||||
|
||||
return "tar";
|
||||
}
|
||||
|
||||
function getArchiveFilename(
|
||||
version: string,
|
||||
platform: NodeJS.Platform,
|
||||
arch: NodeJS.Architecture,
|
||||
): string {
|
||||
const archivePlatform = getArchivePlatform(platform);
|
||||
const archiveArch = getArchiveArch(arch);
|
||||
|
||||
if (semver.order(version, REGISTRY_VERSION) === -1) {
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.tar.gz`;
|
||||
}
|
||||
|
||||
if (semver.order(version, VERSIONED_ARCHIVE_VERSION) >= 0) {
|
||||
const extension = platform === "win32" ? "zip" : "tar.gz";
|
||||
return `supabase_${version}_${archivePlatform}_${archiveArch}.${extension}`;
|
||||
}
|
||||
|
||||
return `supabase_${archivePlatform}_${archiveArch}.tar.gz`;
|
||||
}
|
||||
|
||||
export async function getDownloadArchive(
|
||||
version: string,
|
||||
platform = process.platform,
|
||||
arch = process.arch,
|
||||
): Promise<DownloadArchive> {
|
||||
const resolvedVersion =
|
||||
version.toLowerCase() === "latest" ? await resolveLatestVersion() : normalizeVersion(version);
|
||||
const filename = getArchiveFilename(resolvedVersion, platform, arch);
|
||||
|
||||
return {
|
||||
url: `https://github.com/supabase/cli/releases/download/v${resolvedVersion}/${filename}`,
|
||||
format: getArchiveFormat(resolvedVersion, platform),
|
||||
};
|
||||
}
|
||||
|
||||
function getCliExecutablePath(cliPath: string): string {
|
||||
if (process.platform !== "win32") {
|
||||
return path.join(cliPath, "supabase");
|
||||
}
|
||||
|
||||
const exePath = path.join(cliPath, "supabase.exe");
|
||||
if (existsSync(exePath)) {
|
||||
return exePath;
|
||||
}
|
||||
|
||||
const cmdPath = path.join(cliPath, "supabase.cmd");
|
||||
if (existsSync(cmdPath)) {
|
||||
return cmdPath;
|
||||
}
|
||||
|
||||
return path.join(cliPath, "supabase");
|
||||
return `https://github.com/supabase/cli/releases/download/v${version}/${unversionedFilename}`;
|
||||
}
|
||||
|
||||
export async function determineInstalledVersion(cliPath: string): Promise<string> {
|
||||
const version = (await $`${getCliExecutablePath(cliPath)} --version`.text()).trim();
|
||||
const version = (await $`${path.join(cliPath, "supabase")} --version`.text()).trim();
|
||||
if (!version) {
|
||||
throw new Error("Could not determine installed Supabase CLI version");
|
||||
}
|
||||
@@ -260,18 +209,16 @@ export async function determineInstalledVersion(cliPath: string): Promise<string
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const version = resolveVersion(core.getInput("version"));
|
||||
const archive = await getDownloadArchive(version);
|
||||
const archivePath = await tc.downloadTool(archive.url);
|
||||
const cliPath =
|
||||
archive.format === "zip"
|
||||
? await tc.extractZip(archivePath)
|
||||
: await tc.extractTar(archivePath);
|
||||
const requestedVersion = resolveVersion(core.getInput("version"));
|
||||
const version =
|
||||
requestedVersion.toLowerCase() === "latest" ? await resolveLatestVersion() : requestedVersion;
|
||||
const tarball = await tc.downloadTool(getDownloadUrl(version));
|
||||
const cliPath = await tc.extractTar(tarball);
|
||||
const installedVersion = await determineInstalledVersion(cliPath);
|
||||
core.setOutput("version", installedVersion);
|
||||
core.addPath(cliPath);
|
||||
|
||||
if (version.toLowerCase() === "latest" || semver.order(version, REGISTRY_VERSION) >= 0) {
|
||||
if (semver.order(version, REGISTRY_VERSION) >= 0) {
|
||||
core.exportVariable(CLI_CONFIG_REGISTRY, "ghcr.io");
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user