From d874ab2b1ba96c3d3df5795ca9477d581b0a5921 Mon Sep 17 00:00:00 2001 From: t3code-fork Date: Thu, 12 Nov 2026 08:50:21 +0000 Subject: [PATCH 1/3] fork: builds name the repository they update from (T3CODE_RELEASE_REPOSITORY) A build made with T3CODE_RELEASE_REPOSITORY=/ 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 --- apps/desktop/vite.config.ts | 2 ++ apps/server/vite.config.ts | 2 ++ apps/web/tsconfig.json | 1 + apps/web/vite.config.ts | 6 ++++ packages/shared/src/cliRelease.test.ts | 49 ++++++++++++++++++++++++-- packages/shared/src/cliRelease.ts | 14 +++++++- scripts/build-desktop-artifact.ts | 2 ++ scripts/lib/release-repository.test.ts | 27 ++++++++++++++ scripts/lib/release-repository.ts | 35 ++++++++++++++++++ 9 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 scripts/lib/release-repository.test.ts create mode 100644 scripts/lib/release-repository.ts diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.ts index ba37576815097..e758deab63588 100644 --- a/apps/desktop/vite.config.ts +++ b/apps/desktop/vite.config.ts @@ -3,6 +3,7 @@ import { defaultInclude, defineConfig } from "vite-plus"; import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts"; import { loadRepoEnv } from "../../scripts/lib/public-config.ts"; +import { releaseRepositoryDefine } from "../../scripts/lib/release-repository.ts"; const repoEnv = loadRepoEnv(); @@ -11,6 +12,7 @@ const isMainProcessExternal = (id: string) => id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id); const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1"; const publicConfigDefine = { + ...releaseRepositoryDefine(), __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify( repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "", ), diff --git a/apps/server/vite.config.ts b/apps/server/vite.config.ts index 02fe582953abd..ba47cc4e57418 100644 --- a/apps/server/vite.config.ts +++ b/apps/server/vite.config.ts @@ -5,6 +5,7 @@ import { defineConfig, mergeConfig } from "vite-plus"; import baseConfig from "../../vite.config.ts"; import { loadRepoEnv } from "../../scripts/lib/public-config.ts"; +import { releaseRepositoryDefine } from "../../scripts/lib/release-repository.ts"; import rootPackageJson from "../../package.json" with { type: "json" }; import packageJson from "./package.json" with { type: "json" }; import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts"; @@ -126,6 +127,7 @@ export default mergeConfig( js: "#!/usr/bin/env node\n", }, define: { + ...releaseRepositoryDefine(), __T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel), __T3CODE_TELEMETRY_CHANNEL__: JSON.stringify(telemetryChannel), __T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""), diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index b9cd3ad6b5e47..f64bf416a53a2 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -34,6 +34,7 @@ "scripts/verify-built-boot.ts", "scripts/warm-dep-cache.ts", "../../scripts/lib/public-config.ts", + "../../scripts/lib/release-repository.ts", "../../scripts/lib/third-party-licenses.ts" ] } diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 217294de3762c..51727d51e4a6a 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -19,6 +19,10 @@ import { } from "@t3tools/shared/devProxy"; import { loadRepoEnv } from "../../scripts/lib/public-config"; +import { + releaseRepositoryDefine, + resolveReleaseRepository, +} from "../../scripts/lib/release-repository"; import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses"; import { tailwindPlugins } from "./vite/tailwind"; import { warmBundledDevPlugin } from "./vite/warmBundledDev"; @@ -47,6 +51,7 @@ const configuredReleaseChannel = const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version; const configuredDesktopUpdateRepository = process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() || + resolveReleaseRepository() || process.env.GITHUB_REPOSITORY?.trim() || ""; const configuredFeatureSecrets = process.env.T3CODE_FEATURE_SECRETS?.trim() || ""; @@ -298,6 +303,7 @@ export default defineConfig(() => { ], }, define: { + ...releaseRepositoryDefine(), "import.meta.env.VITE_WS_URL": JSON.stringify(configuredWsUrl ?? ""), // Override .env URLs with empty values in single-origin dev so clients use window.location.origin. "import.meta.env.VITE_HTTP_URL": JSON.stringify(configuredHttpUrl ?? ""), diff --git a/packages/shared/src/cliRelease.test.ts b/packages/shared/src/cliRelease.test.ts index b0aa61765e45a..5b59e3b767035 100644 --- a/packages/shared/src/cliRelease.test.ts +++ b/packages/shared/src/cliRelease.test.ts @@ -1,6 +1,11 @@ -import { describe, expect, it } from "vite-plus/test"; +import { afterEach, describe, expect, it, vi } from "vite-plus/test"; -import { cliArchiveTarCommand, newestCliReleaseVersion, parseChecksums } from "./cliRelease.ts"; +import { + cliArchiveTarCommand, + newestCliReleaseVersion, + parseChecksums, + resolveCliReleaseRepository, +} from "./cliRelease.ts"; describe("cliRelease", () => { it("parses sha256sum output including binary-mode markers", () => { @@ -40,3 +45,43 @@ describe("cliRelease", () => { expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined(); }); }); + +describe("cliRelease repository", () => { + afterEach(() => { + vi.unstubAllGlobals(); + vi.resetModules(); + }); + + it("defaults to upstream when the build names no repository", () => { + expect(resolveCliReleaseRepository(undefined)).toBe("pingdotgg/t3code"); + expect(resolveCliReleaseRepository("")).toBe("pingdotgg/t3code"); + expect(resolveCliReleaseRepository(" ")).toBe("pingdotgg/t3code"); + }); + + it("lists and downloads releases only from the repository the build names", async () => { + vi.stubGlobal("__T3CODE_RELEASE_REPOSITORY__", "fork-owner/t3code"); + vi.resetModules(); + const release = await import("./cliRelease.ts"); + expect(release.cliReleaseIndexPageUrl(2)).toBe( + "https://api.github.com/repos/fork-owner/t3code/releases?per_page=100&page=2", + ); + expect(release.cliReleaseDownloadBaseUrl("0.1.9-fork.1")).toBe( + "https://github.com/fork-owner/t3code/releases/download/v0.1.9-fork.1", + ); + expect(release.cliReleaseAssetUrl("0.1.9-fork.1", "SHA256SUMS")).toBe( + "https://github.com/fork-owner/t3code/releases/download/v0.1.9-fork.1/SHA256SUMS", + ); + expect(release.CLI_RELEASES_PAGE_URL).toBe("https://github.com/fork-owner/t3code/releases"); + }); + + it("keeps upstream URLs in a build without the setting", async () => { + vi.resetModules(); + const release = await import("./cliRelease.ts"); + expect(release.cliReleaseIndexPageUrl(1)).toBe( + "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1", + ); + expect(release.cliReleaseDownloadBaseUrl("0.1.9")).toBe( + "https://github.com/pingdotgg/t3code/releases/download/v0.1.9", + ); + }); +}); diff --git a/packages/shared/src/cliRelease.ts b/packages/shared/src/cliRelease.ts index 07a0c73b17947..9132586be14ee 100644 --- a/packages/shared/src/cliRelease.ts +++ b/packages/shared/src/cliRelease.ts @@ -3,7 +3,19 @@ import * as Schema from "effect/Schema"; import { compareSemverVersions } from "./semver.ts"; -const CLI_RELEASE_REPOSITORY = "pingdotgg/t3code"; +// Set at build time from T3CODE_RELEASE_REPOSITORY (scripts/lib/release-repository.ts). A fork's +// builds name the fork here, so they list and download only the fork's releases. +declare const __T3CODE_RELEASE_REPOSITORY__: string | undefined; +const UPSTREAM_RELEASE_REPOSITORY = "pingdotgg/t3code"; + +/** The repository releases come from: the build's setting, or upstream when it has none. */ +export function resolveCliReleaseRepository(configured: string | undefined): string { + return configured?.trim() || UPSTREAM_RELEASE_REPOSITORY; +} + +const CLI_RELEASE_REPOSITORY = resolveCliReleaseRepository( + typeof __T3CODE_RELEASE_REPOSITORY__ === "undefined" ? undefined : __T3CODE_RELEASE_REPOSITORY__, +); export const CLI_RELEASES_PAGE_URL = `https://github.com/${CLI_RELEASE_REPOSITORY}/releases`; export const CLI_RELEASE_CHECKSUMS_FILE = "SHA256SUMS"; export const CLI_RELEASE_BASE_URL_ENV = "T3CODE_RELEASE_BASE_URL"; diff --git a/scripts/build-desktop-artifact.ts b/scripts/build-desktop-artifact.ts index 2fff4919c40d3..840d934a1d64f 100644 --- a/scripts/build-desktop-artifact.ts +++ b/scripts/build-desktop-artifact.ts @@ -2693,10 +2693,12 @@ export const resolveGitHubPublishConfig = Effect.fn("resolveGitHubPublishConfig" ) { const env = yield* Config.all({ updateRepository: Config.String("T3CODE_DESKTOP_UPDATE_REPOSITORY").pipe(Config.option), + releaseRepository: Config.String("T3CODE_RELEASE_REPOSITORY").pipe(Config.option), githubRepository: Config.String("GITHUB_REPOSITORY").pipe(Config.option), }); const rawRepo = ( Option.getOrUndefined(env.updateRepository)?.trim() || + Option.getOrUndefined(env.releaseRepository)?.trim() || Option.getOrUndefined(env.githubRepository)?.trim() || "" ).trim(); diff --git a/scripts/lib/release-repository.test.ts b/scripts/lib/release-repository.test.ts new file mode 100644 index 0000000000000..1118cfe7df717 --- /dev/null +++ b/scripts/lib/release-repository.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { releaseRepositoryDefine, resolveReleaseRepository } from "./release-repository.ts"; + +describe("release repository build setting", () => { + it("is empty (the upstream default) when unset or blank", () => { + expect(resolveReleaseRepository({})).toBe(""); + expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " " })).toBe(""); + }); + + it("keeps a valid owner/repo", () => { + expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " some-owner/t3code " })).toBe( + "some-owner/t3code", + ); + expect(releaseRepositoryDefine({ T3CODE_RELEASE_REPOSITORY: "some-owner/t3code" })).toEqual({ + __T3CODE_RELEASE_REPOSITORY__: JSON.stringify("some-owner/t3code"), + }); + }); + + it("fails the build on a malformed value instead of falling back to upstream", () => { + for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) { + expect(() => resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: value })).toThrow( + /T3CODE_RELEASE_REPOSITORY/, + ); + } + }); +}); diff --git a/scripts/lib/release-repository.ts b/scripts/lib/release-repository.ts new file mode 100644 index 0000000000000..17cae4abada55 --- /dev/null +++ b/scripts/lib/release-repository.ts @@ -0,0 +1,35 @@ +/** + * The GitHub repository whose releases a build updates from, baked in at build time. + * + * Empty means the upstream default in `@t3tools/shared/cliRelease`. A fork's release workflow sets + * `T3CODE_RELEASE_REPOSITORY=/` so its builds look only at the fork's releases: the + * Update button and `t3 update` can then never install an upstream build over the fork. + */ +export const RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY"; + +const SEGMENT = /^[A-Za-z0-9._-]+$/u; + +function isValidSegment(value: string | undefined): value is string { + return value !== undefined && value !== "." && value !== ".." && SEGMENT.test(value); +} + +/** The configured repository, or "" for the upstream default. Throws on a malformed value, so a + * typo fails the build instead of quietly shipping a build that updates from upstream. */ +export function resolveReleaseRepository( + env: Readonly> = process.env, +): string { + const configured = env[RELEASE_REPOSITORY_ENV]?.trim() ?? ""; + if (configured === "") return ""; + const [owner, name, ...rest] = configured.split("/"); + if (!isValidSegment(owner) || !isValidSegment(name) || rest.length > 0) { + throw new Error(`${RELEASE_REPOSITORY_ENV} must be "/", got "${configured}".`); + } + return configured; +} + +/** The bundler `define` entry every build that bundles `@t3tools/shared/cliRelease` carries. */ +export function releaseRepositoryDefine( + env: Readonly> = process.env, +): Record { + return { __T3CODE_RELEASE_REPOSITORY__: JSON.stringify(resolveReleaseRepository(env)) }; +} From 7c9513cf49840f37fa2d5f2f55c6a7ad2fce7f57 Mon Sep 17 00:00:00 2001 From: t3code-fork Date: Thu, 12 Nov 2026 08:54:18 +0000 Subject: [PATCH 2/3] 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 --- scripts/lib/release-repository.test.ts | 10 ++++++++++ scripts/lib/release-repository.ts | 17 ++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/lib/release-repository.test.ts b/scripts/lib/release-repository.test.ts index 1118cfe7df717..568eda60b3c33 100644 --- a/scripts/lib/release-repository.test.ts +++ b/scripts/lib/release-repository.test.ts @@ -17,6 +17,16 @@ describe("release repository build setting", () => { }); }); + it("names the repository a GitHub Actions build runs in, unless the setting overrides it", () => { + const actions = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "fork-owner/t3code" }; + expect(resolveReleaseRepository(actions)).toBe("fork-owner/t3code"); + expect( + resolveReleaseRepository({ ...actions, T3CODE_RELEASE_REPOSITORY: "other/t3code" }), + ).toBe("other/t3code"); + // Outside Actions a stray GITHUB_REPOSITORY changes nothing. + expect(resolveReleaseRepository({ GITHUB_REPOSITORY: "fork-owner/t3code" })).toBe(""); + }); + it("fails the build on a malformed value instead of falling back to upstream", () => { for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) { expect(() => resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: value })).toThrow( diff --git a/scripts/lib/release-repository.ts b/scripts/lib/release-repository.ts index 17cae4abada55..7c79f3830b731 100644 --- a/scripts/lib/release-repository.ts +++ b/scripts/lib/release-repository.ts @@ -1,9 +1,7 @@ /** - * The GitHub repository whose releases a build updates from, baked in at build time. - * - * Empty means the upstream default in `@t3tools/shared/cliRelease`. A fork's release workflow sets - * `T3CODE_RELEASE_REPOSITORY=/` so its builds look only at the fork's releases: the - * Update button and `t3 update` can then never install an upstream build over the fork. + * The repository a build updates from: T3CODE_RELEASE_REPOSITORY, else an Actions build's own + * GITHUB_REPOSITORY (reusable workflows drop the caller's env), else "" for upstream. Keeps a + * fork's Update button and `t3 update` on the fork's releases. */ export const RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY"; @@ -18,11 +16,16 @@ function isValidSegment(value: string | undefined): value is string { export function resolveReleaseRepository( env: Readonly> = process.env, ): string { - const configured = env[RELEASE_REPOSITORY_ENV]?.trim() ?? ""; + const configured = + env[RELEASE_REPOSITORY_ENV]?.trim() || + (env.GITHUB_ACTIONS === "true" ? env.GITHUB_REPOSITORY?.trim() : "") || + ""; if (configured === "") return ""; const [owner, name, ...rest] = configured.split("/"); if (!isValidSegment(owner) || !isValidSegment(name) || rest.length > 0) { - throw new Error(`${RELEASE_REPOSITORY_ENV} must be "/", got "${configured}".`); + throw new Error( + `${RELEASE_REPOSITORY_ENV} (or GITHUB_REPOSITORY) must be "/", got "${configured}".`, + ); } return configured; } From c798cf342e3008ed44432296a0b64bb076f97bfb Mon Sep 17 00:00:00 2001 From: t3code-fork Date: Thu, 12 Nov 2026 09:49:03 +0000 Subject: [PATCH 3/3] 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 --- apps/web/vite.config.ts | 6 +-- docs/operations/release.md | 1 + packages/shared/src/cliRelease.ts | 4 +- scripts/build-desktop-artifact.ts | 2 - scripts/lib/release-repository.test.ts | 57 +++++++++++++++++++++----- scripts/lib/release-repository.ts | 27 +++++++----- 6 files changed, 67 insertions(+), 30 deletions(-) diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 51727d51e4a6a..ba34eb17d7d99 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -19,10 +19,7 @@ import { } from "@t3tools/shared/devProxy"; import { loadRepoEnv } from "../../scripts/lib/public-config"; -import { - releaseRepositoryDefine, - resolveReleaseRepository, -} from "../../scripts/lib/release-repository"; +import { releaseRepositoryDefine } from "../../scripts/lib/release-repository"; import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses"; import { tailwindPlugins } from "./vite/tailwind"; import { warmBundledDevPlugin } from "./vite/warmBundledDev"; @@ -51,7 +48,6 @@ const configuredReleaseChannel = const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version; const configuredDesktopUpdateRepository = process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() || - resolveReleaseRepository() || process.env.GITHUB_REPOSITORY?.trim() || ""; const configuredFeatureSecrets = process.env.T3CODE_FEATURE_SECRETS?.trim() || ""; diff --git a/docs/operations/release.md b/docs/operations/release.md index be74b2ad2982e..4268bcc90d4a7 100644 --- a/docs/operations/release.md +++ b/docs/operations/release.md @@ -477,6 +477,7 @@ available. - Repository slug source: - `T3CODE_DESKTOP_UPDATE_REPOSITORY` (format `owner/repo`), if set. - otherwise `GITHUB_REPOSITORY` from GitHub Actions. + - The server, `t3 update` and desktop SSH installs bake in the same slug (`scripts/lib/release-repository.ts`). - Required release assets for updater: - platform installers (`.exe`, `.dmg`, `.AppImage`, `.deb`, plus macOS `.zip` for Squirrel.Mac update payloads) - channel metadata: `latest*.yml` for stable releases, `nightly*.yml` for nightly releases diff --git a/packages/shared/src/cliRelease.ts b/packages/shared/src/cliRelease.ts index 9132586be14ee..9c12b4cc426d6 100644 --- a/packages/shared/src/cliRelease.ts +++ b/packages/shared/src/cliRelease.ts @@ -3,8 +3,8 @@ import * as Schema from "effect/Schema"; import { compareSemverVersions } from "./semver.ts"; -// Set at build time from T3CODE_RELEASE_REPOSITORY (scripts/lib/release-repository.ts). A fork's -// builds name the fork here, so they list and download only the fork's releases. +// Set at build time from T3CODE_DESKTOP_UPDATE_REPOSITORY (scripts/lib/release-repository.ts), the +// desktop updater's setting, so a fork's builds list and download only the fork's releases. declare const __T3CODE_RELEASE_REPOSITORY__: string | undefined; const UPSTREAM_RELEASE_REPOSITORY = "pingdotgg/t3code"; diff --git a/scripts/build-desktop-artifact.ts b/scripts/build-desktop-artifact.ts index 840d934a1d64f..2fff4919c40d3 100644 --- a/scripts/build-desktop-artifact.ts +++ b/scripts/build-desktop-artifact.ts @@ -2693,12 +2693,10 @@ export const resolveGitHubPublishConfig = Effect.fn("resolveGitHubPublishConfig" ) { const env = yield* Config.all({ updateRepository: Config.String("T3CODE_DESKTOP_UPDATE_REPOSITORY").pipe(Config.option), - releaseRepository: Config.String("T3CODE_RELEASE_REPOSITORY").pipe(Config.option), githubRepository: Config.String("GITHUB_REPOSITORY").pipe(Config.option), }); const rawRepo = ( Option.getOrUndefined(env.updateRepository)?.trim() || - Option.getOrUndefined(env.releaseRepository)?.trim() || Option.getOrUndefined(env.githubRepository)?.trim() || "" ).trim(); diff --git a/scripts/lib/release-repository.test.ts b/scripts/lib/release-repository.test.ts index 568eda60b3c33..46a285b29425e 100644 --- a/scripts/lib/release-repository.test.ts +++ b/scripts/lib/release-repository.test.ts @@ -1,18 +1,27 @@ +import { it as effectIt } from "@effect/vitest"; +import * as ConfigProvider from "effect/ConfigProvider"; +import * as Effect from "effect/Effect"; import { describe, expect, it } from "vite-plus/test"; +import { resolveGitHubPublishConfig } from "../build-desktop-artifact.ts"; import { releaseRepositoryDefine, resolveReleaseRepository } from "./release-repository.ts"; +const desktopFeedRepository = (env: Record) => + resolveGitHubPublishConfig("latest").pipe( + Effect.map((config) => (config ? `${config.owner}/${config.repo}` : "")), + Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))), + ); + describe("release repository build setting", () => { it("is empty (the upstream default) when unset or blank", () => { expect(resolveReleaseRepository({})).toBe(""); - expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " " })).toBe(""); + expect(resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: " " })).toBe(""); }); - it("keeps a valid owner/repo", () => { - expect(resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: " some-owner/t3code " })).toBe( - "some-owner/t3code", - ); - expect(releaseRepositoryDefine({ T3CODE_RELEASE_REPOSITORY: "some-owner/t3code" })).toEqual({ + it("is upstream's desktop update setting, so the server follows the desktop feed", () => { + const env = { T3CODE_DESKTOP_UPDATE_REPOSITORY: " some-owner/t3code " }; + expect(resolveReleaseRepository(env)).toBe("some-owner/t3code"); + expect(releaseRepositoryDefine(env)).toEqual({ __T3CODE_RELEASE_REPOSITORY__: JSON.stringify("some-owner/t3code"), }); }); @@ -21,16 +30,42 @@ describe("release repository build setting", () => { const actions = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "fork-owner/t3code" }; expect(resolveReleaseRepository(actions)).toBe("fork-owner/t3code"); expect( - resolveReleaseRepository({ ...actions, T3CODE_RELEASE_REPOSITORY: "other/t3code" }), + resolveReleaseRepository({ ...actions, T3CODE_DESKTOP_UPDATE_REPOSITORY: "other/t3code" }), ).toBe("other/t3code"); - // Outside Actions a stray GITHUB_REPOSITORY changes nothing. - expect(resolveReleaseRepository({ GITHUB_REPOSITORY: "fork-owner/t3code" })).toBe(""); + }); + + effectIt.effect("names the same repository as the desktop updater feed for every setting", () => + Effect.gen(function* () { + const cases: Array> = [ + {}, + { T3CODE_DESKTOP_UPDATE_REPOSITORY: "fork-owner/t3code" }, + { GITHUB_REPOSITORY: "fork-owner/t3code" }, + { T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code", GITHUB_REPOSITORY: "b/t3code" }, + { T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "b/t3code" }, + ]; + for (const env of cases) { + const feed = yield* desktopFeedRepository(env); + expect(resolveReleaseRepository(env), JSON.stringify(env)).toBe(feed); + } + }), + ); + + it("fails the build when the former setting disagrees with the desktop updater's", () => { + for (const env of [ + { T3CODE_RELEASE_REPOSITORY: "fork-owner/t3code" }, + { T3CODE_RELEASE_REPOSITORY: "b/t3code", T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code" }, + { T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "a/t3code" }, + ]) { + expect(() => resolveReleaseRepository(env), JSON.stringify(env)).toThrow( + /T3CODE_RELEASE_REPOSITORY=".+" disagrees.*Set T3CODE_DESKTOP_UPDATE_REPOSITORY/, + ); + } }); it("fails the build on a malformed value instead of falling back to upstream", () => { for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) { - expect(() => resolveReleaseRepository({ T3CODE_RELEASE_REPOSITORY: value })).toThrow( - /T3CODE_RELEASE_REPOSITORY/, + expect(() => resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: value })).toThrow( + /T3CODE_DESKTOP_UPDATE_REPOSITORY/, ); } }); diff --git a/scripts/lib/release-repository.ts b/scripts/lib/release-repository.ts index 7c79f3830b731..ee0d22b7f4cee 100644 --- a/scripts/lib/release-repository.ts +++ b/scripts/lib/release-repository.ts @@ -1,9 +1,11 @@ /** - * The repository a build updates from: T3CODE_RELEASE_REPOSITORY, else an Actions build's own - * GITHUB_REPOSITORY (reusable workflows drop the caller's env), else "" for upstream. Keeps a - * fork's Update button and `t3 update` on the fork's releases. + * The repository a build updates from, for the server, CLI and desktop SSH installs. It is the one + * upstream already uses for the desktop updater feed and release links (docs/operations/release.md): + * T3CODE_DESKTOP_UPDATE_REPOSITORY, else GITHUB_REPOSITORY, else "" for upstream. */ -export const RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY"; +export const RELEASE_REPOSITORY_ENV = "T3CODE_DESKTOP_UPDATE_REPOSITORY"; +// The setting's first name in this fork; still accepted only when it names the same repository. +const FORMER_RELEASE_REPOSITORY_ENV = "T3CODE_RELEASE_REPOSITORY"; const SEGMENT = /^[A-Za-z0-9._-]+$/u; @@ -11,15 +13,20 @@ function isValidSegment(value: string | undefined): value is string { return value !== undefined && value !== "." && value !== ".." && SEGMENT.test(value); } -/** The configured repository, or "" for the upstream default. Throws on a malformed value, so a - * typo fails the build instead of quietly shipping a build that updates from upstream. */ +/** The configured repository, or "" for the upstream default. Throws on a malformed value or a + * disagreeing former setting, so no build ships the desktop and the server on different feeds. */ export function resolveReleaseRepository( env: Readonly> = process.env, ): string { - const configured = - env[RELEASE_REPOSITORY_ENV]?.trim() || - (env.GITHUB_ACTIONS === "true" ? env.GITHUB_REPOSITORY?.trim() : "") || - ""; + // The same order as apps/web/vite.config.ts and resolveGitHubPublishConfig read them. + const configured = env[RELEASE_REPOSITORY_ENV]?.trim() || env.GITHUB_REPOSITORY?.trim() || ""; + const former = env[FORMER_RELEASE_REPOSITORY_ENV]?.trim() || ""; + if (former !== "" && former !== configured) { + throw new Error( + `${FORMER_RELEASE_REPOSITORY_ENV}="${former}" disagrees with the repository the desktop ` + + `updater uses ("${configured || "pingdotgg/t3code"}"). Set ${RELEASE_REPOSITORY_ENV} instead.`, + ); + } if (configured === "") return ""; const [owner, name, ...rest] = configured.split("/"); if (!isValidSegment(owner) || !isValidSegment(name) || rest.length > 0) {