Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions src/commandOutputParsing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { handleWranglerDeployOutputEntry } from "./commandOutputParsing";
import { setOutput } from "@actions/core";
import { WranglerActionConfig } from "./wranglerAction";
import { OutputEntryDeployment } from "./wranglerArtifactManager";

vi.mock("@actions/core");
vi.mock("./wranglerAction", () => ({
info: vi.fn(),
}));

describe("handleWranglerDeployOutputEntry", () => {
const mockConfig = {} as WranglerActionConfig;

beforeEach(() => {
vi.clearAllMocks();
});

it("should handle clean URL", () => {
const entry: OutputEntryDeployment = {
version: 1,
type: "deploy",
targets: ["https://example.com"],
};
handleWranglerDeployOutputEntry(mockConfig, entry);
expect(setOutput).toHaveBeenCalledWith("deployment-url", "https://example.com");
});

it("should handle URL without protocol", () => {
const entry: OutputEntryDeployment = {
version: 1,
type: "deploy",
targets: ["example.com"],
};
handleWranglerDeployOutputEntry(mockConfig, entry);
expect(setOutput).toHaveBeenCalledWith("deployment-url", "https://example.com");
});

it("should handle URL with extra text (custom domain)", () => {
const entry: OutputEntryDeployment = {
version: 1,
type: "deploy",
targets: ["example.com (custom domain)"],
};
handleWranglerDeployOutputEntry(mockConfig, entry);
expect(setOutput).toHaveBeenCalledWith("deployment-url", "https://example.com");
});

it("should handle URL with extra text and protocol", () => {
const entry: OutputEntryDeployment = {
version: 1,
type: "deploy",
targets: ["https://foo.bar (Custom)"],
};
handleWranglerDeployOutputEntry(mockConfig, entry);
expect(setOutput).toHaveBeenCalledWith("deployment-url", "https://foo.bar");
});

it("should take the first URL if multiple are present", () => {
const entry: OutputEntryDeployment = {
version: 1,
type: "deploy",
targets: ["https://primary.com", "https://secondary.com"],
};
handleWranglerDeployOutputEntry(mockConfig, entry);
expect(setOutput).toHaveBeenCalledWith("deployment-url", "https://primary.com");
});
});
25 changes: 23 additions & 2 deletions src/commandOutputParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function handlePagesDeployCommand(
setOutput("pages-deployment-alias-url", aliasUrl);
}

function handleWranglerDeployOutputEntry(
export function handleWranglerDeployOutputEntry(
config: WranglerActionConfig,
wranglerDeployOutputEntry: OutputEntryDeployment,
) {
Expand All @@ -89,7 +89,28 @@ function handleWranglerDeployOutputEntry(
);
}

setOutput("deployment-url", wranglerDeployOutputEntry.targets[0]);
let deploymentUrl = (wranglerDeployOutputEntry.targets?.[0] ?? "").trim();

// Clean up suffix annotations like "(...)"
deploymentUrl = deploymentUrl.replace(/\s*\([^)]*\)\s*$/, "");

// Add protocol if missing
if (deploymentUrl && !/^https?:\/\//i.test(deploymentUrl)) {
deploymentUrl = `https://${deploymentUrl}`;
}

// Validate
try {
const u = new URL(deploymentUrl);
deploymentUrl =
u.pathname === "/" && !u.search && !u.hash ? u.origin : u.toString();
} catch {
deploymentUrl = "";
}

if (deploymentUrl) {
setOutput("deployment-url", deploymentUrl);
}
}

/**
Expand Down