Nightly release channel (#2012)
Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
49 files changed
+1221
-149
No files matched your search
@@ -2,9 +2,59 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { ConfigProvider, Effect, Option } from "effect";
|
||||
|
||||
import { resolveBuildOptions } from "./build-desktop-artifact.ts";
|
||||
import {
|
||||
resolveBuildOptions,
|
||||
resolveDesktopBuildIconAssets,
|
||||
resolveDesktopUpdateChannel,
|
||||
resolveMockUpdateServerPort,
|
||||
resolveMockUpdateServerUrl,
|
||||
} from "./build-desktop-artifact.ts";
|
||||
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
|
||||
|
||||
it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
it("resolves the dedicated nightly updater channel from nightly versions", () => {
|
||||
assert.equal(resolveDesktopUpdateChannel("0.0.17-nightly.20260413.42"), "nightly");
|
||||
assert.equal(resolveDesktopUpdateChannel("0.0.17"), "latest");
|
||||
});
|
||||
|
||||
it("switches desktop packaging icons to the nightly artwork for nightly versions", () => {
|
||||
assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17"), {
|
||||
macIconPng: BRAND_ASSET_PATHS.productionMacIconPng,
|
||||
linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng,
|
||||
windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(resolveDesktopBuildIconAssets("0.0.17-nightly.20260413.42"), {
|
||||
macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng,
|
||||
linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng,
|
||||
windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco,
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the default mock update port when the configured port is blank", () => {
|
||||
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
|
||||
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
|
||||
});
|
||||
|
||||
it.effect("normalizes mock update server ports from env-style strings", () =>
|
||||
Effect.gen(function* () {
|
||||
assert.equal(yield* resolveMockUpdateServerPort(undefined), undefined);
|
||||
assert.equal(yield* resolveMockUpdateServerPort(""), undefined);
|
||||
assert.equal(yield* resolveMockUpdateServerPort(" "), undefined);
|
||||
assert.equal(yield* resolveMockUpdateServerPort("4123"), 4123);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects non-numeric or out-of-range mock update ports", () =>
|
||||
Effect.gen(function* () {
|
||||
const invalidPorts = ["abc", "12.5", "0", "65536"];
|
||||
for (const port of invalidPorts) {
|
||||
const exit = yield* Effect.exit(resolveMockUpdateServerPort(port));
|
||||
assert.equal(exit._tag, "Failure");
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves explicit false boolean flags over true env defaults", () =>
|
||||
Effect.gen(function* () {
|
||||
const resolved = yield* resolveBuildOptions({
|
||||
|
||||
@@ -23,23 +23,14 @@ const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
|
||||
const RepoRoot = Effect.service(Path.Path).pipe(
|
||||
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
|
||||
);
|
||||
const ProductionMacIconSource = Effect.zipWith(
|
||||
RepoRoot,
|
||||
Effect.service(Path.Path),
|
||||
(repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionMacIconPng),
|
||||
);
|
||||
const ProductionLinuxIconSource = Effect.zipWith(
|
||||
RepoRoot,
|
||||
Effect.service(Path.Path),
|
||||
(repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionLinuxIconPng),
|
||||
);
|
||||
const ProductionWindowsIconSource = Effect.zipWith(
|
||||
RepoRoot,
|
||||
Effect.service(Path.Path),
|
||||
(repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionWindowsIconIco),
|
||||
);
|
||||
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
|
||||
|
||||
interface DesktopBuildIconAssets {
|
||||
readonly macIconPng: string;
|
||||
readonly linuxIconPng: string;
|
||||
readonly windowsIconIco: string;
|
||||
}
|
||||
|
||||
interface PlatformConfig {
|
||||
readonly cliFlag: "--mac" | "--linux" | "--win";
|
||||
readonly defaultTarget: string;
|
||||
@@ -75,7 +66,7 @@ interface BuildCliInput {
|
||||
readonly signed: Option.Option<boolean>;
|
||||
readonly verbose: Option.Option<boolean>;
|
||||
readonly mockUpdates: Option.Option<boolean>;
|
||||
readonly mockUpdateServerPort: Option.Option<string>;
|
||||
readonly mockUpdateServerPort: Option.Option<number>;
|
||||
}
|
||||
|
||||
function detectHostBuildPlatform(hostPlatform: string): typeof BuildPlatform.Type | undefined {
|
||||
@@ -165,7 +156,7 @@ interface ResolvedBuildOptions {
|
||||
readonly signed: boolean;
|
||||
readonly verbose: boolean;
|
||||
readonly mockUpdates: boolean;
|
||||
readonly mockUpdateServerPort: string | undefined;
|
||||
readonly mockUpdateServerPort: number | undefined;
|
||||
}
|
||||
|
||||
interface StagePackageJson {
|
||||
@@ -213,11 +204,28 @@ const BuildEnvConfig = Config.all({
|
||||
mockUpdateServerPort: Config.string("T3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT").pipe(Config.option),
|
||||
});
|
||||
|
||||
const MockUpdateServerPortSchema = Schema.NumberFromString.check(
|
||||
Schema.isInt(),
|
||||
Schema.isBetween({ minimum: 1, maximum: 65535 }),
|
||||
);
|
||||
const decodeMockUpdateServerPort = Schema.decodeUnknownEffect(MockUpdateServerPortSchema);
|
||||
|
||||
const resolveBooleanFlag = (flag: Option.Option<boolean>, envValue: boolean) =>
|
||||
Option.getOrElse(flag, () => envValue);
|
||||
const mergeOptions = <A>(a: Option.Option<A>, b: Option.Option<A>, defaultValue: A) =>
|
||||
Option.getOrElse(a, () => Option.getOrElse(b, () => defaultValue));
|
||||
|
||||
export const resolveMockUpdateServerPort = Effect.fn("resolveMockUpdateServerPort")(function* (
|
||||
mockUpdateServerPort: string | undefined,
|
||||
) {
|
||||
const port = mockUpdateServerPort?.trim();
|
||||
if (!port) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return yield* decodeMockUpdateServerPort(port);
|
||||
});
|
||||
|
||||
export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* (
|
||||
input: BuildCliInput,
|
||||
) {
|
||||
@@ -254,11 +262,17 @@ export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* (
|
||||
const verbose = resolveBooleanFlag(input.verbose, env.verbose);
|
||||
|
||||
const mockUpdates = resolveBooleanFlag(input.mockUpdates, env.mockUpdates);
|
||||
const mockUpdateServerPort = mergeOptions(
|
||||
input.mockUpdateServerPort,
|
||||
env.mockUpdateServerPort,
|
||||
undefined,
|
||||
);
|
||||
const mockUpdateServerPort =
|
||||
Option.getOrUndefined(input.mockUpdateServerPort) ??
|
||||
(yield* resolveMockUpdateServerPort(Option.getOrUndefined(env.mockUpdateServerPort)).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new BuildScriptError({
|
||||
message: "Invalid mock update server port.",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
));
|
||||
|
||||
return {
|
||||
platform,
|
||||
@@ -329,14 +343,13 @@ function generateMacIconSet(
|
||||
});
|
||||
}
|
||||
|
||||
function stageMacIcons(stageResourcesDir: string, verbose: boolean) {
|
||||
function stageMacIcons(stageResourcesDir: string, sourcePng: string, verbose: boolean) {
|
||||
return Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const iconSource = yield* ProductionMacIconSource;
|
||||
if (!(yield* fs.exists(iconSource))) {
|
||||
if (!(yield* fs.exists(sourcePng))) {
|
||||
return yield* new BuildScriptError({
|
||||
message: `Production icon source is missing at ${iconSource}`,
|
||||
message: `Desktop macOS icon source is missing at ${sourcePng}`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -350,42 +363,40 @@ function stageMacIcons(stageResourcesDir: string, verbose: boolean) {
|
||||
yield* runCommand(
|
||||
ChildProcess.make({
|
||||
...commandOutputOptions(verbose),
|
||||
})`sips -z 512 512 ${iconSource} --out ${iconPngPath}`,
|
||||
})`sips -z 512 512 ${sourcePng} --out ${iconPngPath}`,
|
||||
);
|
||||
|
||||
yield* generateMacIconSet(iconSource, iconIcnsPath, tmpRoot, path, verbose);
|
||||
yield* generateMacIconSet(sourcePng, iconIcnsPath, tmpRoot, path, verbose);
|
||||
});
|
||||
}
|
||||
|
||||
function stageLinuxIcons(stageResourcesDir: string) {
|
||||
function stageLinuxIcons(stageResourcesDir: string, sourcePng: string) {
|
||||
return Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const iconSource = yield* ProductionLinuxIconSource;
|
||||
if (!(yield* fs.exists(iconSource))) {
|
||||
if (!(yield* fs.exists(sourcePng))) {
|
||||
return yield* new BuildScriptError({
|
||||
message: `Production icon source is missing at ${iconSource}`,
|
||||
message: `Desktop Linux icon source is missing at ${sourcePng}`,
|
||||
});
|
||||
}
|
||||
|
||||
const iconPath = path.join(stageResourcesDir, "icon.png");
|
||||
yield* fs.copyFile(iconSource, iconPath);
|
||||
yield* fs.copyFile(sourcePng, iconPath);
|
||||
});
|
||||
}
|
||||
|
||||
function stageWindowsIcons(stageResourcesDir: string) {
|
||||
function stageWindowsIcons(stageResourcesDir: string, sourceIco: string) {
|
||||
return Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const iconSource = yield* ProductionWindowsIconSource;
|
||||
if (!(yield* fs.exists(iconSource))) {
|
||||
if (!(yield* fs.exists(sourceIco))) {
|
||||
return yield* new BuildScriptError({
|
||||
message: `Production Windows icon source is missing at ${iconSource}`,
|
||||
message: `Desktop Windows icon source is missing at ${sourceIco}`,
|
||||
});
|
||||
}
|
||||
|
||||
const iconPath = path.join(stageResourcesDir, "icon.ico");
|
||||
yield* fs.copyFile(iconSource, iconPath);
|
||||
yield* fs.copyFile(sourceIco, iconPath);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -441,12 +452,13 @@ function resolveDesktopRuntimeDependencies(
|
||||
return resolveCatalogDependencies(runtimeDependencies, catalog, "apps/desktop");
|
||||
}
|
||||
|
||||
function resolveGitHubPublishConfig():
|
||||
function resolveGitHubPublishConfig(updateChannel: "latest" | "nightly"):
|
||||
| {
|
||||
readonly provider: "github";
|
||||
readonly owner: string;
|
||||
readonly repo: string;
|
||||
readonly releaseType: "release";
|
||||
readonly releaseType: "release" | "prerelease";
|
||||
readonly channel?: "nightly";
|
||||
}
|
||||
| undefined {
|
||||
const rawRepo =
|
||||
@@ -462,17 +474,43 @@ function resolveGitHubPublishConfig():
|
||||
provider: "github",
|
||||
owner,
|
||||
repo,
|
||||
releaseType: "release",
|
||||
releaseType: updateChannel === "nightly" ? "prerelease" : "release",
|
||||
...(updateChannel === "nightly" ? { channel: "nightly" as const } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveDesktopUpdateChannel(version: string): "latest" | "nightly" {
|
||||
return /-nightly\.\d{8}\.\d+$/.test(version) ? "nightly" : "latest";
|
||||
}
|
||||
|
||||
export function resolveDesktopBuildIconAssets(version: string): DesktopBuildIconAssets {
|
||||
if (resolveDesktopUpdateChannel(version) === "nightly") {
|
||||
return {
|
||||
macIconPng: BRAND_ASSET_PATHS.nightlyMacIconPng,
|
||||
linuxIconPng: BRAND_ASSET_PATHS.nightlyLinuxIconPng,
|
||||
windowsIconIco: BRAND_ASSET_PATHS.nightlyWindowsIconIco,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
macIconPng: BRAND_ASSET_PATHS.productionMacIconPng,
|
||||
linuxIconPng: BRAND_ASSET_PATHS.productionLinuxIconPng,
|
||||
windowsIconIco: BRAND_ASSET_PATHS.productionWindowsIconIco,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveMockUpdateServerUrl(mockUpdateServerPort: number | undefined): string {
|
||||
return `http://localhost:${mockUpdateServerPort ?? 3000}`;
|
||||
}
|
||||
|
||||
const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
platform: typeof BuildPlatform.Type,
|
||||
target: string,
|
||||
productName: string,
|
||||
version: string,
|
||||
signed: boolean,
|
||||
mockUpdates: boolean,
|
||||
mockUpdateServerPort: string | undefined,
|
||||
mockUpdateServerPort: number | undefined,
|
||||
) {
|
||||
const buildConfig: Record<string, unknown> = {
|
||||
appId: "com.t3tools.t3code",
|
||||
@@ -482,14 +520,15 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
buildResources: "apps/desktop/resources",
|
||||
},
|
||||
};
|
||||
const publishConfig = resolveGitHubPublishConfig();
|
||||
const updateChannel = resolveDesktopUpdateChannel(version);
|
||||
const publishConfig = resolveGitHubPublishConfig(updateChannel);
|
||||
if (publishConfig) {
|
||||
buildConfig.publish = [publishConfig];
|
||||
} else if (mockUpdates) {
|
||||
buildConfig.publish = [
|
||||
{
|
||||
provider: "generic",
|
||||
url: `http://localhost:${mockUpdateServerPort ?? 3000}`,
|
||||
url: resolveMockUpdateServerUrl(mockUpdateServerPort),
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -533,20 +572,21 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
const assertPlatformBuildResources = Effect.fn("assertPlatformBuildResources")(function* (
|
||||
platform: typeof BuildPlatform.Type,
|
||||
stageResourcesDir: string,
|
||||
iconAssets: DesktopBuildIconAssets,
|
||||
verbose: boolean,
|
||||
) {
|
||||
if (platform === "mac") {
|
||||
yield* stageMacIcons(stageResourcesDir, verbose);
|
||||
yield* stageMacIcons(stageResourcesDir, iconAssets.macIconPng, verbose);
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform === "linux") {
|
||||
yield* stageLinuxIcons(stageResourcesDir);
|
||||
yield* stageLinuxIcons(stageResourcesDir, iconAssets.linuxIconPng);
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform === "win") {
|
||||
yield* stageWindowsIcons(stageResourcesDir);
|
||||
yield* stageWindowsIcons(stageResourcesDir, iconAssets.windowsIconIco);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -614,6 +654,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
});
|
||||
|
||||
const appVersion = options.version ?? serverPackageJson.version;
|
||||
const iconAssets = resolveDesktopBuildIconAssets(appVersion);
|
||||
const commitHash = resolveGitCommitHash(repoRoot);
|
||||
const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
|
||||
const stageRoot = yield* mkdir({
|
||||
@@ -665,7 +706,16 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
yield* fs.copy(distDirs.desktopResources, stageResourcesDir);
|
||||
yield* fs.copy(distDirs.serverDist, path.join(stageAppDir, "apps/server/dist"));
|
||||
|
||||
yield* assertPlatformBuildResources(options.platform, stageResourcesDir, options.verbose);
|
||||
yield* assertPlatformBuildResources(
|
||||
options.platform,
|
||||
stageResourcesDir,
|
||||
{
|
||||
macIconPng: join(repoRoot, iconAssets.macIconPng),
|
||||
linuxIconPng: join(repoRoot, iconAssets.linuxIconPng),
|
||||
windowsIconIco: join(repoRoot, iconAssets.windowsIconIco),
|
||||
},
|
||||
options.verbose,
|
||||
);
|
||||
|
||||
// electron-builder is filtering out stageResourcesDir directory in the AppImage for production
|
||||
yield* fs.copy(stageResourcesDir, path.join(stageAppDir, "apps/desktop/prod-resources"));
|
||||
@@ -683,6 +733,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
options.platform,
|
||||
options.target,
|
||||
desktopPackageJson.productName ?? "T3 Code",
|
||||
appVersion,
|
||||
options.signed,
|
||||
options.mockUpdates,
|
||||
options.mockUpdateServerPort,
|
||||
@@ -829,7 +880,8 @@ const buildDesktopArtifactCli = Command.make("build-desktop-artifact", {
|
||||
Flag.withDescription("Enable mock updates (env: T3CODE_DESKTOP_MOCK_UPDATES)."),
|
||||
Flag.optional,
|
||||
),
|
||||
mockUpdateServerPort: Flag.string("mock-update-server-port").pipe(
|
||||
mockUpdateServerPort: Flag.integer("mock-update-server-port").pipe(
|
||||
Flag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }))),
|
||||
Flag.withDescription("Mock update server port (env: T3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT)."),
|
||||
Flag.optional,
|
||||
),
|
||||
|
||||
@@ -6,6 +6,12 @@ export const BRAND_ASSET_PATHS = {
|
||||
productionWebFavicon16Png: "assets/prod/t3-black-web-favicon-16x16.png",
|
||||
productionWebFavicon32Png: "assets/prod/t3-black-web-favicon-32x32.png",
|
||||
productionWebAppleTouchIconPng: "assets/prod/t3-black-web-apple-touch-180.png",
|
||||
|
||||
nightlyMacIconPng: "assets/nightly/blueprint-macos-1024.png",
|
||||
nightlyLinuxIconPng: "assets/nightly/blueprint-universal-1024.png",
|
||||
nightlyWindowsIconIco: "assets/nightly/blueprint-windows.ico",
|
||||
|
||||
developmentDesktopIconPng: "assets/dev/blueprint-macos-1024.png",
|
||||
developmentWindowsIconIco: "assets/dev/blueprint-windows.ico",
|
||||
developmentWebFaviconIco: "assets/dev/blueprint-web-favicon.ico",
|
||||
developmentWebFavicon16Png: "assets/dev/blueprint-web-favicon-16x16.png",
|
||||
|
||||
@@ -95,7 +95,7 @@ try {
|
||||
},
|
||||
);
|
||||
|
||||
execFileSync("bun", ["install", "--lockfile-only", "--ignore-scripts"], {
|
||||
execFileSync("bun", ["install", "--ignore-scripts"], {
|
||||
cwd: tempRoot,
|
||||
stdio: "inherit",
|
||||
});
|
||||
@@ -107,6 +107,40 @@ try {
|
||||
"Expected bun.lock to contain the smoke version.",
|
||||
);
|
||||
|
||||
const nightlyReleaseMetadata = execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
resolve(repoRoot, "scripts/resolve-nightly-release.ts"),
|
||||
"--date",
|
||||
"20260413",
|
||||
"--run-number",
|
||||
"321",
|
||||
"--sha",
|
||||
"abcdef1234567890",
|
||||
"--root",
|
||||
tempRoot,
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
encoding: "utf8",
|
||||
},
|
||||
);
|
||||
assertContains(
|
||||
nightlyReleaseMetadata,
|
||||
"version=9.9.9-nightly.20260413.321",
|
||||
"Expected nightly metadata to contain the derived nightly version.",
|
||||
);
|
||||
assertContains(
|
||||
nightlyReleaseMetadata,
|
||||
"tag=nightly-v9.9.9-nightly.20260413.321",
|
||||
"Expected nightly metadata to contain the derived nightly tag.",
|
||||
);
|
||||
assertContains(
|
||||
nightlyReleaseMetadata,
|
||||
"name=T3 Code Nightly 9.9.9-nightly.20260413.321 (abcdef123456)",
|
||||
"Expected nightly metadata to include the short commit SHA in the release name.",
|
||||
);
|
||||
|
||||
const { arm64Path, x64Path } = writeMacManifestFixtures(tempRoot);
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
|
||||
import {
|
||||
resolveNightlyBaseVersion,
|
||||
resolveNightlyReleaseMetadata,
|
||||
} from "./resolve-nightly-release.ts";
|
||||
|
||||
it("strips prerelease and build metadata when deriving the nightly base version", () => {
|
||||
assert.equal(resolveNightlyBaseVersion("0.0.17"), "0.0.17");
|
||||
assert.equal(resolveNightlyBaseVersion("9.9.9-smoke.0"), "9.9.9");
|
||||
assert.equal(resolveNightlyBaseVersion("1.2.3-beta.4+build.9"), "1.2.3");
|
||||
});
|
||||
|
||||
it("derives nightly metadata including the short commit sha in the release name", () => {
|
||||
assert.deepStrictEqual(
|
||||
resolveNightlyReleaseMetadata("9.9.9", "20260413", 321, "abcdef1234567890"),
|
||||
{
|
||||
baseVersion: "9.9.9",
|
||||
version: "9.9.9-nightly.20260413.321",
|
||||
tag: "nightly-v9.9.9-nightly.20260413.321",
|
||||
name: "T3 Code Nightly 9.9.9-nightly.20260413.321 (abcdef123456)",
|
||||
shortSha: "abcdef123456",
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Config, Effect, FileSystem, Option, Path, Schema } from "effect";
|
||||
import { Command, Flag } from "effect/unstable/cli";
|
||||
|
||||
interface NightlyReleaseMetadata {
|
||||
readonly baseVersion: string;
|
||||
readonly version: string;
|
||||
readonly tag: string;
|
||||
readonly name: string;
|
||||
readonly shortSha: string;
|
||||
}
|
||||
|
||||
const DateSchema = Schema.String.check(Schema.isPattern(/^\d{8}$/));
|
||||
const RunNumberSchema = Schema.FiniteFromString.check(
|
||||
Schema.isInt(),
|
||||
Schema.isGreaterThanOrEqualTo(1),
|
||||
);
|
||||
const ShaSchema = Schema.String.check(Schema.isPattern(/^[0-9a-f]{7,40}$/i));
|
||||
const DesktopPackageJsonSchema = Schema.Struct({
|
||||
version: Schema.NonEmptyString,
|
||||
});
|
||||
|
||||
const RepoRoot = Effect.service(Path.Path).pipe(
|
||||
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
|
||||
);
|
||||
const decodeDesktopPackageJson = Schema.decodeUnknownEffect(
|
||||
Schema.fromJsonString(DesktopPackageJsonSchema),
|
||||
);
|
||||
|
||||
export const resolveNightlyBaseVersion = (version: string) => version.replace(/[-+].*$/, "");
|
||||
|
||||
export const resolveNightlyReleaseMetadata = (
|
||||
baseVersion: string,
|
||||
date: string,
|
||||
runNumber: number,
|
||||
sha: string,
|
||||
) => {
|
||||
const shortSha = sha.slice(0, 12);
|
||||
const version = `${baseVersion}-nightly.${date}.${runNumber}`;
|
||||
return {
|
||||
baseVersion,
|
||||
version,
|
||||
tag: `nightly-v${version}`,
|
||||
name: `T3 Code Nightly ${version} (${shortSha})`,
|
||||
shortSha,
|
||||
};
|
||||
};
|
||||
|
||||
const readDesktopBaseVersion = Effect.fn("readDesktopBaseVersion")(function* (
|
||||
rootDir: string | undefined,
|
||||
) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const workspaceRoot = rootDir ? path.resolve(rootDir) : yield* RepoRoot;
|
||||
const packageJsonPath = path.join(workspaceRoot, "apps/desktop/package.json");
|
||||
const packageJson = yield* fs
|
||||
.readFileString(packageJsonPath)
|
||||
.pipe(Effect.flatMap(decodeDesktopPackageJson));
|
||||
return resolveNightlyBaseVersion(packageJson.version);
|
||||
});
|
||||
|
||||
const writeOutput = Effect.fn("writeOutput")(function* (
|
||||
metadata: NightlyReleaseMetadata,
|
||||
writeGithubOutput: boolean,
|
||||
) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
|
||||
const entries = [
|
||||
["base_version", metadata.baseVersion],
|
||||
["version", metadata.version],
|
||||
["tag", metadata.tag],
|
||||
["name", metadata.name],
|
||||
["short_sha", metadata.shortSha],
|
||||
] as const;
|
||||
|
||||
if (writeGithubOutput) {
|
||||
const githubOutputPath = yield* Config.nonEmptyString("GITHUB_OUTPUT");
|
||||
const serialized = entries.map(([key, value]) => `${key}=${value}\n`).join("");
|
||||
yield* fs.writeFileString(githubOutputPath, serialized, { flag: "a" });
|
||||
} else {
|
||||
for (const [key, value] of entries) {
|
||||
console.log(`${key}=${value}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const command = Command.make(
|
||||
"resolve-nightly-release",
|
||||
{
|
||||
date: Flag.string("date").pipe(
|
||||
Flag.withSchema(DateSchema),
|
||||
Flag.withDescription("Nightly build date in YYYYMMDD."),
|
||||
),
|
||||
runNumber: Flag.string("run-number").pipe(
|
||||
Flag.withSchema(RunNumberSchema),
|
||||
Flag.withDescription("GitHub Actions run number."),
|
||||
),
|
||||
sha: Flag.string("sha").pipe(
|
||||
Flag.withSchema(ShaSchema),
|
||||
Flag.withDescription("Commit sha for the nightly build."),
|
||||
),
|
||||
githubOutput: Flag.boolean("github-output").pipe(
|
||||
Flag.withDescription("Write values to GITHUB_OUTPUT instead of stdout."),
|
||||
Flag.withDefault(false),
|
||||
),
|
||||
root: Flag.string("root").pipe(
|
||||
Flag.withDescription("Workspace root used to resolve apps/desktop/package.json."),
|
||||
Flag.optional,
|
||||
),
|
||||
},
|
||||
({ date, runNumber, sha, githubOutput, root }) =>
|
||||
readDesktopBaseVersion(Option.getOrUndefined(root)).pipe(
|
||||
Effect.map((baseVersion) => resolveNightlyReleaseMetadata(baseVersion, date, runNumber, sha)),
|
||||
Effect.flatMap((metadata) => writeOutput(metadata, githubOutput)),
|
||||
),
|
||||
).pipe(Command.withDescription("Resolve nightly release version metadata."));
|
||||
|
||||
if (import.meta.main) {
|
||||
Command.run(command, { version: "0.0.0" }).pipe(
|
||||
Effect.provide(NodeServices.layer),
|
||||
NodeRuntime.runMain,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Array, Config, Effect, FileSystem, Schema, Stream, String } from "effect";
|
||||
import { Command, Flag } from "effect/unstable/cli";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
const ReleaseChannel = Schema.Literals(["stable", "nightly"]);
|
||||
type ReleaseChannel = typeof ReleaseChannel.Type;
|
||||
|
||||
interface StableVersion {
|
||||
readonly major: number;
|
||||
readonly minor: number;
|
||||
readonly patch: number;
|
||||
readonly prerelease: ReadonlyArray<string>;
|
||||
}
|
||||
|
||||
interface NightlyVersion {
|
||||
readonly major: number;
|
||||
readonly minor: number;
|
||||
readonly patch: number;
|
||||
readonly date: number;
|
||||
readonly runNumber: number;
|
||||
}
|
||||
|
||||
const parseNumericIdentifier = (identifier: string): number | undefined =>
|
||||
/^\d+$/.test(identifier) ? Number(identifier) : undefined;
|
||||
|
||||
const comparePrereleaseIdentifiers = (left: string, right: string): number => {
|
||||
const leftNumeric = parseNumericIdentifier(left);
|
||||
const rightNumeric = parseNumericIdentifier(right);
|
||||
|
||||
if (leftNumeric !== undefined && rightNumeric !== undefined) {
|
||||
return leftNumeric - rightNumeric;
|
||||
}
|
||||
if (leftNumeric !== undefined) {
|
||||
return -1;
|
||||
}
|
||||
if (rightNumeric !== undefined) {
|
||||
return 1;
|
||||
}
|
||||
return left.localeCompare(right);
|
||||
};
|
||||
|
||||
const compareStableVersions = (left: StableVersion, right: StableVersion): number => {
|
||||
if (left.major !== right.major) return left.major - right.major;
|
||||
if (left.minor !== right.minor) return left.minor - right.minor;
|
||||
if (left.patch !== right.patch) return left.patch - right.patch;
|
||||
|
||||
const leftHasPrerelease = left.prerelease.length > 0;
|
||||
const rightHasPrerelease = right.prerelease.length > 0;
|
||||
if (!leftHasPrerelease && !rightHasPrerelease) return 0;
|
||||
if (!leftHasPrerelease) return 1;
|
||||
if (!rightHasPrerelease) return -1;
|
||||
|
||||
const maxLength = Math.max(left.prerelease.length, right.prerelease.length);
|
||||
for (let index = 0; index < maxLength; index += 1) {
|
||||
const leftIdentifier = left.prerelease[index];
|
||||
const rightIdentifier = right.prerelease[index];
|
||||
if (leftIdentifier === undefined) return -1;
|
||||
if (rightIdentifier === undefined) return 1;
|
||||
|
||||
const comparison = comparePrereleaseIdentifiers(leftIdentifier, rightIdentifier);
|
||||
if (comparison !== 0) return comparison;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
const parseStableTag = (tag: string): StableVersion | undefined => {
|
||||
const match = /^v(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(tag);
|
||||
if (!match) return undefined;
|
||||
|
||||
const [, major, minor, patch, prerelease] = match;
|
||||
if (!major || !minor || !patch) return undefined;
|
||||
|
||||
return {
|
||||
major: Number(major),
|
||||
minor: Number(minor),
|
||||
patch: Number(patch),
|
||||
prerelease: prerelease ? prerelease.split(".") : [],
|
||||
};
|
||||
};
|
||||
|
||||
const compareNightlyVersions = (left: NightlyVersion, right: NightlyVersion): number => {
|
||||
if (left.major !== right.major) return left.major - right.major;
|
||||
if (left.minor !== right.minor) return left.minor - right.minor;
|
||||
if (left.patch !== right.patch) return left.patch - right.patch;
|
||||
if (left.date !== right.date) return left.date - right.date;
|
||||
return left.runNumber - right.runNumber;
|
||||
};
|
||||
|
||||
const parseNightlyTag = (tag: string): NightlyVersion | undefined => {
|
||||
const match = /^nightly-v(\d+)\.(\d+)\.(\d+)-nightly\.(\d{8})\.(\d+)$/.exec(tag);
|
||||
if (!match) return undefined;
|
||||
|
||||
const [, major, minor, patch, date, runNumber] = match;
|
||||
if (!major || !minor || !patch || !date || !runNumber) return undefined;
|
||||
|
||||
return {
|
||||
major: Number(major),
|
||||
minor: Number(minor),
|
||||
patch: Number(patch),
|
||||
date: Number(date),
|
||||
runNumber: Number(runNumber),
|
||||
};
|
||||
};
|
||||
|
||||
const resolvePreviousReleaseTag = (
|
||||
channel: ReleaseChannel,
|
||||
currentTag: string,
|
||||
tags: ReadonlyArray<string>,
|
||||
): string | undefined => {
|
||||
if (channel === "stable") {
|
||||
const current = parseStableTag(currentTag);
|
||||
if (!current) {
|
||||
throw new Error(`Invalid stable release tag '${currentTag}'.`);
|
||||
}
|
||||
|
||||
const candidates = tags
|
||||
.map((tag) => ({ tag, parsed: parseStableTag(tag) }))
|
||||
.filter(
|
||||
(entry): entry is { tag: string; parsed: StableVersion } => entry.parsed !== undefined,
|
||||
)
|
||||
.filter((entry) => compareStableVersions(entry.parsed, current) < 0)
|
||||
.toSorted((left, right) => compareStableVersions(right.parsed, left.parsed));
|
||||
|
||||
return candidates[0]?.tag;
|
||||
}
|
||||
|
||||
const current = parseNightlyTag(currentTag);
|
||||
if (!current) {
|
||||
throw new Error(`Invalid nightly release tag '${currentTag}'.`);
|
||||
}
|
||||
|
||||
const candidates = tags
|
||||
.map((tag) => ({ tag, parsed: parseNightlyTag(tag) }))
|
||||
.filter((entry): entry is { tag: string; parsed: NightlyVersion } => entry.parsed !== undefined)
|
||||
.filter((entry) => compareNightlyVersions(entry.parsed, current) < 0)
|
||||
.toSorted((left, right) => compareNightlyVersions(right.parsed, left.parsed));
|
||||
|
||||
return candidates[0]?.tag;
|
||||
};
|
||||
|
||||
const listGitTags = Effect.fn("listGitTags")(function* () {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const child = yield* spawner.spawn(ChildProcess.make("git", ["tag", "--list"]));
|
||||
const tags = yield* child.stdout.pipe(
|
||||
Stream.decodeText(),
|
||||
Stream.runFold(
|
||||
() => "",
|
||||
(acc, chunk) => acc + chunk,
|
||||
),
|
||||
Effect.map(String.split(/\r?\n/)),
|
||||
Effect.map(Array.map(String.trim)),
|
||||
Effect.map(Array.filter(String.isNonEmpty)),
|
||||
);
|
||||
return tags;
|
||||
});
|
||||
|
||||
const writeOutput = Effect.fn("writeOutput")(function* (
|
||||
previousTag: string | undefined,
|
||||
writeGithubOutput: boolean,
|
||||
) {
|
||||
const entry = `previous_tag=${previousTag ?? ""}\n`;
|
||||
|
||||
if (writeGithubOutput) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const githubOutputPath = yield* Config.nonEmptyString("GITHUB_OUTPUT");
|
||||
yield* fs.writeFileString(githubOutputPath, entry, { flag: "a" });
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(entry);
|
||||
});
|
||||
|
||||
const command = Command.make(
|
||||
"resolve-previous-release-tag",
|
||||
{
|
||||
channel: Flag.choice("channel", ReleaseChannel.literals).pipe(
|
||||
Flag.withDescription("Release channel whose previous tag should be resolved."),
|
||||
),
|
||||
currentTag: Flag.string("current-tag").pipe(
|
||||
Flag.withDescription("Current release tag to compare against."),
|
||||
),
|
||||
githubOutput: Flag.boolean("github-output").pipe(
|
||||
Flag.withDescription("Write values to GITHUB_OUTPUT instead of stdout."),
|
||||
Flag.withDefault(false),
|
||||
),
|
||||
},
|
||||
({ channel, currentTag, githubOutput }) =>
|
||||
listGitTags().pipe(
|
||||
Effect.map((tags) => resolvePreviousReleaseTag(channel, currentTag, tags)),
|
||||
Effect.flatMap((previousTag) => writeOutput(previousTag, githubOutput)),
|
||||
),
|
||||
).pipe(Command.withDescription("Resolve the previous release tag for a stable or nightly series."));
|
||||
|
||||
Command.run(command, { version: "0.0.0" }).pipe(
|
||||
Effect.scoped,
|
||||
Effect.provide(NodeServices.layer),
|
||||
NodeRuntime.runMain,
|
||||
);
|
||||
Reference in new issue
Block a user