Skip to content

Commit 1cfd0a7

Browse files
scuttletobynoreplyclaude
authored
fork: the server and CLI update from the desktop app's repository (#1)
* fork: builds name the repository they update from (T3CODE_RELEASE_REPOSITORY) A build made with T3CODE_RELEASE_REPOSITORY=<owner>/<repo> lists, downloads and links releases only from that repository: the server's `t3 update`, the Update button's pinned-runtime download, the desktop app's SSH installs, and the desktop app's own electron-updater feed. Without the setting nothing changes (upstream pingdotgg/t3code). A malformed value fails the build instead of quietly falling back to upstream. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fork: a GitHub Actions build names the repository it runs in Without T3CODE_RELEASE_REPOSITORY, an Actions build takes GITHUB_REPOSITORY, as the desktop updater feed already does. Reusable workflows (release-desktop.yml re-bundles the server for the CLI executable) do not pass the caller's env on, so the explicit variable alone would let a fork's CLI archive name upstream. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fork: the server follows upstream's desktop update repository setting Review round 1: a second setting (T3CODE_RELEASE_REPOSITORY) with the opposite precedence let a build set only T3CODE_DESKTOP_UPDATE_REPOSITORY and ship a desktop app on the fork's feed with a server that updates from upstream. The server, CLI and desktop SSH installs now read upstream's own setting in upstream's order (T3CODE_DESKTOP_UPDATE_REPOSITORY, then GITHUB_REPOSITORY), so all three readers agree by construction, and the patch no longer touches build-desktop-artifact.ts or the web config's repository line. The former name is still accepted when it names the same repository and fails the build otherwise. A test checks the server's value against the desktop updater feed. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: t3code-fork <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent dc032d7 commit 1cfd0a7

9 files changed

Lines changed: 185 additions & 3 deletions

File tree

‎apps/desktop/vite.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defaultInclude, defineConfig } from "vite-plus";
55

66
import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
77
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
8+
import { releaseRepositoryDefine } from "../../scripts/lib/release-repository.ts";
89

910
const repoEnv = loadRepoEnv();
1011
const domTests = ["src/preview/PickPreload.test.ts"];
@@ -21,6 +22,7 @@ const devElectronCommand =
2122
? "node scripts/dev-electron.mjs"
2223
: "exec node scripts/dev-electron.mjs";
2324
const publicConfigDefine = {
25+
...releaseRepositoryDefine(),
2426
__T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
2527
repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
2628
),

‎apps/server/vite.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defineConfig, mergeConfig } from "vite-plus";
55

66
import baseConfig from "../../vite.config.ts";
77
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
8+
import { releaseRepositoryDefine } from "../../scripts/lib/release-repository.ts";
89
import rootPackageJson from "../../package.json" with { type: "json" };
910
import packageJson from "./package.json" with { type: "json" };
1011
import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
@@ -126,6 +127,7 @@ export default mergeConfig(
126127
js: "#!/usr/bin/env node\n",
127128
},
128129
define: {
130+
...releaseRepositoryDefine(),
129131
__T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel),
130132
__T3CODE_TELEMETRY_CHANNEL__: JSON.stringify(telemetryChannel),
131133
__T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""),

‎apps/web/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"scripts/verify-built-boot.ts",
3636
"scripts/warm-dep-cache.ts",
3737
"../../scripts/lib/public-config.ts",
38+
"../../scripts/lib/release-repository.ts",
3839
"../../scripts/lib/third-party-licenses.ts"
3940
]
4041
}

‎apps/web/vite.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "@t3tools/shared/devProxy";
2020

2121
import { loadRepoEnv } from "../../scripts/lib/public-config";
22+
import { releaseRepositoryDefine } from "../../scripts/lib/release-repository";
2223
import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
2324
import { tailwindPlugins } from "./vite/tailwind";
2425
import { warmBundledDevPlugin } from "./vite/warmBundledDev";
@@ -322,6 +323,7 @@ export default defineConfig(() => {
322323
],
323324
},
324325
define: {
326+
...releaseRepositoryDefine(),
325327
"import.meta.env.VITE_WS_URL": JSON.stringify(configuredWsUrl ?? ""),
326328
// Override .env URLs with empty values in single-origin dev so clients use window.location.origin.
327329
"import.meta.env.VITE_HTTP_URL": JSON.stringify(configuredHttpUrl ?? ""),

‎docs/operations/release.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ available.
477477
- Repository slug source:
478478
- `T3CODE_DESKTOP_UPDATE_REPOSITORY` (format `owner/repo`), if set.
479479
- otherwise `GITHUB_REPOSITORY` from GitHub Actions.
480+
- The server, `t3 update` and desktop SSH installs bake in the same slug (`scripts/lib/release-repository.ts`).
480481
- Required release assets for updater:
481482
- platform installers (`.exe`, `.dmg`, `.AppImage`, `.deb`, plus macOS `.zip` for Squirrel.Mac update payloads)
482483
- channel metadata: `latest*.yml` for stable releases, `nightly*.yml` for nightly releases

‎packages/shared/src/cliRelease.test.ts‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22

3-
import { cliArchiveTarCommand, newestCliReleaseVersion, parseChecksums } from "./cliRelease.ts";
3+
import {
4+
cliArchiveTarCommand,
5+
newestCliReleaseVersion,
6+
parseChecksums,
7+
resolveCliReleaseRepository,
8+
} from "./cliRelease.ts";
49

510
describe("cliRelease", () => {
611
it("parses sha256sum output including binary-mode markers", () => {
@@ -40,3 +45,43 @@ describe("cliRelease", () => {
4045
expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined();
4146
});
4247
});
48+
49+
describe("cliRelease repository", () => {
50+
afterEach(() => {
51+
vi.unstubAllGlobals();
52+
vi.resetModules();
53+
});
54+
55+
it("defaults to upstream when the build names no repository", () => {
56+
expect(resolveCliReleaseRepository(undefined)).toBe("pingdotgg/t3code");
57+
expect(resolveCliReleaseRepository("")).toBe("pingdotgg/t3code");
58+
expect(resolveCliReleaseRepository(" ")).toBe("pingdotgg/t3code");
59+
});
60+
61+
it("lists and downloads releases only from the repository the build names", async () => {
62+
vi.stubGlobal("__T3CODE_RELEASE_REPOSITORY__", "fork-owner/t3code");
63+
vi.resetModules();
64+
const release = await import("./cliRelease.ts");
65+
expect(release.cliReleaseIndexPageUrl(2)).toBe(
66+
"https://api.github.com/repos/fork-owner/t3code/releases?per_page=100&page=2",
67+
);
68+
expect(release.cliReleaseDownloadBaseUrl("0.1.9-fork.1")).toBe(
69+
"https://github.com/fork-owner/t3code/releases/download/v0.1.9-fork.1",
70+
);
71+
expect(release.cliReleaseAssetUrl("0.1.9-fork.1", "SHA256SUMS")).toBe(
72+
"https://github.com/fork-owner/t3code/releases/download/v0.1.9-fork.1/SHA256SUMS",
73+
);
74+
expect(release.CLI_RELEASES_PAGE_URL).toBe("https://github.com/fork-owner/t3code/releases");
75+
});
76+
77+
it("keeps upstream URLs in a build without the setting", async () => {
78+
vi.resetModules();
79+
const release = await import("./cliRelease.ts");
80+
expect(release.cliReleaseIndexPageUrl(1)).toBe(
81+
"https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1",
82+
);
83+
expect(release.cliReleaseDownloadBaseUrl("0.1.9")).toBe(
84+
"https://github.com/pingdotgg/t3code/releases/download/v0.1.9",
85+
);
86+
});
87+
});

‎packages/shared/src/cliRelease.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ import * as Schema from "effect/Schema";
33

44
import { compareSemverVersions } from "./semver.ts";
55

6-
const CLI_RELEASE_REPOSITORY = "pingdotgg/t3code";
6+
// Set at build time from T3CODE_DESKTOP_UPDATE_REPOSITORY (scripts/lib/release-repository.ts), the
7+
// desktop updater's setting, so a fork's builds list and download only the fork's releases.
8+
declare const __T3CODE_RELEASE_REPOSITORY__: string | undefined;
9+
const UPSTREAM_RELEASE_REPOSITORY = "pingdotgg/t3code";
10+
11+
/** The repository releases come from: the build's setting, or upstream when it has none. */
12+
export function resolveCliReleaseRepository(configured: string | undefined): string {
13+
return configured?.trim() || UPSTREAM_RELEASE_REPOSITORY;
14+
}
15+
16+
const CLI_RELEASE_REPOSITORY = resolveCliReleaseRepository(
17+
typeof __T3CODE_RELEASE_REPOSITORY__ === "undefined" ? undefined : __T3CODE_RELEASE_REPOSITORY__,
18+
);
719
export const CLI_RELEASES_PAGE_URL = `https://github.com/${CLI_RELEASE_REPOSITORY}/releases`;
820
export const CLI_RELEASE_CHECKSUMS_FILE = "SHA256SUMS";
921
export const CLI_RELEASE_BASE_URL_ENV = "T3CODE_RELEASE_BASE_URL";
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { it as effectIt } from "@effect/vitest";
2+
import * as ConfigProvider from "effect/ConfigProvider";
3+
import * as Effect from "effect/Effect";
4+
import { describe, expect, it } from "vite-plus/test";
5+
6+
import { resolveGitHubPublishConfig } from "../build-desktop-artifact.ts";
7+
import { releaseRepositoryDefine, resolveReleaseRepository } from "./release-repository.ts";
8+
9+
const desktopFeedRepository = (env: Record<string, string>) =>
10+
resolveGitHubPublishConfig("latest").pipe(
11+
Effect.map((config) => (config ? `${config.owner}/${config.repo}` : "")),
12+
Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))),
13+
);
14+
15+
describe("release repository build setting", () => {
16+
it("is empty (the upstream default) when unset or blank", () => {
17+
expect(resolveReleaseRepository({})).toBe("");
18+
expect(resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: " " })).toBe("");
19+
});
20+
21+
it("is upstream's desktop update setting, so the server follows the desktop feed", () => {
22+
const env = { T3CODE_DESKTOP_UPDATE_REPOSITORY: " some-owner/t3code " };
23+
expect(resolveReleaseRepository(env)).toBe("some-owner/t3code");
24+
expect(releaseRepositoryDefine(env)).toEqual({
25+
__T3CODE_RELEASE_REPOSITORY__: JSON.stringify("some-owner/t3code"),
26+
});
27+
});
28+
29+
it("names the repository a GitHub Actions build runs in, unless the setting overrides it", () => {
30+
const actions = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "fork-owner/t3code" };
31+
expect(resolveReleaseRepository(actions)).toBe("fork-owner/t3code");
32+
expect(
33+
resolveReleaseRepository({ ...actions, T3CODE_DESKTOP_UPDATE_REPOSITORY: "other/t3code" }),
34+
).toBe("other/t3code");
35+
});
36+
37+
effectIt.effect("names the same repository as the desktop updater feed for every setting", () =>
38+
Effect.gen(function* () {
39+
const cases: Array<Record<string, string>> = [
40+
{},
41+
{ T3CODE_DESKTOP_UPDATE_REPOSITORY: "fork-owner/t3code" },
42+
{ GITHUB_REPOSITORY: "fork-owner/t3code" },
43+
{ T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code", GITHUB_REPOSITORY: "b/t3code" },
44+
{ T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "b/t3code" },
45+
];
46+
for (const env of cases) {
47+
const feed = yield* desktopFeedRepository(env);
48+
expect(resolveReleaseRepository(env), JSON.stringify(env)).toBe(feed);
49+
}
50+
}),
51+
);
52+
53+
it("fails the build when the former setting disagrees with the desktop updater's", () => {
54+
for (const env of [
55+
{ T3CODE_RELEASE_REPOSITORY: "fork-owner/t3code" },
56+
{ T3CODE_RELEASE_REPOSITORY: "b/t3code", T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code" },
57+
{ T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "a/t3code" },
58+
]) {
59+
expect(() => resolveReleaseRepository(env), JSON.stringify(env)).toThrow(
60+
/T3CODE_RELEASE_REPOSITORY=".+" disagrees.*Set T3CODE_DESKTOP_UPDATE_REPOSITORY/,
61+
);
62+
}
63+
});
64+
65+
it("fails the build on a malformed value instead of falling back to upstream", () => {
66+
for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) {
67+
expect(() => resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: value })).toThrow(
68+
/T3CODE_DESKTOP_UPDATE_REPOSITORY/,
69+
);
70+
}
71+
});
72+
});

‎scripts/lib/release-repository.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* The repository a build updates from, for the server, CLI and desktop SSH installs. It is the one
3+
* upstream already uses for the desktop updater feed and release links (docs/operations/release.md):
4+
* T3CODE_DESKTOP_UPDATE_REPOSITORY, else GITHUB_REPOSITORY, else "" for upstream.
5+
*/
6+
export const RELEASE_REPOSITORY_ENV = "T3CODE_DESKTOP_UPDATE_REPOSITORY";
7+
// The setting's first name in this fork; still accepted only when it names the same repository.
8+
const FORMER_RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY";
9+
10+
const SEGMENT = /^[A-Za-z0-9._-]+$/u;
11+
12+
function isValidSegment(value: string | undefined): value is string {
13+
return value !== undefined && value !== "." && value !== ".." && SEGMENT.test(value);
14+
}
15+
16+
/** The configured repository, or "" for the upstream default. Throws on a malformed value or a
17+
* disagreeing former setting, so no build ships the desktop and the server on different feeds. */
18+
export function resolveReleaseRepository(
19+
env: Readonly<Record<string, string | undefined>> = process.env,
20+
): string {
21+
// The same order as apps/web/vite.config.ts and resolveGitHubPublishConfig read them.
22+
const configured = env[RELEASE_REPOSITORY_ENV]?.trim() || env.GITHUB_REPOSITORY?.trim() || "";
23+
const former = env[FORMER_RELEASE_REPOSITORY_ENV]?.trim() || "";
24+
if (former !== "" && former !== configured) {
25+
throw new Error(
26+
`${FORMER_RELEASE_REPOSITORY_ENV}="${former}" disagrees with the repository the desktop ` +
27+
`updater uses ("${configured || "pingdotgg/t3code"}"). Set ${RELEASE_REPOSITORY_ENV} instead.`,
28+
);
29+
}
30+
if (configured === "") return "";
31+
const [owner, name, ...rest] = configured.split("/");
32+
if (!isValidSegment(owner) || !isValidSegment(name) || rest.length > 0) {
33+
throw new Error(
34+
`${RELEASE_REPOSITORY_ENV} (or GITHUB_REPOSITORY) must be "<owner>/<repo>", got "${configured}".`,
35+
);
36+
}
37+
return configured;
38+
}
39+
40+
/** The bundler `define` entry every build that bundles `@t3tools/shared/cliRelease` carries. */
41+
export function releaseRepositoryDefine(
42+
env: Readonly<Record<string, string | undefined>> = process.env,
43+
): Record<string, string> {
44+
return { __T3CODE_RELEASE_REPOSITORY__: JSON.stringify(resolveReleaseRepository(env)) };
45+
}

0 commit comments

Comments
 (0)