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
7 changes: 5 additions & 2 deletions infra/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "@cap/infra",
"type": "module",
"devDependencies": {
"sst": "3.17.14"
"sst": "3.17.14",
"vitest": "~2.1.9"
},
"scripts": {
"sst": "sst"
"sst": "sst",
"test": "vitest run"
},
"dependencies": {
"@pulumi/github": "^6.7.0",
Expand Down
13 changes: 3 additions & 10 deletions infra/sst.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference path="./.sst/platform/config.d.ts" />

import { parseStageName } from "./stage";

const GITHUB_ORG = "CapSoftware";
const _GITHUB_REPO = "Cap";
const _GITHUB_APP_ID = "1196731";
Expand All @@ -12,16 +14,7 @@ const _CLOUDFLARE_ACCOUNT_ID = "3de2dd633194481d80f68f55257bdbaa";
const AXIOM_API_TOKEN = "xaat-c0704be6-e942-4935-b068-3b491d7cc00f";
const AXIOM_DATASET = "cap-otel";

const parsedStage = () => {
if ($app.stage === "staging") return { variant: "staging" } as const;
if ($app.stage === "production") return { variant: "production" } as const;
if ($app.stage.startsWith("git-branch-"))
return {
variant: "git-branch",
branch: $app.stage.slice("git-branch-".length),
} as const;
throw new Error("Unsupported stage");
};
const parsedStage = () => parseStageName($app.stage);

export default $config({
app(input) {
Expand Down
21 changes: 21 additions & 0 deletions infra/stage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { parseStageName } from "./stage";

describe("parseStageName", () => {
it("recognizes fixed deployment stages", () => {
expect(parseStageName("staging")).toEqual({ variant: "staging" });
expect(parseStageName("production")).toEqual({ variant: "production" });
});

it("extracts branch names from git branch preview stages", () => {
expect(parseStageName("git-branch-add-infra-tests")).toEqual({
variant: "git-branch",
branch: "add-infra-tests",
});
});

it("rejects unsupported stages", () => {
expect(() => parseStageName("preview")).toThrow("Unsupported stage");
expect(() => parseStageName("git-branch-")).toThrow("Unsupported stage");
});
});
15 changes: 15 additions & 0 deletions infra/stage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type ParsedStage =
| { variant: "staging" }
| { variant: "production" }
| { variant: "git-branch"; branch: string };

export function parseStageName(stage: string): ParsedStage {
if (stage === "staging") return { variant: "staging" };
if (stage === "production") return { variant: "production" };
if (stage.startsWith("git-branch-")) {
const branch = stage.slice("git-branch-".length);
if (!branch) throw new Error("Unsupported stage");
return { variant: "git-branch", branch };
}
throw new Error("Unsupported stage");
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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