tui: set up for publishing via github actions (#8020)
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Builds the goose-acp-server binary for target platforms and places them
|
||||
* into the corresponding npm package directories under native/.
|
||||
*
|
||||
* Usage:
|
||||
* npm run build:native # build for current platform only
|
||||
* npm run build:native:all # build for all platforms
|
||||
* tsx scripts/build-native.ts darwin-arm64 # build specific platform
|
||||
*
|
||||
* Prerequisites:
|
||||
* - Rust cross-compilation toolchains installed for each target
|
||||
*/
|
||||
|
||||
import { execSync } from "child_process";
|
||||
import { dirname, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { mkdirSync, copyFileSync, chmodSync, existsSync } from "fs";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const ROOT = resolve(__dirname, "../../..");
|
||||
const NATIVE_DIR = resolve(ROOT, "ui/goose-acp-server");
|
||||
|
||||
const RUST_TARGETS: Record<string, string> = {
|
||||
"darwin-arm64": "aarch64-apple-darwin",
|
||||
"darwin-x64": "x86_64-apple-darwin",
|
||||
"linux-arm64": "aarch64-unknown-linux-gnu",
|
||||
"linux-x64": "x86_64-unknown-linux-gnu",
|
||||
"win32-x64": "x86_64-pc-windows-msvc",
|
||||
};
|
||||
|
||||
const PLATFORM_MAP: Record<string, string> = {
|
||||
"darwin-arm64": "darwin-arm64",
|
||||
"darwin-x64": "darwin-x64",
|
||||
"linux-arm64": "linux-arm64",
|
||||
"linux-x64": "linux-x64",
|
||||
"win32-x64": "win32-x64",
|
||||
};
|
||||
|
||||
function getCurrentPlatform(): string | null {
|
||||
const platform = process.platform;
|
||||
const arch = process.arch;
|
||||
const key = `${platform}-${arch}`;
|
||||
return PLATFORM_MAP[key] || null;
|
||||
}
|
||||
|
||||
function buildTarget(platform: string): void {
|
||||
const rustTarget = RUST_TARGETS[platform];
|
||||
if (!rustTarget) {
|
||||
throw new Error(`Unknown platform: ${platform}`);
|
||||
}
|
||||
|
||||
const pkgDir = resolve(NATIVE_DIR, `goose-acp-server-${platform}`);
|
||||
const binDir = resolve(pkgDir, "bin");
|
||||
|
||||
console.log(`==> Building goose-acp-server for ${platform} (${rustTarget})`);
|
||||
|
||||
try {
|
||||
execSync(
|
||||
`cargo build --release --target ${rustTarget} --bin goose-acp-server`,
|
||||
{
|
||||
cwd: ROOT,
|
||||
stdio: "inherit",
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`Failed to build for ${platform}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
mkdirSync(binDir, { recursive: true });
|
||||
|
||||
const ext = platform.startsWith("win32") ? ".exe" : "";
|
||||
const binaryName = `goose-acp-server${ext}`;
|
||||
const srcPath = resolve(ROOT, "target", rustTarget, "release", binaryName);
|
||||
const destPath = resolve(binDir, binaryName);
|
||||
|
||||
if (!existsSync(srcPath)) {
|
||||
throw new Error(`Binary not found at ${srcPath}`);
|
||||
}
|
||||
|
||||
copyFileSync(srcPath, destPath);
|
||||
chmodSync(destPath, 0o755);
|
||||
|
||||
console.log(` ✅ Placed binary at ${destPath}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const buildAll = args.includes("--all");
|
||||
|
||||
if (buildAll) {
|
||||
console.log("==> Building for all platforms");
|
||||
for (const platform of Object.keys(RUST_TARGETS)) {
|
||||
try {
|
||||
buildTarget(platform);
|
||||
} catch (err) {
|
||||
console.error(`Failed to build ${platform}:`, err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
} else if (args.length > 0 && !args[0].startsWith("--")) {
|
||||
// Build specific platforms
|
||||
for (const platform of args) {
|
||||
if (!RUST_TARGETS[platform]) {
|
||||
console.error(`Unknown platform: ${platform}`);
|
||||
console.error(`Valid platforms: ${Object.keys(RUST_TARGETS).join(", ")}`);
|
||||
process.exit(1);
|
||||
}
|
||||
buildTarget(platform);
|
||||
}
|
||||
} else {
|
||||
// Build for current platform only
|
||||
const currentPlatform = getCurrentPlatform();
|
||||
if (!currentPlatform) {
|
||||
console.error(
|
||||
`Unsupported platform: ${process.platform}-${process.arch}`
|
||||
);
|
||||
console.error(`Valid platforms: ${Object.keys(RUST_TARGETS).join(", ")}`);
|
||||
console.error(`Use --all to build for all platforms`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`==> Building for current platform: ${currentPlatform}`);
|
||||
buildTarget(currentPlatform);
|
||||
}
|
||||
|
||||
console.log("==> Done. Native packages staged in ui/goose-acp-server/");
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Builds the generate-acp-schema Rust binary and runs it to generate
|
||||
* acp-schema.json and acp-meta.json, then generates TypeScript types.
|
||||
*
|
||||
* Usage:
|
||||
* npm run build:schema
|
||||
*/
|
||||
|
||||
import { execSync } from "child_process";
|
||||
import { dirname, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { existsSync, copyFileSync, mkdirSync } from "fs";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const ROOT = resolve(__dirname, "../../..");
|
||||
const ACP_CRATE = resolve(ROOT, "crates/goose-acp");
|
||||
const SCHEMA_PATH = resolve(ACP_CRATE, "acp-schema.json");
|
||||
const META_PATH = resolve(ACP_CRATE, "acp-meta.json");
|
||||
const LOCAL_SCHEMA_PATH = resolve(__dirname, "..", "acp-schema.json");
|
||||
const LOCAL_META_PATH = resolve(__dirname, "..", "acp-meta.json");
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
async function main() {
|
||||
console.log("==> Building generate-acp-schema binary...");
|
||||
|
||||
try {
|
||||
execSync(
|
||||
"cargo build --release --bin generate-acp-schema",
|
||||
{
|
||||
cwd: ROOT,
|
||||
stdio: "inherit",
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Failed to build generate-acp-schema binary");
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log("==> Running generate-acp-schema...");
|
||||
|
||||
try {
|
||||
execSync(
|
||||
"cargo run --release --bin generate-acp-schema",
|
||||
{
|
||||
cwd: ACP_CRATE,
|
||||
stdio: "inherit",
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Failed to generate schema");
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Copy schema files to ui/acp for reference
|
||||
console.log("==> Copying schema files to ui/acp...");
|
||||
mkdirSync(dirname(LOCAL_SCHEMA_PATH), { recursive: true });
|
||||
copyFileSync(SCHEMA_PATH, LOCAL_SCHEMA_PATH);
|
||||
copyFileSync(META_PATH, LOCAL_META_PATH);
|
||||
|
||||
console.log("==> Generating TypeScript types...");
|
||||
|
||||
// Import and run the generate-schema logic
|
||||
const { default: generateSchema } = await import("../generate-schema.js");
|
||||
await generateSchema();
|
||||
|
||||
console.log("✅ Schema generation complete");
|
||||
}
|
||||
Reference in New Issue
Block a user