mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-05-31 13:56:13 -07:00
refactor(cli): reorganize commands — add test, alias orchestrate to o, extract shared options
- Add `test` / `t` command mirroring unity-test-runner (EditMode, PlayMode, All, code coverage, test filters) - Add `o` short alias for `orchestrate` command - Extract shared option builders (project, docker, android, orchestrator) to eliminate duplication across build/test/orchestrate - Make `build` local-only — remove --provider-strategy (use `orchestrate` for remote builds) - Absorb `cache` command into `status` (--cache-dir flag) — remove standalone cache command that was half-implemented - Fix `list-worfklow` typo in internal CLI → `list-workflow` - Add test-related fields to CliArguments input mapper - Update all unit and integration tests (64 passing) Command structure is now: game-ci build Local build (Docker/macOS) game-ci test / t Run Unity tests game-ci orchestrate / o Remote build (AWS/K8s/etc) game-ci activate License validation game-ci status Project info + cache status game-ci version Version info game-ci update Self-update Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
6
dist/index.js
generated
vendored
6
dist/index.js
generated
vendored
@@ -678,7 +678,7 @@ class Cli {
|
||||
orchestrator_logger_1.default.log(JSON.stringify(result, undefined, 4));
|
||||
return result.map((x) => x.Name);
|
||||
}
|
||||
static async ListWorfklow() {
|
||||
static async ListWorkflow() {
|
||||
const buildParameter = await __1.BuildParameters.create();
|
||||
await __1.Orchestrator.setup(buildParameter);
|
||||
return (await __1.Orchestrator.Provider.listWorkflow()).map((x) => x.Name);
|
||||
@@ -708,8 +708,8 @@ __decorate([
|
||||
(0, cli_functions_repository_1.CliFunction)(`list-resources`, `lists active resources`)
|
||||
], Cli, "ListResources", null);
|
||||
__decorate([
|
||||
(0, cli_functions_repository_1.CliFunction)(`list-worfklow`, `lists running workflows`)
|
||||
], Cli, "ListWorfklow", null);
|
||||
(0, cli_functions_repository_1.CliFunction)(`list-workflow`, `lists running workflows`)
|
||||
], Cli, "ListWorkflow", null);
|
||||
__decorate([
|
||||
(0, cli_functions_repository_1.CliFunction)(`watch`, `follows logs of a running workflow`)
|
||||
], Cli, "Watch", null);
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -4,9 +4,9 @@ import yargs from 'yargs';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import buildCommand from './cli/commands/build';
|
||||
import activateCommand from './cli/commands/activate';
|
||||
import testCommand from './cli/commands/test';
|
||||
import orchestrateCommand from './cli/commands/orchestrate';
|
||||
import cacheCommand from './cli/commands/cache';
|
||||
import activateCommand from './cli/commands/activate';
|
||||
import statusCommand from './cli/commands/status';
|
||||
import versionCommand from './cli/commands/version';
|
||||
import updateCommand from './cli/commands/update';
|
||||
@@ -16,9 +16,9 @@ const cli = yargs(hideBin(process.argv))
|
||||
.scriptName('game-ci')
|
||||
.usage('$0 <command> [options]')
|
||||
.command(buildCommand)
|
||||
.command(activateCommand)
|
||||
.command(testCommand)
|
||||
.command(orchestrateCommand)
|
||||
.command(cacheCommand)
|
||||
.command(activateCommand)
|
||||
.command(statusCommand)
|
||||
.command(versionCommand)
|
||||
.command(updateCommand)
|
||||
|
||||
@@ -36,9 +36,9 @@ describe('CLI integration', () => {
|
||||
expect(result.code).toStrictEqual(0);
|
||||
expect(result.stdout).toContain('game-ci');
|
||||
expect(result.stdout).toContain('build');
|
||||
expect(result.stdout).toContain('activate');
|
||||
expect(result.stdout).toContain('test');
|
||||
expect(result.stdout).toContain('orchestrate');
|
||||
expect(result.stdout).toContain('cache');
|
||||
expect(result.stdout).toContain('activate');
|
||||
expect(result.stdout).toContain('status');
|
||||
expect(result.stdout).toContain('version');
|
||||
expect(result.stdout).toContain('update');
|
||||
@@ -62,7 +62,24 @@ describe('CLI integration', () => {
|
||||
expect(result.stdout).toContain('--builds-path');
|
||||
expect(result.stdout).toContain('--build-method');
|
||||
expect(result.stdout).toContain('--custom-parameters');
|
||||
expect(result.stdout).toContain('--provider-strategy');
|
||||
expect(result.stdout).toContain('--versioning');
|
||||
});
|
||||
|
||||
it('exits 0 and shows test flags for test --help', async () => {
|
||||
const result = await runCli(['test', '--help']);
|
||||
|
||||
expect(result.code).toStrictEqual(0);
|
||||
expect(result.stdout).toContain('--target-platform');
|
||||
expect(result.stdout).toContain('--test-mode');
|
||||
expect(result.stdout).toContain('--test-results-path');
|
||||
expect(result.stdout).toContain('--enable-code-coverage');
|
||||
});
|
||||
|
||||
it('exits 0 for test alias t --help', async () => {
|
||||
const result = await runCli(['t', '--help']);
|
||||
|
||||
expect(result.code).toStrictEqual(0);
|
||||
expect(result.stdout).toContain('--test-mode');
|
||||
});
|
||||
|
||||
it('exits non-zero for an unknown command', async () => {
|
||||
@@ -85,6 +102,13 @@ describe('CLI integration', () => {
|
||||
expect(result.stdout).toContain('--provider-strategy');
|
||||
});
|
||||
|
||||
it('exits 0 for orchestrate alias o --help', async () => {
|
||||
const result = await runCli(['o', '--help']);
|
||||
|
||||
expect(result.code).toStrictEqual(0);
|
||||
expect(result.stdout).toContain('--provider-strategy');
|
||||
});
|
||||
|
||||
it('exits 0 for activate --help', async () => {
|
||||
const result = await runCli(['activate', '--help']);
|
||||
|
||||
@@ -92,11 +116,12 @@ describe('CLI integration', () => {
|
||||
expect(result.stdout).toContain('activate');
|
||||
});
|
||||
|
||||
it('exits 0 for cache --help', async () => {
|
||||
const result = await runCli(['cache', '--help']);
|
||||
it('exits 0 for status --help', async () => {
|
||||
const result = await runCli(['status', '--help']);
|
||||
|
||||
expect(result.code).toStrictEqual(0);
|
||||
expect(result.stdout).toContain('cache');
|
||||
expect(result.stdout).toContain('status');
|
||||
expect(result.stdout).toContain('--cache-dir');
|
||||
});
|
||||
|
||||
it('exits 0 for update --help', async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import buildCommand from '../commands/build';
|
||||
import testCommand from '../commands/test';
|
||||
import activateCommand from '../commands/activate';
|
||||
import orchestrateCommand from '../commands/orchestrate';
|
||||
import cacheCommand from '../commands/cache';
|
||||
import statusCommand from '../commands/status';
|
||||
import versionCommand from '../commands/version';
|
||||
import updateCommand from '../commands/update';
|
||||
@@ -54,7 +54,7 @@ describe('CLI commands', () => {
|
||||
|
||||
(buildCommand.builder as Function)(yargs);
|
||||
|
||||
// Core build flags
|
||||
// Core build flags (from shared + build-specific)
|
||||
expect(options['target-platform']).toBeDefined();
|
||||
expect(options['target-platform'].demandOption).toStrictEqual(true);
|
||||
expect(options['unity-version']).toBeDefined();
|
||||
@@ -88,10 +88,10 @@ describe('CLI commands', () => {
|
||||
expect(options['run-as-host-user']).toBeDefined();
|
||||
expect(options['chown-files-to']).toBeDefined();
|
||||
|
||||
// Provider flags
|
||||
expect(options['provider-strategy']).toBeDefined();
|
||||
expect(options['skip-activation']).toBeDefined();
|
||||
expect(options['unity-licensing-server']).toBeDefined();
|
||||
// Build should NOT have orchestrator-specific flags
|
||||
expect(options['provider-strategy']).toBeUndefined();
|
||||
expect(options['aws-stack-name']).toBeUndefined();
|
||||
expect(options['kube-config']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('sets correct default values', () => {
|
||||
@@ -107,7 +107,6 @@ describe('CLI commands', () => {
|
||||
expect(options['enable-gpu'].default).toStrictEqual(false);
|
||||
expect(options['android-export-type'].default).toStrictEqual('androidPackage');
|
||||
expect(options['android-symbol-type'].default).toStrictEqual('none');
|
||||
expect(options['provider-strategy'].default).toStrictEqual('local');
|
||||
});
|
||||
|
||||
it('provides camelCase aliases for kebab-case options', () => {
|
||||
@@ -124,6 +123,62 @@ describe('CLI commands', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('test command', () => {
|
||||
it('exports command with alias', () => {
|
||||
expect(testCommand.command).toStrictEqual(['test', 't']);
|
||||
});
|
||||
|
||||
it('has a description', () => {
|
||||
expect(testCommand.describe).toBeTruthy();
|
||||
});
|
||||
|
||||
it('has a builder function', () => {
|
||||
expect(typeof testCommand.builder).toStrictEqual('function');
|
||||
});
|
||||
|
||||
it('has a handler function', () => {
|
||||
expect(typeof testCommand.handler).toStrictEqual('function');
|
||||
});
|
||||
|
||||
it('defines test-specific flags', () => {
|
||||
const { yargs, options } = createFakeYargs();
|
||||
|
||||
(testCommand.builder as Function)(yargs);
|
||||
|
||||
expect(options['test-mode']).toBeDefined();
|
||||
expect(options['test-mode'].default).toStrictEqual('All');
|
||||
expect(options['test-mode'].choices).toStrictEqual(['EditMode', 'PlayMode', 'All']);
|
||||
expect(options['test-results-path']).toBeDefined();
|
||||
expect(options['test-category']).toBeDefined();
|
||||
expect(options['test-filter']).toBeDefined();
|
||||
expect(options['enable-code-coverage']).toBeDefined();
|
||||
expect(options['coverage-options']).toBeDefined();
|
||||
});
|
||||
|
||||
it('includes shared project options', () => {
|
||||
const { yargs, options } = createFakeYargs();
|
||||
|
||||
(testCommand.builder as Function)(yargs);
|
||||
|
||||
expect(options['target-platform']).toBeDefined();
|
||||
expect(options['target-platform'].demandOption).toStrictEqual(true);
|
||||
expect(options['unity-version']).toBeDefined();
|
||||
expect(options['project-path']).toBeDefined();
|
||||
expect(options['custom-image']).toBeDefined();
|
||||
});
|
||||
|
||||
it('includes docker options but not orchestrator options', () => {
|
||||
const { yargs, options } = createFakeYargs();
|
||||
|
||||
(testCommand.builder as Function)(yargs);
|
||||
|
||||
expect(options['docker-cpu-limit']).toBeDefined();
|
||||
expect(options['docker-memory-limit']).toBeDefined();
|
||||
expect(options['provider-strategy']).toBeUndefined();
|
||||
expect(options['aws-stack-name']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('activate command', () => {
|
||||
it('exports the correct command name', () => {
|
||||
expect(activateCommand.command).toStrictEqual('activate');
|
||||
@@ -143,8 +198,8 @@ describe('CLI commands', () => {
|
||||
});
|
||||
|
||||
describe('orchestrate command', () => {
|
||||
it('exports the correct command name', () => {
|
||||
expect(orchestrateCommand.command).toStrictEqual('orchestrate');
|
||||
it('exports command with alias', () => {
|
||||
expect(orchestrateCommand.command).toStrictEqual(['orchestrate', 'o']);
|
||||
});
|
||||
|
||||
it('has a description', () => {
|
||||
@@ -175,23 +230,16 @@ describe('CLI commands', () => {
|
||||
expect(options['watch-to-end']).toBeDefined();
|
||||
expect(options['clone-depth']).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('cache command', () => {
|
||||
it('exports the correct command name', () => {
|
||||
expect(cacheCommand.command).toStrictEqual('cache <action>');
|
||||
});
|
||||
it('does not include build-only options', () => {
|
||||
const { yargs, options } = createFakeYargs();
|
||||
|
||||
it('has a description', () => {
|
||||
expect(cacheCommand.describe).toBeTruthy();
|
||||
});
|
||||
(orchestrateCommand.builder as Function)(yargs);
|
||||
|
||||
it('has a builder function', () => {
|
||||
expect(typeof cacheCommand.builder).toStrictEqual('function');
|
||||
});
|
||||
|
||||
it('has a handler function', () => {
|
||||
expect(typeof cacheCommand.handler).toStrictEqual('function');
|
||||
expect(options['build-profile']).toBeUndefined();
|
||||
expect(options['manual-exit']).toBeUndefined();
|
||||
expect(options['enable-gpu']).toBeUndefined();
|
||||
expect(options['android-version-code']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -207,6 +255,15 @@ describe('CLI commands', () => {
|
||||
it('has a handler function', () => {
|
||||
expect(typeof statusCommand.handler).toStrictEqual('function');
|
||||
});
|
||||
|
||||
it('includes cache-dir option', () => {
|
||||
const { yargs, options } = createFakeYargs();
|
||||
|
||||
(statusCommand.builder as Function)(yargs);
|
||||
|
||||
expect(options['cache-dir']).toBeDefined();
|
||||
expect(options['project-path']).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('version command', () => {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import type { CommandModule } from 'yargs';
|
||||
import * as core from '@actions/core';
|
||||
import { BuildParameters, ImageTag, Orchestrator } from '../../model';
|
||||
import { BuildParameters, ImageTag } from '../../model';
|
||||
import { mapCliArgumentsToInput, CliArguments } from '../input-mapper';
|
||||
import MacBuilder from '../../model/mac-builder';
|
||||
import Docker from '../../model/docker';
|
||||
import Action from '../../model/action';
|
||||
import PlatformSetup from '../../model/platform-setup';
|
||||
import { withProjectOptions, withDockerOptions, withAndroidOptions } from './shared-options';
|
||||
|
||||
interface BuildArguments extends CliArguments {
|
||||
targetPlatform: string;
|
||||
@@ -13,57 +14,19 @@ interface BuildArguments extends CliArguments {
|
||||
|
||||
const buildCommand: CommandModule<object, BuildArguments> = {
|
||||
command: 'build',
|
||||
describe: 'Build a Unity project',
|
||||
describe: 'Build a Unity project locally via Docker or native runner',
|
||||
builder: (yargs) => {
|
||||
return yargs
|
||||
.option('target-platform', {
|
||||
alias: 'targetPlatform',
|
||||
type: 'string',
|
||||
description: 'Platform that the build should target',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('unity-version', {
|
||||
alias: 'unityVersion',
|
||||
type: 'string',
|
||||
description: 'Version of Unity to use for building the project. Use "auto" to detect.',
|
||||
default: 'auto',
|
||||
})
|
||||
.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string',
|
||||
description: 'Path to the Unity project to be built',
|
||||
default: '.',
|
||||
})
|
||||
let y = withProjectOptions(yargs);
|
||||
y = withAndroidOptions(y);
|
||||
y = withDockerOptions(y);
|
||||
|
||||
return y
|
||||
.option('build-profile', {
|
||||
alias: 'buildProfile',
|
||||
type: 'string',
|
||||
description: 'Path to the build profile to activate, relative to the project root',
|
||||
default: '',
|
||||
})
|
||||
.option('build-name', {
|
||||
alias: 'buildName',
|
||||
type: 'string',
|
||||
description: 'Name of the build (no file extension)',
|
||||
default: '',
|
||||
})
|
||||
.option('builds-path', {
|
||||
alias: 'buildsPath',
|
||||
type: 'string',
|
||||
description: 'Path where the builds should be stored',
|
||||
default: 'build',
|
||||
})
|
||||
.option('build-method', {
|
||||
alias: 'buildMethod',
|
||||
type: 'string',
|
||||
description: 'Path to a Namespace.Class.StaticMethod to run to perform the build',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-parameters', {
|
||||
alias: 'customParameters',
|
||||
type: 'string',
|
||||
description: 'Custom parameters to configure the build',
|
||||
default: '',
|
||||
})
|
||||
.option('versioning', {
|
||||
type: 'string',
|
||||
description: 'The versioning scheme to use when building the project',
|
||||
@@ -74,12 +37,6 @@ const buildCommand: CommandModule<object, BuildArguments> = {
|
||||
description: 'The version, when used with the "Custom" versioning scheme',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-image', {
|
||||
alias: 'customImage',
|
||||
type: 'string',
|
||||
description: 'Specific docker image that should be used for building the project',
|
||||
default: '',
|
||||
})
|
||||
.option('manual-exit', {
|
||||
alias: 'manualExit',
|
||||
type: 'boolean',
|
||||
@@ -92,145 +49,6 @@ const buildCommand: CommandModule<object, BuildArguments> = {
|
||||
description: 'Launches unity without specifying -nographics',
|
||||
default: false,
|
||||
})
|
||||
.option('android-version-code', {
|
||||
alias: 'androidVersionCode',
|
||||
type: 'string',
|
||||
description: 'The android versionCode',
|
||||
default: '',
|
||||
})
|
||||
.option('android-export-type', {
|
||||
alias: 'androidExportType',
|
||||
type: 'string',
|
||||
description: 'The android export type (androidPackage, androidAppBundle, androidStudioProject)',
|
||||
default: 'androidPackage',
|
||||
})
|
||||
.option('android-keystore-name', {
|
||||
alias: 'androidKeystoreName',
|
||||
type: 'string',
|
||||
description: 'The android keystoreName',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keystore-base64', {
|
||||
alias: 'androidKeystoreBase64',
|
||||
type: 'string',
|
||||
description: 'The base64 contents of the android keystore file',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keystore-pass', {
|
||||
alias: 'androidKeystorePass',
|
||||
type: 'string',
|
||||
description: 'The android keystorePass',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keyalias-name', {
|
||||
alias: 'androidKeyaliasName',
|
||||
type: 'string',
|
||||
description: 'The android keyaliasName',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keyalias-pass', {
|
||||
alias: 'androidKeyaliasPass',
|
||||
type: 'string',
|
||||
description: 'The android keyaliasPass',
|
||||
default: '',
|
||||
})
|
||||
.option('android-target-sdk-version', {
|
||||
alias: 'androidTargetSdkVersion',
|
||||
type: 'string',
|
||||
description: 'The android target API level',
|
||||
default: '',
|
||||
})
|
||||
.option('android-symbol-type', {
|
||||
alias: 'androidSymbolType',
|
||||
type: 'string',
|
||||
description: 'The android symbol type to export (none, public, debugging)',
|
||||
default: 'none',
|
||||
})
|
||||
.option('docker-cpu-limit', {
|
||||
alias: 'dockerCpuLimit',
|
||||
type: 'string',
|
||||
description: 'Number of CPU cores to assign the docker container',
|
||||
default: '',
|
||||
})
|
||||
.option('docker-memory-limit', {
|
||||
alias: 'dockerMemoryLimit',
|
||||
type: 'string',
|
||||
description: 'Amount of memory to assign the docker container (e.g. 512m, 4g)',
|
||||
default: '',
|
||||
})
|
||||
.option('docker-workspace-path', {
|
||||
alias: 'dockerWorkspacePath',
|
||||
type: 'string',
|
||||
description: 'The path to mount the workspace inside the docker container',
|
||||
default: '/github/workspace',
|
||||
})
|
||||
.option('run-as-host-user', {
|
||||
alias: 'runAsHostUser',
|
||||
type: 'string',
|
||||
description: 'Whether to run as a user that matches the host system',
|
||||
default: 'false',
|
||||
})
|
||||
.option('chown-files-to', {
|
||||
alias: 'chownFilesTo',
|
||||
type: 'string',
|
||||
description: 'User and optionally group to give ownership of build artifacts',
|
||||
default: '',
|
||||
})
|
||||
.option('ssh-agent', {
|
||||
alias: 'sshAgent',
|
||||
type: 'string',
|
||||
description: 'SSH Agent path to forward to the container',
|
||||
default: '',
|
||||
})
|
||||
.option('git-private-token', {
|
||||
alias: 'gitPrivateToken',
|
||||
type: 'string',
|
||||
description: 'GitHub private token to pull from GitHub',
|
||||
default: '',
|
||||
})
|
||||
.option('provider-strategy', {
|
||||
alias: 'providerStrategy',
|
||||
type: 'string',
|
||||
description: 'Execution strategy: local, k8s, or aws',
|
||||
default: 'local',
|
||||
})
|
||||
.option('skip-activation', {
|
||||
alias: 'skipActivation',
|
||||
type: 'string',
|
||||
description: 'Skip the activation/deactivation of Unity',
|
||||
default: 'false',
|
||||
})
|
||||
.option('unity-licensing-server', {
|
||||
alias: 'unityLicensingServer',
|
||||
type: 'string',
|
||||
description: 'The Unity licensing server address',
|
||||
default: '',
|
||||
})
|
||||
.option('container-registry-repository', {
|
||||
alias: 'containerRegistryRepository',
|
||||
type: 'string',
|
||||
description: 'Container registry and repository to pull image from. Only applicable if customImage is not set.',
|
||||
default: 'unityci/editor',
|
||||
})
|
||||
.option('container-registry-image-version', {
|
||||
alias: 'containerRegistryImageVersion',
|
||||
type: 'string',
|
||||
description: 'Container registry image version. Only applicable if customImage is not set.',
|
||||
default: '3',
|
||||
})
|
||||
.option('docker-isolation-mode', {
|
||||
alias: 'dockerIsolationMode',
|
||||
type: 'string',
|
||||
description:
|
||||
'Isolation mode to use for the docker container (process, hyperv, or default). Only applicable on Windows.',
|
||||
default: 'default',
|
||||
})
|
||||
.option('ssh-public-keys-directory-path', {
|
||||
alias: 'sshPublicKeysDirectoryPath',
|
||||
type: 'string',
|
||||
description: 'Path to a directory containing SSH public keys to forward to the container',
|
||||
default: '',
|
||||
})
|
||||
.option('cache-unity-installation-on-mac', {
|
||||
alias: 'cacheUnityInstallationOnMac',
|
||||
type: 'boolean',
|
||||
@@ -256,31 +74,22 @@ const buildCommand: CommandModule<object, BuildArguments> = {
|
||||
const buildParameters = await BuildParameters.create();
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
|
||||
let exitCode = -1;
|
||||
core.info(`Building locally for ${buildParameters.targetPlatform}...`);
|
||||
core.info(`Unity version: ${buildParameters.editorVersion}`);
|
||||
core.info(`Project path: ${buildParameters.projectPath}`);
|
||||
|
||||
if (buildParameters.providerStrategy === 'local') {
|
||||
core.info(`Building locally for ${buildParameters.targetPlatform}...`);
|
||||
core.info(`Unity version: ${buildParameters.editorVersion}`);
|
||||
core.info(`Project path: ${buildParameters.projectPath}`);
|
||||
const actionFolder = Action.actionFolder;
|
||||
await PlatformSetup.setup(buildParameters, actionFolder);
|
||||
|
||||
const actionFolder = Action.actionFolder;
|
||||
await PlatformSetup.setup(buildParameters, actionFolder);
|
||||
const exitCode =
|
||||
process.platform === 'darwin'
|
||||
? await MacBuilder.run(actionFolder)
|
||||
: await Docker.run(baseImage.toString(), {
|
||||
workspace: process.cwd(),
|
||||
actionFolder,
|
||||
...buildParameters,
|
||||
});
|
||||
|
||||
exitCode =
|
||||
process.platform === 'darwin'
|
||||
? await MacBuilder.run(actionFolder)
|
||||
: await Docker.run(baseImage.toString(), {
|
||||
workspace: process.cwd(),
|
||||
actionFolder,
|
||||
...buildParameters,
|
||||
});
|
||||
} else {
|
||||
core.info(`Building via orchestrator (${buildParameters.providerStrategy})...`);
|
||||
await Orchestrator.run(buildParameters, baseImage.toString());
|
||||
exitCode = 0;
|
||||
}
|
||||
|
||||
// Output results
|
||||
core.info(`\nBuild completed with exit code: ${exitCode}`);
|
||||
core.info(`Build version: ${buildParameters.buildVersion}`);
|
||||
core.info(`Build path: ${buildParameters.buildPath}`);
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
import type { CommandModule } from 'yargs';
|
||||
import * as core from '@actions/core';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const cacheCommand: CommandModule = {
|
||||
command: 'cache <action>',
|
||||
describe: 'Manage build caches',
|
||||
builder: (yargs) => {
|
||||
return yargs
|
||||
.positional('action', {
|
||||
describe: 'Cache action to perform',
|
||||
choices: ['list', 'restore', 'clear'] as const,
|
||||
})
|
||||
.option('cache-dir', {
|
||||
alias: 'cacheDir',
|
||||
type: 'string',
|
||||
description: 'Path to the cache directory',
|
||||
default: '',
|
||||
})
|
||||
.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string',
|
||||
description: 'Path to the Unity project',
|
||||
default: '.',
|
||||
})
|
||||
.example('game-ci cache list', 'List all cached workspaces')
|
||||
.example('game-ci cache restore --cache-dir ./my-cache', 'Restore a cached workspace')
|
||||
.example('game-ci cache clear', 'Clear all cached workspaces');
|
||||
},
|
||||
handler: async (cliArguments) => {
|
||||
const action = cliArguments.action as string;
|
||||
const projectPath = (cliArguments.projectPath as string) || '.';
|
||||
const cacheDirectory = (cliArguments.cacheDir as string) || path.join(projectPath, 'Library');
|
||||
|
||||
try {
|
||||
switch (action) {
|
||||
case 'list': {
|
||||
await listCache(cacheDirectory, projectPath);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'restore': {
|
||||
await restoreCache(cacheDirectory);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'clear': {
|
||||
await clearCache(cacheDirectory);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new Error(`Unknown cache action: ${action}. Available actions: list, restore, clear`);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
core.setFailed(`Cache operation failed: ${error.message}`);
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
async function listCache(cacheDirectory: string, projectPath: string): Promise<void> {
|
||||
const libraryPath = path.resolve(projectPath, 'Library');
|
||||
|
||||
core.info('Cache Status:');
|
||||
core.info('=============');
|
||||
|
||||
if (fs.existsSync(libraryPath)) {
|
||||
const stats = fs.statSync(libraryPath);
|
||||
const files = fs.readdirSync(libraryPath);
|
||||
core.info(` Library folder: ${libraryPath}`);
|
||||
core.info(` Entries: ${files.length}`);
|
||||
core.info(` Last modified: ${stats.mtime.toISOString()}`);
|
||||
|
||||
// Show size of key subdirectories
|
||||
const keyDirectories = ['PackageCache', 'ScriptAssemblies', 'ShaderCache', 'Bee'];
|
||||
for (const directory of keyDirectories) {
|
||||
const directoryPath = path.join(libraryPath, directory);
|
||||
if (fs.existsSync(directoryPath)) {
|
||||
const directoryStats = fs.statSync(directoryPath);
|
||||
core.info(` ${directory}/: exists (modified ${directoryStats.mtime.toISOString()})`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
core.info(` Library folder not found at: ${libraryPath}`);
|
||||
core.info(' No cache available. First build will be a clean build.');
|
||||
}
|
||||
|
||||
// Check for .tar cache files if a custom cache dir is specified
|
||||
if (cacheDirectory && cacheDirectory !== libraryPath && fs.existsSync(cacheDirectory)) {
|
||||
core.info(`\nCache directory: ${cacheDirectory}`);
|
||||
const cacheFiles = fs.readdirSync(cacheDirectory).filter((f) => f.endsWith('.tar') || f.endsWith('.tar.lz4'));
|
||||
if (cacheFiles.length > 0) {
|
||||
core.info(` Cache archives found: ${cacheFiles.length}`);
|
||||
for (const file of cacheFiles) {
|
||||
const filePath = path.join(cacheDirectory, file);
|
||||
const fileStats = fs.statSync(filePath);
|
||||
const sizeMegabytes = (fileStats.size / (1024 * 1024)).toFixed(1);
|
||||
core.info(` - ${file} (${sizeMegabytes} MB, ${fileStats.mtime.toISOString()})`);
|
||||
}
|
||||
} else {
|
||||
core.info(' No cache archives found.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreCache(cacheDirectory: string): Promise<void> {
|
||||
if (!cacheDirectory) {
|
||||
throw new Error('--cache-dir is required for restore');
|
||||
}
|
||||
|
||||
if (!fs.existsSync(cacheDirectory)) {
|
||||
core.info(`Cache directory does not exist: ${cacheDirectory}`);
|
||||
core.info('Nothing to restore.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const cacheFiles = fs.readdirSync(cacheDirectory).filter((f) => f.endsWith('.tar') || f.endsWith('.tar.lz4'));
|
||||
if (cacheFiles.length === 0) {
|
||||
core.info('No cache archives found to restore.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort by modification time, newest first
|
||||
const sorted = cacheFiles
|
||||
.map((f) => ({ name: f, mtime: fs.statSync(path.join(cacheDirectory, f)).mtime }))
|
||||
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
||||
|
||||
core.info(`Found ${sorted.length} cache archive(s). Latest: ${sorted[0].name}`);
|
||||
core.info('Use the orchestrator cache system for full restore functionality:');
|
||||
core.info(' game-ci orchestrate --cache-key <key> ...');
|
||||
}
|
||||
|
||||
async function clearCache(cacheDirectory: string): Promise<void> {
|
||||
let cleared = false;
|
||||
|
||||
if (cacheDirectory && fs.existsSync(cacheDirectory)) {
|
||||
const cacheFiles = fs.readdirSync(cacheDirectory).filter((f) => f.endsWith('.tar') || f.endsWith('.tar.lz4'));
|
||||
if (cacheFiles.length > 0) {
|
||||
for (const file of cacheFiles) {
|
||||
fs.unlinkSync(path.join(cacheDirectory, file));
|
||||
core.info(` Removed: ${file}`);
|
||||
}
|
||||
cleared = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cleared) {
|
||||
core.info('No cache archives found to clear.');
|
||||
} else {
|
||||
core.info('Cache cleared.');
|
||||
}
|
||||
}
|
||||
|
||||
export default cacheCommand;
|
||||
@@ -2,6 +2,7 @@ import type { CommandModule } from 'yargs';
|
||||
import * as core from '@actions/core';
|
||||
import { BuildParameters, ImageTag, Orchestrator } from '../../model';
|
||||
import { mapCliArgumentsToInput, CliArguments } from '../input-mapper';
|
||||
import { withProjectOptions, withOrchestratorOptions } from './shared-options';
|
||||
|
||||
interface OrchestrateArguments extends CliArguments {
|
||||
targetPlatform: string;
|
||||
@@ -9,181 +10,25 @@ interface OrchestrateArguments extends CliArguments {
|
||||
}
|
||||
|
||||
const orchestrateCommand: CommandModule<object, OrchestrateArguments> = {
|
||||
command: 'orchestrate',
|
||||
command: ['orchestrate', 'o'],
|
||||
describe: 'Run a build via orchestrator providers (AWS, Kubernetes, etc.)',
|
||||
builder: (yargs) => {
|
||||
return yargs
|
||||
.option('target-platform', {
|
||||
alias: 'targetPlatform',
|
||||
type: 'string',
|
||||
description: 'Platform that the build should target',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('provider-strategy', {
|
||||
alias: 'providerStrategy',
|
||||
type: 'string',
|
||||
description: 'Orchestrator provider: aws, k8s, local-docker, local-system',
|
||||
default: 'aws',
|
||||
})
|
||||
.option('unity-version', {
|
||||
alias: 'unityVersion',
|
||||
type: 'string',
|
||||
description: 'Version of Unity to use for building',
|
||||
default: 'auto',
|
||||
})
|
||||
.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string',
|
||||
description: 'Path to the Unity project to be built',
|
||||
default: '.',
|
||||
})
|
||||
.option('build-name', {
|
||||
alias: 'buildName',
|
||||
type: 'string',
|
||||
description: 'Name of the build',
|
||||
default: '',
|
||||
})
|
||||
.option('builds-path', {
|
||||
alias: 'buildsPath',
|
||||
type: 'string',
|
||||
description: 'Path where the builds should be stored',
|
||||
default: 'build',
|
||||
})
|
||||
.option('build-method', {
|
||||
alias: 'buildMethod',
|
||||
type: 'string',
|
||||
description: 'Path to a Namespace.Class.StaticMethod to run to perform the build',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-parameters', {
|
||||
alias: 'customParameters',
|
||||
type: 'string',
|
||||
description: 'Custom parameters to configure the build',
|
||||
default: '',
|
||||
})
|
||||
let y = withProjectOptions(yargs);
|
||||
y = withOrchestratorOptions(y);
|
||||
|
||||
return y
|
||||
.option('versioning', {
|
||||
type: 'string',
|
||||
description: 'The versioning scheme to use',
|
||||
default: 'None',
|
||||
})
|
||||
.option('aws-stack-name', {
|
||||
alias: 'awsStackName',
|
||||
type: 'string',
|
||||
description: 'The Cloud Formation stack name (AWS provider)',
|
||||
default: 'game-ci',
|
||||
})
|
||||
.option('kube-config', {
|
||||
alias: 'kubeConfig',
|
||||
type: 'string',
|
||||
description: 'Base64 encoded Kubernetes config (K8s provider)',
|
||||
default: '',
|
||||
})
|
||||
.option('kube-volume', {
|
||||
alias: 'kubeVolume',
|
||||
type: 'string',
|
||||
description: 'Persistent Volume Claim name for Unity build (K8s provider)',
|
||||
default: '',
|
||||
})
|
||||
.option('kube-volume-size', {
|
||||
alias: 'kubeVolumeSize',
|
||||
type: 'string',
|
||||
description: 'Disc space for Kubernetes Persistent Volume',
|
||||
default: '5Gi',
|
||||
})
|
||||
.option('container-cpu', {
|
||||
alias: 'containerCpu',
|
||||
type: 'string',
|
||||
description: 'CPU allocation for remote build container',
|
||||
default: '1024',
|
||||
})
|
||||
.option('container-memory', {
|
||||
alias: 'containerMemory',
|
||||
type: 'string',
|
||||
description: 'Memory allocation for remote build container',
|
||||
default: '3072',
|
||||
})
|
||||
.option('cache-key', {
|
||||
alias: 'cacheKey',
|
||||
type: 'string',
|
||||
description: 'Cache key to indicate bucket for cache',
|
||||
default: '',
|
||||
})
|
||||
.option('git-private-token', {
|
||||
alias: 'gitPrivateToken',
|
||||
type: 'string',
|
||||
description: 'GitHub private token for repository access',
|
||||
default: '',
|
||||
})
|
||||
.option('allow-dirty-build', {
|
||||
alias: 'allowDirtyBuild',
|
||||
type: 'boolean',
|
||||
description: 'Allow builds from dirty branches',
|
||||
default: false,
|
||||
})
|
||||
.option('watch-to-end', {
|
||||
alias: 'watchToEnd',
|
||||
type: 'string',
|
||||
description: 'Whether to watch the build to completion',
|
||||
default: 'true',
|
||||
})
|
||||
.option('clone-depth', {
|
||||
alias: 'cloneDepth',
|
||||
type: 'string',
|
||||
description: 'Git clone depth (0 for full clone)',
|
||||
default: '50',
|
||||
})
|
||||
.option('skip-activation', {
|
||||
alias: 'skipActivation',
|
||||
type: 'string',
|
||||
description: 'Skip Unity activation/deactivation',
|
||||
default: 'false',
|
||||
})
|
||||
.option('kube-storage-class', {
|
||||
alias: 'kubeStorageClass',
|
||||
type: 'string',
|
||||
description: 'Kubernetes storage class to use for orchestrator jobs. Leave empty to install rook cluster.',
|
||||
default: '',
|
||||
})
|
||||
.option('read-input-from-override-list', {
|
||||
alias: 'readInputFromOverrideList',
|
||||
type: 'string',
|
||||
description: 'Comma separated list of input value names to read from the input override command',
|
||||
default: '',
|
||||
})
|
||||
.option('read-input-override-command', {
|
||||
alias: 'readInputOverrideCommand',
|
||||
type: 'string',
|
||||
description: 'Command to execute to pull input from an external source (e.g. cloud provider secret managers)',
|
||||
default: '',
|
||||
})
|
||||
.option('post-build-steps', {
|
||||
alias: 'postBuildSteps',
|
||||
type: 'string',
|
||||
description:
|
||||
'Post build job in yaml format with the keys image, secrets (name, value object array), command string',
|
||||
default: '',
|
||||
})
|
||||
.option('pre-build-steps', {
|
||||
alias: 'preBuildSteps',
|
||||
type: 'string',
|
||||
description:
|
||||
'Pre build job after repository setup but before the build job (yaml format with keys image, secrets, command)',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-job', {
|
||||
alias: 'customJob',
|
||||
type: 'string',
|
||||
description:
|
||||
'Custom job instead of the standard build automation (yaml format with keys image, secrets, command)',
|
||||
default: '',
|
||||
})
|
||||
.example(
|
||||
'game-ci orchestrate --target-platform StandaloneLinux64 --provider-strategy aws',
|
||||
'Build on AWS using the orchestrator',
|
||||
)
|
||||
.example(
|
||||
'game-ci orchestrate --target-platform StandaloneLinux64 --provider-strategy k8s --kube-config <base64>',
|
||||
'Build on Kubernetes',
|
||||
'game-ci o --target-platform StandaloneLinux64 --provider-strategy k8s --kube-config <base64>',
|
||||
'Build on Kubernetes (short alias)',
|
||||
) as any;
|
||||
},
|
||||
handler: async (cliArguments) => {
|
||||
|
||||
308
src/cli/commands/shared-options.ts
Normal file
308
src/cli/commands/shared-options.ts
Normal file
@@ -0,0 +1,308 @@
|
||||
import type { Argv } from 'yargs';
|
||||
|
||||
/**
|
||||
* Shared option groups for CLI commands. Avoids duplicating option
|
||||
* definitions across build, test, and orchestrate commands.
|
||||
*/
|
||||
|
||||
export function withProjectOptions<T>(yargs: Argv<T>) {
|
||||
return yargs
|
||||
.option('target-platform', {
|
||||
alias: 'targetPlatform',
|
||||
type: 'string' as const,
|
||||
description: 'Platform that the build should target',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('unity-version', {
|
||||
alias: 'unityVersion',
|
||||
type: 'string' as const,
|
||||
description: 'Version of Unity to use. Use "auto" to detect from ProjectVersion.txt.',
|
||||
default: 'auto',
|
||||
})
|
||||
.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string' as const,
|
||||
description: 'Path to the Unity project',
|
||||
default: '.',
|
||||
})
|
||||
.option('build-name', {
|
||||
alias: 'buildName',
|
||||
type: 'string' as const,
|
||||
description: 'Name of the build',
|
||||
default: '',
|
||||
})
|
||||
.option('builds-path', {
|
||||
alias: 'buildsPath',
|
||||
type: 'string' as const,
|
||||
description: 'Path where the builds should be stored',
|
||||
default: 'build',
|
||||
})
|
||||
.option('build-method', {
|
||||
alias: 'buildMethod',
|
||||
type: 'string' as const,
|
||||
description: 'Path to a Namespace.Class.StaticMethod to run to perform the build',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-parameters', {
|
||||
alias: 'customParameters',
|
||||
type: 'string' as const,
|
||||
description: 'Custom parameters to configure the build',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-image', {
|
||||
alias: 'customImage',
|
||||
type: 'string' as const,
|
||||
description: 'Specific docker image that should be used for building the project',
|
||||
default: '',
|
||||
})
|
||||
.option('git-private-token', {
|
||||
alias: 'gitPrivateToken',
|
||||
type: 'string' as const,
|
||||
description: 'GitHub private token for repository access',
|
||||
default: '',
|
||||
})
|
||||
.option('skip-activation', {
|
||||
alias: 'skipActivation',
|
||||
type: 'string' as const,
|
||||
description: 'Skip Unity activation/deactivation',
|
||||
default: 'false',
|
||||
})
|
||||
.option('unity-licensing-server', {
|
||||
alias: 'unityLicensingServer',
|
||||
type: 'string' as const,
|
||||
description: 'The Unity licensing server address',
|
||||
default: '',
|
||||
})
|
||||
.option('container-registry-repository', {
|
||||
alias: 'containerRegistryRepository',
|
||||
type: 'string' as const,
|
||||
description: 'Container registry and repository to pull image from. Only applicable if customImage is not set.',
|
||||
default: 'unityci/editor',
|
||||
})
|
||||
.option('container-registry-image-version', {
|
||||
alias: 'containerRegistryImageVersion',
|
||||
type: 'string' as const,
|
||||
description: 'Container registry image version. Only applicable if customImage is not set.',
|
||||
default: '3',
|
||||
});
|
||||
}
|
||||
|
||||
export function withDockerOptions<T>(yargs: Argv<T>) {
|
||||
return yargs
|
||||
.option('docker-cpu-limit', {
|
||||
alias: 'dockerCpuLimit',
|
||||
type: 'string' as const,
|
||||
description: 'Number of CPU cores to assign the docker container',
|
||||
default: '',
|
||||
})
|
||||
.option('docker-memory-limit', {
|
||||
alias: 'dockerMemoryLimit',
|
||||
type: 'string' as const,
|
||||
description: 'Amount of memory to assign the docker container (e.g. 512m, 4g)',
|
||||
default: '',
|
||||
})
|
||||
.option('docker-workspace-path', {
|
||||
alias: 'dockerWorkspacePath',
|
||||
type: 'string' as const,
|
||||
description: 'The path to mount the workspace inside the docker container',
|
||||
default: '/github/workspace',
|
||||
})
|
||||
.option('docker-isolation-mode', {
|
||||
alias: 'dockerIsolationMode',
|
||||
type: 'string' as const,
|
||||
description:
|
||||
'Isolation mode to use for the docker container (process, hyperv, or default). Only applicable on Windows.',
|
||||
default: 'default',
|
||||
})
|
||||
.option('run-as-host-user', {
|
||||
alias: 'runAsHostUser',
|
||||
type: 'string' as const,
|
||||
description: 'Whether to run as a user that matches the host system',
|
||||
default: 'false',
|
||||
})
|
||||
.option('chown-files-to', {
|
||||
alias: 'chownFilesTo',
|
||||
type: 'string' as const,
|
||||
description: 'User and optionally group to give ownership of build artifacts',
|
||||
default: '',
|
||||
})
|
||||
.option('ssh-agent', {
|
||||
alias: 'sshAgent',
|
||||
type: 'string' as const,
|
||||
description: 'SSH Agent path to forward to the container',
|
||||
default: '',
|
||||
})
|
||||
.option('ssh-public-keys-directory-path', {
|
||||
alias: 'sshPublicKeysDirectoryPath',
|
||||
type: 'string' as const,
|
||||
description: 'Path to a directory containing SSH public keys to forward to the container',
|
||||
default: '',
|
||||
});
|
||||
}
|
||||
|
||||
export function withAndroidOptions<T>(yargs: Argv<T>) {
|
||||
return yargs
|
||||
.option('android-version-code', {
|
||||
alias: 'androidVersionCode',
|
||||
type: 'string' as const,
|
||||
description: 'The android versionCode',
|
||||
default: '',
|
||||
})
|
||||
.option('android-export-type', {
|
||||
alias: 'androidExportType',
|
||||
type: 'string' as const,
|
||||
description: 'The android export type (androidPackage, androidAppBundle, androidStudioProject)',
|
||||
default: 'androidPackage',
|
||||
})
|
||||
.option('android-keystore-name', {
|
||||
alias: 'androidKeystoreName',
|
||||
type: 'string' as const,
|
||||
description: 'The android keystoreName',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keystore-base64', {
|
||||
alias: 'androidKeystoreBase64',
|
||||
type: 'string' as const,
|
||||
description: 'The base64 contents of the android keystore file',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keystore-pass', {
|
||||
alias: 'androidKeystorePass',
|
||||
type: 'string' as const,
|
||||
description: 'The android keystorePass',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keyalias-name', {
|
||||
alias: 'androidKeyaliasName',
|
||||
type: 'string' as const,
|
||||
description: 'The android keyaliasName',
|
||||
default: '',
|
||||
})
|
||||
.option('android-keyalias-pass', {
|
||||
alias: 'androidKeyaliasPass',
|
||||
type: 'string' as const,
|
||||
description: 'The android keyaliasPass',
|
||||
default: '',
|
||||
})
|
||||
.option('android-target-sdk-version', {
|
||||
alias: 'androidTargetSdkVersion',
|
||||
type: 'string' as const,
|
||||
description: 'The android target API level',
|
||||
default: '',
|
||||
})
|
||||
.option('android-symbol-type', {
|
||||
alias: 'androidSymbolType',
|
||||
type: 'string' as const,
|
||||
description: 'The android symbol type to export (none, public, debugging)',
|
||||
default: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
export function withOrchestratorOptions<T>(yargs: Argv<T>) {
|
||||
return yargs
|
||||
.option('provider-strategy', {
|
||||
alias: 'providerStrategy',
|
||||
type: 'string' as const,
|
||||
description: 'Orchestrator provider: aws, k8s, local-docker, local-system',
|
||||
default: 'aws',
|
||||
})
|
||||
.option('aws-stack-name', {
|
||||
alias: 'awsStackName',
|
||||
type: 'string' as const,
|
||||
description: 'The Cloud Formation stack name (AWS provider)',
|
||||
default: 'game-ci',
|
||||
})
|
||||
.option('kube-config', {
|
||||
alias: 'kubeConfig',
|
||||
type: 'string' as const,
|
||||
description: 'Base64 encoded Kubernetes config (K8s provider)',
|
||||
default: '',
|
||||
})
|
||||
.option('kube-volume', {
|
||||
alias: 'kubeVolume',
|
||||
type: 'string' as const,
|
||||
description: 'Persistent Volume Claim name for Unity build (K8s provider)',
|
||||
default: '',
|
||||
})
|
||||
.option('kube-volume-size', {
|
||||
alias: 'kubeVolumeSize',
|
||||
type: 'string' as const,
|
||||
description: 'Disc space for Kubernetes Persistent Volume',
|
||||
default: '5Gi',
|
||||
})
|
||||
.option('kube-storage-class', {
|
||||
alias: 'kubeStorageClass',
|
||||
type: 'string' as const,
|
||||
description: 'Kubernetes storage class to use for orchestrator jobs. Leave empty to install rook cluster.',
|
||||
default: '',
|
||||
})
|
||||
.option('container-cpu', {
|
||||
alias: 'containerCpu',
|
||||
type: 'string' as const,
|
||||
description: 'CPU allocation for remote build container',
|
||||
default: '1024',
|
||||
})
|
||||
.option('container-memory', {
|
||||
alias: 'containerMemory',
|
||||
type: 'string' as const,
|
||||
description: 'Memory allocation for remote build container',
|
||||
default: '3072',
|
||||
})
|
||||
.option('cache-key', {
|
||||
alias: 'cacheKey',
|
||||
type: 'string' as const,
|
||||
description: 'Cache key to indicate bucket for cache',
|
||||
default: '',
|
||||
})
|
||||
.option('allow-dirty-build', {
|
||||
alias: 'allowDirtyBuild',
|
||||
type: 'boolean' as const,
|
||||
description: 'Allow builds from dirty branches',
|
||||
default: false,
|
||||
})
|
||||
.option('watch-to-end', {
|
||||
alias: 'watchToEnd',
|
||||
type: 'string' as const,
|
||||
description: 'Whether to watch the build to completion',
|
||||
default: 'true',
|
||||
})
|
||||
.option('clone-depth', {
|
||||
alias: 'cloneDepth',
|
||||
type: 'string' as const,
|
||||
description: 'Git clone depth (0 for full clone)',
|
||||
default: '50',
|
||||
})
|
||||
.option('read-input-from-override-list', {
|
||||
alias: 'readInputFromOverrideList',
|
||||
type: 'string' as const,
|
||||
description: 'Comma separated list of input value names to read from the input override command',
|
||||
default: '',
|
||||
})
|
||||
.option('read-input-override-command', {
|
||||
alias: 'readInputOverrideCommand',
|
||||
type: 'string' as const,
|
||||
description: 'Command to execute to pull input from an external source (e.g. cloud provider secret managers)',
|
||||
default: '',
|
||||
})
|
||||
.option('post-build-steps', {
|
||||
alias: 'postBuildSteps',
|
||||
type: 'string' as const,
|
||||
description:
|
||||
'Post build job in yaml format with the keys image, secrets (name, value object array), command string',
|
||||
default: '',
|
||||
})
|
||||
.option('pre-build-steps', {
|
||||
alias: 'preBuildSteps',
|
||||
type: 'string' as const,
|
||||
description:
|
||||
'Pre build job after repository setup but before the build job (yaml format with keys image, secrets, command)',
|
||||
default: '',
|
||||
})
|
||||
.option('custom-job', {
|
||||
alias: 'customJob',
|
||||
type: 'string' as const,
|
||||
description:
|
||||
'Custom job instead of the standard build automation (yaml format with keys image, secrets, command)',
|
||||
default: '',
|
||||
});
|
||||
}
|
||||
@@ -6,17 +6,25 @@ import UnityVersioning from '../../model/unity-versioning';
|
||||
|
||||
const statusCommand: CommandModule = {
|
||||
command: 'status',
|
||||
describe: 'Show build status and workspace info',
|
||||
describe: 'Show project info, environment, and cache status',
|
||||
builder: (yargs) => {
|
||||
return yargs.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string',
|
||||
description: 'Path to the Unity project',
|
||||
default: '.',
|
||||
});
|
||||
return yargs
|
||||
.option('project-path', {
|
||||
alias: 'projectPath',
|
||||
type: 'string',
|
||||
description: 'Path to the Unity project',
|
||||
default: '.',
|
||||
})
|
||||
.option('cache-dir', {
|
||||
alias: 'cacheDir',
|
||||
type: 'string',
|
||||
description: 'Path to an additional cache directory to inspect',
|
||||
default: '',
|
||||
});
|
||||
},
|
||||
handler: async (cliArguments) => {
|
||||
const projectPath = (cliArguments.projectPath as string) || '.';
|
||||
const cacheDirectory = cliArguments.cacheDir as string;
|
||||
|
||||
core.info('game-ci Workspace Status');
|
||||
core.info('========================\n');
|
||||
@@ -36,15 +44,40 @@ const statusCommand: CommandModule = {
|
||||
core.info(`Unity Version: Unable to detect`);
|
||||
}
|
||||
|
||||
// Library folder status
|
||||
// Library cache status
|
||||
const libraryPath = path.join(projectPath, 'Library');
|
||||
if (fs.existsSync(libraryPath)) {
|
||||
const stats = fs.statSync(libraryPath);
|
||||
core.info(`Library Cache: Present (modified ${stats.mtime.toISOString()})`);
|
||||
|
||||
const keyDirectories = ['PackageCache', 'ScriptAssemblies', 'ShaderCache', 'Bee'];
|
||||
for (const directory of keyDirectories) {
|
||||
const directoryPath = path.join(libraryPath, directory);
|
||||
if (fs.existsSync(directoryPath)) {
|
||||
const directoryStats = fs.statSync(directoryPath);
|
||||
core.info(` ${directory}/: exists (modified ${directoryStats.mtime.toISOString()})`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
core.info(`Library Cache: Not present (clean build required)`);
|
||||
}
|
||||
|
||||
// Cache archive detection
|
||||
if (cacheDirectory && fs.existsSync(cacheDirectory)) {
|
||||
core.info(`\nCache Archives (${cacheDirectory}):`);
|
||||
const cacheFiles = fs.readdirSync(cacheDirectory).filter((f) => f.endsWith('.tar') || f.endsWith('.tar.lz4'));
|
||||
if (cacheFiles.length > 0) {
|
||||
for (const file of cacheFiles) {
|
||||
const filePath = path.join(cacheDirectory, file);
|
||||
const fileStats = fs.statSync(filePath);
|
||||
const sizeMegabytes = (fileStats.size / (1024 * 1024)).toFixed(1);
|
||||
core.info(` - ${file} (${sizeMegabytes} MB, ${fileStats.mtime.toISOString()})`);
|
||||
}
|
||||
} else {
|
||||
core.info(' No cache archives found.');
|
||||
}
|
||||
}
|
||||
|
||||
// Build output detection
|
||||
const buildsPath = path.join(projectPath, '..', 'build');
|
||||
if (fs.existsSync(buildsPath)) {
|
||||
|
||||
126
src/cli/commands/test.ts
Normal file
126
src/cli/commands/test.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
import type { CommandModule } from 'yargs';
|
||||
import * as core from '@actions/core';
|
||||
import { BuildParameters, ImageTag } from '../../model';
|
||||
import { mapCliArgumentsToInput, CliArguments } from '../input-mapper';
|
||||
import Docker from '../../model/docker';
|
||||
import Action from '../../model/action';
|
||||
import PlatformSetup from '../../model/platform-setup';
|
||||
import { withProjectOptions, withDockerOptions } from './shared-options';
|
||||
|
||||
interface TestArguments extends CliArguments {
|
||||
targetPlatform: string;
|
||||
testMode?: string;
|
||||
}
|
||||
|
||||
const testCommand: CommandModule<object, TestArguments> = {
|
||||
command: ['test', 't'],
|
||||
describe: 'Run tests for a Unity project',
|
||||
builder: (yargs) => {
|
||||
let y = withProjectOptions(yargs);
|
||||
y = withDockerOptions(y);
|
||||
|
||||
return y
|
||||
.option('test-mode', {
|
||||
alias: 'testMode',
|
||||
type: 'string',
|
||||
description: 'The mode to run tests in (EditMode, PlayMode, or All)',
|
||||
default: 'All',
|
||||
choices: ['EditMode', 'PlayMode', 'All'],
|
||||
})
|
||||
.option('test-results-path', {
|
||||
alias: 'testResultsPath',
|
||||
type: 'string',
|
||||
description: 'Path where test results XML should be stored',
|
||||
default: 'test-results',
|
||||
})
|
||||
.option('test-category', {
|
||||
alias: 'testCategory',
|
||||
type: 'string',
|
||||
description: 'Only run tests in the given category (semicolon-separated)',
|
||||
default: '',
|
||||
})
|
||||
.option('test-filter', {
|
||||
alias: 'testFilter',
|
||||
type: 'string',
|
||||
description: 'Only run tests that match the filter (semicolon-separated)',
|
||||
default: '',
|
||||
})
|
||||
.option('coverage-options', {
|
||||
alias: 'coverageOptions',
|
||||
type: 'string',
|
||||
description: 'Options for code coverage (e.g. assemblyFilters, pathFilters)',
|
||||
default: '',
|
||||
})
|
||||
.option('enable-code-coverage', {
|
||||
alias: 'enableCodeCoverage',
|
||||
type: 'boolean',
|
||||
description: 'Enable code coverage when running tests',
|
||||
default: false,
|
||||
})
|
||||
.option('versioning', {
|
||||
type: 'string',
|
||||
description: 'The versioning scheme to use',
|
||||
default: 'None',
|
||||
})
|
||||
.option('cache-unity-installation-on-mac', {
|
||||
alias: 'cacheUnityInstallationOnMac',
|
||||
type: 'boolean',
|
||||
description: 'Whether to cache the Unity hub and editor installation on MacOS',
|
||||
default: false,
|
||||
})
|
||||
.option('unity-hub-version-on-mac', {
|
||||
alias: 'unityHubVersionOnMac',
|
||||
type: 'string',
|
||||
description: 'The version of Unity Hub to install on MacOS (e.g. 3.4.0). Defaults to latest available on brew.',
|
||||
default: '',
|
||||
})
|
||||
.example('game-ci test --target-platform StandaloneLinux64', 'Run all tests for Linux platform')
|
||||
.example(
|
||||
'game-ci t --target-platform StandaloneLinux64 --test-mode EditMode',
|
||||
'Run only EditMode tests (short alias)',
|
||||
)
|
||||
.example(
|
||||
'game-ci test --target-platform StandaloneLinux64 --enable-code-coverage',
|
||||
'Run tests with code coverage',
|
||||
) as any;
|
||||
},
|
||||
handler: async (cliArguments) => {
|
||||
try {
|
||||
// Map test-specific flags into the input system
|
||||
mapCliArgumentsToInput(cliArguments);
|
||||
|
||||
const buildParameters = await BuildParameters.create();
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
|
||||
const testMode = cliArguments.testMode || 'All';
|
||||
|
||||
core.info(`Running Unity tests (${testMode})...`);
|
||||
core.info(`Target platform: ${buildParameters.targetPlatform}`);
|
||||
core.info(`Unity version: ${buildParameters.editorVersion}`);
|
||||
core.info(`Project path: ${buildParameters.projectPath}`);
|
||||
|
||||
const actionFolder = Action.actionFolder;
|
||||
await PlatformSetup.setup(buildParameters, actionFolder);
|
||||
|
||||
const exitCode = await Docker.run(baseImage.toString(), {
|
||||
workspace: process.cwd(),
|
||||
actionFolder,
|
||||
...buildParameters,
|
||||
});
|
||||
|
||||
const resultsPath = cliArguments.testResultsPath || 'test-results';
|
||||
core.info(`\nTests completed with exit code: ${exitCode}`);
|
||||
core.info(`Test results: ${resultsPath}`);
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(`Tests failed with exit code ${exitCode}`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
core.setFailed(`Tests failed: ${error.message}`);
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default testCommand;
|
||||
@@ -73,6 +73,13 @@ export interface CliArguments {
|
||||
cacheUnityInstallationOnMac?: boolean;
|
||||
unityHubVersionOnMac?: string;
|
||||
|
||||
testMode?: string;
|
||||
testResultsPath?: string;
|
||||
testCategory?: string;
|
||||
testFilter?: string;
|
||||
coverageOptions?: string;
|
||||
enableCodeCoverage?: boolean;
|
||||
|
||||
mode?: string;
|
||||
|
||||
[key: string]: unknown;
|
||||
|
||||
@@ -155,8 +155,8 @@ export class Cli {
|
||||
return result.map((x) => x.Name);
|
||||
}
|
||||
|
||||
@CliFunction(`list-worfklow`, `lists running workflows`)
|
||||
public static async ListWorfklow(): Promise<string[]> {
|
||||
@CliFunction(`list-workflow`, `lists running workflows`)
|
||||
public static async ListWorkflow(): Promise<string[]> {
|
||||
const buildParameter = await BuildParameters.create();
|
||||
|
||||
await Orchestrator.setup(buildParameter);
|
||||
|
||||
Reference in New Issue
Block a user