Skip to content

Commit c798cf3

Browse files
noreplyclaude
andcommitted
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]>
1 parent 7c9513c commit c798cf3

6 files changed

Lines changed: 67 additions & 30 deletions

File tree

‎apps/web/vite.config.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import {
1919
} from "@t3tools/shared/devProxy";
2020

2121
import { loadRepoEnv } from "../../scripts/lib/public-config";
22-
import {
23-
releaseRepositoryDefine,
24-
resolveReleaseRepository,
25-
} from "../../scripts/lib/release-repository";
22+
import { releaseRepositoryDefine } from "../../scripts/lib/release-repository";
2623
import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
2724
import { tailwindPlugins } from "./vite/tailwind";
2825
import { warmBundledDevPlugin } from "./vite/warmBundledDev";
@@ -51,7 +48,6 @@ const configuredReleaseChannel =
5148
const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version;
5249
const configuredDesktopUpdateRepository =
5350
process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
54-
resolveReleaseRepository() ||
5551
process.env.GITHUB_REPOSITORY?.trim() ||
5652
"";
5753
const configuredFeatureSecrets = process.env.T3CODE_FEATURE_SECRETS?.trim() || "";

‎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.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as Schema from "effect/Schema";
33

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

6-
// Set at build time from T3CODE_RELEASE_REPOSITORY (scripts/lib/release-repository.ts). A fork's
7-
// builds name the fork here, so they list and download only the fork's releases.
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.
88
declare const __T3CODE_RELEASE_REPOSITORY__: string | undefined;
99
const UPSTREAM_RELEASE_REPOSITORY = "pingdotgg/t3code";
1010

‎scripts/build-desktop-artifact.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,12 +2693,10 @@ export const resolveGitHubPublishConfig = Effect.fn("resolveGitHubPublishConfig"
26932693
) {
26942694
const env = yield* Config.all({
26952695
updateRepository: Config.String("T3CODE_DESKTOP_UPDATE_REPOSITORY").pipe(Config.option),
2696-
releaseRepository: Config.String("T3CODE_RELEASE_REPOSITORY").pipe(Config.option),
26972696
githubRepository: Config.String("GITHUB_REPOSITORY").pipe(Config.option),
26982697
});
26992698
const rawRepo = (
27002699
Option.getOrUndefined(env.updateRepository)?.trim() ||
2701-
Option.getOrUndefined(env.releaseRepository)?.trim() ||
27022700
Option.getOrUndefined(env.githubRepository)?.trim() ||
27032701
""
27042702
).trim();

‎scripts/lib/release-repository.test.ts‎

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
import { it as effectIt } from "@effect/vitest";
2+
import * as ConfigProvider from "effect/ConfigProvider";
3+
import * as Effect from "effect/Effect";
14
import { describe, expect, it } from "vite-plus/test";
25

6+
import { resolveGitHubPublishConfig } from "../build-desktop-artifact.ts";
37
import { releaseRepositoryDefine, resolveReleaseRepository } from "./release-repository.ts";
48

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+
515
describe("release repository build setting", () => {
616
it("is empty (the upstream default) when unset or blank", () => {
717
expect(resolveReleaseRepository({})).toBe("");
8-
expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " " })).toBe("");
18+
expect(resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: " " })).toBe("");
919
});
1020

11-
it("keeps a valid owner/repo", () => {
12-
expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " some-owner/t3code " })).toBe(
13-
"some-owner/t3code",
14-
);
15-
expect(releaseRepositoryDefine({ T3CODE_RELEASE_REPOSITORY: "some-owner/t3code" })).toEqual({
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({
1625
__T3CODE_RELEASE_REPOSITORY__: JSON.stringify("some-owner/t3code"),
1726
});
1827
});
@@ -21,16 +30,42 @@ describe("release repository build setting", () => {
2130
const actions = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "fork-owner/t3code" };
2231
expect(resolveReleaseRepository(actions)).toBe("fork-owner/t3code");
2332
expect(
24-
resolveReleaseRepository({ ...actions, T3CODE_RELEASE_REPOSITORY: "other/t3code" }),
33+
resolveReleaseRepository({ ...actions, T3CODE_DESKTOP_UPDATE_REPOSITORY: "other/t3code" }),
2534
).toBe("other/t3code");
26-
// Outside Actions a stray GITHUB_REPOSITORY changes nothing.
27-
expect(resolveReleaseRepository({ GITHUB_REPOSITORY: "fork-owner/t3code" })).toBe("");
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+
}
2863
});
2964

3065
it("fails the build on a malformed value instead of falling back to upstream", () => {
3166
for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) {
32-
expect(() => resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: value })).toThrow(
33-
/T3CODE_RELEASE_REPOSITORY/,
67+
expect(() => resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: value })).toThrow(
68+
/T3CODE_DESKTOP_UPDATE_REPOSITORY/,
3469
);
3570
}
3671
});

‎scripts/lib/release-repository.ts‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
/**
2-
* The repository a build updates from: T3CODE_RELEASE_REPOSITORY, else an Actions build's own
3-
* GITHUB_REPOSITORY (reusable workflows drop the caller's env), else "" for upstream. Keeps a
4-
* fork's Update button and `t3 update` on the fork's releases.
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.
55
*/
6-
export const RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY";
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";
79

810
const SEGMENT = /^[A-Za-z0-9._-]+$/u;
911

1012
function isValidSegment(value: string | undefined): value is string {
1113
return value !== undefined && value !== "." && value !== ".." && SEGMENT.test(value);
1214
}
1315

14-
/** The configured repository, or "" for the upstream default. Throws on a malformed value, so a
15-
* typo fails the build instead of quietly shipping a build that updates from upstream. */
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. */
1618
export function resolveReleaseRepository(
1719
env: Readonly<Record<string, string | undefined>> = process.env,
1820
): string {
19-
const configured =
20-
env[RELEASE_REPOSITORY_ENV]?.trim() ||
21-
(env.GITHUB_ACTIONS === "true" ? env.GITHUB_REPOSITORY?.trim() : "") ||
22-
"";
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+
}
2330
if (configured === "") return "";
2431
const [owner, name, ...rest] = configured.split("/");
2532
if (!isValidSegment(owner) || !isValidSegment(name) || rest.length > 0) {

0 commit comments

Comments
 (0)