Skip to content
Merged
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
54 changes: 52 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,60 @@ jobs:
path: release-publish/*
if-no-files-found: error

publish_fork_cli:
name: Publish fork CLI to npm
needs: preflight
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }}
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
id-token: write
env:
VERSION: ${{ needs.preflight.outputs.version }}
IS_PRERELEASE: ${{ needs.preflight.outputs.is_prerelease }}
steps:
- name: Checkout immutable release commit
uses: actions/checkout@v6
with:
ref: ${{ needs.preflight.outputs.commit_sha }}
fetch-depth: 0

- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1
with:
node-version-file: package.json
cache: true
run-install: true

- name: Align package metadata to the release version
run: node scripts/update-release-package-versions.ts "$VERSION"

- name: Build web package for the CLI bundle
run: vp run --filter @t3tools/web build

- name: Build fork CLI package
run: node apps/server/scripts/cli.ts build

- name: Publish and verify the exact fork CLI version
shell: bash
run: |
set -euo pipefail
dist_tag=latest
if [[ "$IS_PRERELEASE" == "true" ]]; then
dist_tag=next
fi
node apps/server/scripts/cli.ts publish --tag "$dist_tag" --app-version "$VERSION" --provenance --verbose
published_version="$(npm view "@ag-jin/t3code@${VERSION}" version)"
if [[ "$published_version" != "$VERSION" ]]; then
echo "Published fork CLI version did not match the release tag." >&2
exit 1
fi

release:
name: Publish fork GitHub Release
needs: [preflight, build]
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' }}
needs: [preflight, build, publish_fork_cli]
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' && needs.publish_fork_cli.result == 'success' }}
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
Expand Down
3 changes: 2 additions & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "t3",
"version": "0.0.28",
"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/pingdotgg/t3code",
"url": "https://github.com/ag-jin/t3code-2K",
"directory": "apps/server"
},
"bin": {
Expand Down
26 changes: 26 additions & 0 deletions apps/server/scripts/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { assert, it } from "@effect/vitest";

import { createVpPmPublishArgs } from "./cli.ts";

it("publishes the fork package rather than the private workspace package", () => {
assert.deepEqual(
createVpPmPublishArgs({
access: "public",
tag: "next",
provenance: true,
dryRun: true,
}),
[
"publish",
"--filter",
"@ag-jin/t3code",
"--access",
"public",
"--tag",
"next",
"--no-git-checks",
"--provenance",
"--dry-run",
],
);
});
29 changes: 18 additions & 11 deletions apps/server/scripts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";
import { fromYaml } from "@t3tools/shared/schemaYaml";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
import serverPackageJson from "../package.json" with { type: "json" };
import {
forkServerCliBinary,
forkServerPackageName,
forkServerRepositoryUrl,
} from "../src/packageIdentity.ts";
import {
ServerCliBuildAssetMissingError,
ServerCliCommandExitError,
Expand Down Expand Up @@ -186,11 +191,11 @@ interface PublishCommandConfig {
readonly dryRun: boolean;
}

const createVpPmPublishArgs = (config: PublishCommandConfig): ReadonlyArray<string> => {
export const createVpPmPublishArgs = (config: PublishCommandConfig): ReadonlyArray<string> => {
const args = [
"publish",
"--filter",
"t3",
forkServerPackageName,
"--access",
config.access,
"--tag",
Expand Down Expand Up @@ -238,9 +243,9 @@ const publishCmd = Command.make(
const workspaceCatalog = workspaceConfig.catalog ?? {};
const workspaceOverrides = workspaceConfig.overrides ?? {};
const pkg: PackageJson = {
name: serverPackageJson.name,
repository: serverPackageJson.repository,
bin: serverPackageJson.bin,
name: forkServerPackageName,
repository: { ...serverPackageJson.repository, url: forkServerRepositoryUrl },
bin: { [forkServerCliBinary]: "./dist/bin.mjs" },
type: serverPackageJson.type,
version,
engines: serverPackageJson.engines,
Expand Down Expand Up @@ -303,13 +308,15 @@ const publishCmd = Command.make(
// root command
// ---------------------------------------------------------------------------

const cli = Command.make("cli").pipe(
export const cli = Command.make("cli").pipe(
Command.withDescription("T3 server build & publish CLI."),
Command.withSubcommands([buildCmd, publishCmd]),
);

Command.run(cli, { version: "0.0.0" }).pipe(
Effect.scoped,
Effect.provide([Logger.layer([Logger.consolePretty()]), NodeServices.layer]),
NodeRuntime.runMain,
);
if (import.meta.main) {
Command.run(cli, { version: "0.0.0" }).pipe(
Effect.scoped,
Effect.provide([Logger.layer([Logger.consolePretty()]), NodeServices.layer]),
NodeRuntime.runMain,
);
}
45 changes: 29 additions & 16 deletions apps/server/src/cloud/bootService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const makeTestContext = Effect.fn("test.makeTestContext")(function* () {
it("renders a systemd unit with absolute paths and append-mode logging", () => {
const unit = BootService.renderBootServiceUnit({
nodePath: "/usr/local/bin/node",
t3EntryPath: "/home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs",
t3EntryPath: "/home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs",
baseDir: "/home/theo/.t3",
logPath: "/home/theo/.t3/userdata/logs/boot-service.log",
unitPath: "/home/theo/.config/systemd/user/t3code.service",
Expand All @@ -110,7 +110,7 @@ it("renders a systemd unit with absolute paths and append-mode logging", () => {
"WorkingDirectory=%h",
"Environment=T3CODE_HOME=/home/theo/.t3",
"Environment=T3_BOOT_SERVICE_UNIT=t3code.service",
"ExecStart=/usr/local/bin/node /home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs serve",
"ExecStart=/usr/local/bin/node /home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs serve",
"Restart=always",
"RestartSec=5",
"StandardOutput=append:/home/theo/.t3/userdata/logs/boot-service.log",
Expand Down Expand Up @@ -145,28 +145,34 @@ it("quotes systemd values containing spaces and escapes percent specifiers", ()

it("flags package-manager cache entry points as ephemeral", () => {
assert.isTrue(
BootService.isEphemeralCacheEntry("/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs"),
BootService.isEphemeralCacheEntry(
"/home/theo/.npm/_npx/abc123/node_modules/@ag-jin/t3code/dist/bin.mjs",
),
);
assert.isTrue(
BootService.isEphemeralCacheEntry("C:\\Users\\theo\\AppData\\npm-cache\\_npx\\abc\\bin.mjs"),
);
assert.isTrue(
BootService.isEphemeralCacheEntry(
"/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs",
"/home/theo/.cache/pnpm/dlx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs",
),
);
assert.isTrue(
BootService.isEphemeralCacheEntry("/home/theo/.bun/install/cache/t3@0.0.27/dist/bin.mjs"),
BootService.isEphemeralCacheEntry(
"/home/theo/.bun/install/cache/@ag-jin/t3code@0.0.27/dist/bin.mjs",
),
);
assert.isFalse(
BootService.isEphemeralCacheEntry("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"),
);
assert.isFalse(BootService.isEphemeralCacheEntry("/usr/local/lib/node_modules/t3/dist/bin.mjs"));
assert.isFalse(
BootService.isEphemeralCacheEntry(
"/home/theo/dev/pnpm/dlx-tools/t3/node_modules/t3/dist/bin.mjs",
"/home/theo/dev/pnpm/dlx-tools/t3/node_modules/@ag-jin/t3code/dist/bin.mjs",
),
);
assert.isFalse(
BootService.isEphemeralCacheEntry(
"/home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs",
"/home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs",
),
);
});
Expand Down Expand Up @@ -254,19 +260,26 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"),
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(Effect.provide(makeRecordingRunnerLayer(commands)), provideHostRefs(dirs.home));

const plan = yield* service.install;

const runtimeDir = path.join(dirs.baseDir, "runtime", "versions", "0.0.27");
assert.equal(
plan.t3EntryPath,
path.join(runtimeDir, "node_modules", "t3", "dist", "bin.mjs"),
path.join(runtimeDir, "node_modules", "@ag-jin", "t3code", "dist", "bin.mjs"),
);
assert.deepEqual(commands[0], {
command: "npm",
args: ["install", "--prefix", runtimeDir, "--no-fund", "--no-audit", "t3@0.0.27"],
args: [
"install",
"--prefix",
runtimeDir,
"--no-fund",
"--no-audit",
"@ag-jin/t3code@0.0.27",
],
});
// Success is recorded via a sentinel so interrupted installs re-run.
assert.isTrue(yield* fs.exists(path.join(runtimeDir, ".install-complete")));
Expand All @@ -281,7 +294,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"),
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(Effect.provide(makeRecordingRunnerLayer(commands)), provideHostRefs(dirs.home));

const plan = yield* service.install;
Expand Down Expand Up @@ -325,7 +338,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"),
host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(
Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "npm" })),
provideHostRefs(dirs.home),
Expand Down Expand Up @@ -396,7 +409,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"),
host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(
Effect.provide(makeRecordingRunnerLayer(commands)),
provideHostRefs(dirs.home, "darwin"),
Expand All @@ -423,7 +436,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"),
host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(
Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "loginctl" })),
provideHostRefs(dirs.home),
Expand Down Expand Up @@ -538,7 +551,7 @@ it.layer(NodeServices.layer)("BootService", (it) => {
baseDir: dirs.baseDir,
logsDir: dirs.logsDir,
cliVersion: "0.0.27",
host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"),
host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"),
}).pipe(
Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "systemctl" })),
provideHostRefs(dirs.home),
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/cloud/bootService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ensurePinnedRuntimeInstalled, pinnedRuntimePaths } from "./pinnedRuntim
/**
* Installs T3 Code as a per-user boot service. Linux-only for now: systemd
* user unit + loginctl enable-linger. The service runs a stable or pinned
* runtime — never an ephemeral `npx t3` cache whose eviction could break
* runtime — never an ephemeral `npx @ag-jin/t3code` cache whose eviction could break
* startup.
*/

Expand All @@ -39,7 +39,7 @@ const EPHEMERAL_CACHE_SEGMENTS = [
];

/**
* `npx t3` (and pnpm dlx / bunx) run out of ephemeral package-manager
* `npx @ag-jin/t3code` (and pnpm dlx / bunx) run out of ephemeral package-manager
* caches that can be evicted at any time — a boot service must never point
* there. Global installs, repo checkouts, and the pinned runtime below are
* all stable.
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/cloud/pinnedRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import {
} from "./pinnedRuntime.ts";

it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
it.effect("resolves the fork package as the pinned runtime entry", () =>
Effect.gen(function* () {
const path = yield* Path.Path;
const paths = pinnedRuntimePaths(path, "/tmp/t3", "0.0.30");

assert.equal(
paths.entryPath,
"/tmp/t3/runtime/versions/0.0.30/node_modules/@ag-jin/t3code/dist/bin.mjs",
);
}),
);

it.effect("serializes concurrent installs of the same runtime", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
21 changes: 15 additions & 6 deletions apps/server/src/cloud/pinnedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import * as Schema from "effect/Schema";
import * as Semaphore from "effect/Semaphore";

import * as ProcessRunner from "../processRunner.ts";
import { forkServerPackageName } from "../packageIdentity.ts";

/**
* A pinned runtime is an exact `t3@<version>` npm-installed into
* A pinned runtime is an exact `@ag-jin/t3code@<version>` npm-installed into
* <baseDir>/runtime/versions/<version>. The boot service points its systemd
* unit here, and server self-update installs the target version here before
* switching over — never `npx t3`, whose cache is ephemeral and whose
* switching over — never `npx @ag-jin/t3code`, whose cache is ephemeral and whose
* registry fetch at boot would make startup depend on the network.
*/

const PINNED_RUNTIME_DIR = "runtime";
const PINNED_RUNTIME_INSTALL_TIMEOUT = Duration.minutes(10);
const PUBLISHED_SERVER_PACKAGE_NAME = forkServerPackageName;
const PUBLISHED_SERVER_PACKAGE_PATH = PUBLISHED_SERVER_PACKAGE_NAME.split("/");
// Boot-service setup and remote self-update share this module but can be
// constructed in separate layers. Serialize the complete check/install/
// sentinel transaction across all callers in this process.
Expand All @@ -36,7 +39,13 @@ export function pinnedRuntimePaths(
const versionDir = path.join(baseDir, PINNED_RUNTIME_DIR, "versions", version);
return {
versionDir,
entryPath: path.join(versionDir, "node_modules", "t3", "dist", "bin.mjs"),
entryPath: path.join(
versionDir,
"node_modules",
...PUBLISHED_SERVER_PACKAGE_PATH,
"dist",
"bin.mjs",
),
sentinelPath: path.join(versionDir, ".install-complete"),
};
}
Expand All @@ -59,7 +68,7 @@ export class PinnedRuntimeInstallError extends Schema.TaggedErrorClass<PinnedRun
}

/**
* Installs `t3@<version>` into the pinned runtime directory unless a complete
* Installs `@ag-jin/t3code@<version>` into the pinned runtime directory unless a complete
* install is already there, and returns its paths. The sentinel is written
* only after npm exits 0; checking the entry file alone is not enough — npm
* extracts files before running native builds (node-pty), so a killed
Expand Down Expand Up @@ -103,7 +112,7 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu
),
);

const installStep = "installing the pinned t3 runtime (this can take a few minutes)";
const installStep = `installing the pinned ${PUBLISHED_SERVER_PACKAGE_NAME} runtime (this can take a few minutes)`;
yield* runner
.run({
command: "npm",
Expand All @@ -113,7 +122,7 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu
paths.versionDir,
"--no-fund",
"--no-audit",
`t3@${input.version}`,
`${PUBLISHED_SERVER_PACKAGE_NAME}@${input.version}`,
],
// Native deps (node-pty) can compile from source on slow boxes; the
// ProcessRunner default of 60s would kill a healthy install.
Expand Down
Loading
Loading