Skip to content

[email protected] #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 62 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25850,17 +25850,48 @@ async function exec(command, onPid) {
}
let lastSize = 0;
let logEnded = false;
const logs = [];
const tailLog = async () => {
let leftover = '';
while (!logEnded) {
try {
const stats = fs.statSync(logPath);
if (stats.size > lastSize) {
const fd = fs.openSync(logPath, 'r');
const buffer = Buffer.alloc(stats.size - lastSize);
fs.readSync(fd, buffer, 0, buffer.length, lastSize);
process.stdout.write(buffer.toString('utf8'));
let chunk = buffer.toString('utf8');
fs.closeSync(fd);
lastSize = stats.size;
chunk = leftover + chunk;
const lines = chunk.split(/\r?\n/);
leftover = lines.pop() || '';
for (const line of lines) {
if (line.startsWith('##utp:')) {
try {
const utp = JSON.parse(line.slice(6));
logs.push(utp);
if (utp.type === 'LogEntry') {
switch (utp.severity) {
case 'Error':
core.error(utp.message, { file: utp.file, startLine: utp.line });
break;
case 'Warning':
core.warning(utp.message, { file: utp.file, startLine: utp.line });
break;
default:
core.info(utp.message);
break;
}
}
}
catch (e) {
}
}
else {
process.stdout.write(line + '\n');
}
}
}
}
catch (error) {
Expand Down Expand Up @@ -25904,6 +25935,36 @@ async function exec(command, onPid) {
await new Promise(res => setTimeout(res, logPollingInterval));
}
}
if (logs.length > 0) {
try {
core.summary.addHeading('Unity Action Logs');
const logMap = new Map();
for (const log of logs) {
for (const [key, value] of Object.entries(log)) {
logMap.set(key, value.toString());
}
}
const keys = new Set();
for (const log of logs) {
Object.keys(log).forEach(key => keys.add(key));
}
const headers = [];
for (const key of keys) {
headers.push({ data: key });
}
const rows = [];
rows.push(headers);
for (const log of logs) {
const dataRow = Array.from(keys).map(key => { var _a, _b; return ({ data: (_b = (_a = log[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '' }); });
rows.push(dataRow);
}
const summary = core.summary.addTable(rows);
await summary.write();
}
catch (e) {
core.warning('Failed to write Unity Action logs to summary: ' + e);
}
}
return exitCode;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-action",
"version": "2.0.1",
"version": "2.1.0",
"description": "A Github Action to execute Unity Editor command line arguments.",
"author": "buildalon",
"repository": {
Expand All @@ -24,10 +24,10 @@
"@actions/io": "^1.1.3"
},
"devDependencies": {
"@types/node": "^22.16.5",
"@types/node": "^22.17.1",
"@vercel/ncc": "^0.34.0",
"shx": "^0.3.4",
"typescript": "^5.8.3"
"typescript": "^5.9.2"
},
"scripts": {
"build": "npm run clean && npm run bundle",
Expand Down
23 changes: 23 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,51 @@ const UNITY_PROJECT_PATH = process.env.UNITY_PROJECT_PATH;

export async function ValidateInputs(): Promise<UnityCommand> {
let editorPath = core.getInput(`editor-path`) || UNITY_EDITOR_PATH;

if (!editorPath) {
throw Error(`Missing editor-path or UNITY_EDITOR_PATH`);
}

await fs.promises.access(editorPath, fs.constants.X_OK);
core.debug(`Unity Editor Path:\n > "${editorPath}"`);
const args = [];
const inputArgsString = core.getInput(`args`);
const inputArgs = shellSplit(inputArgsString);

if (inputArgs.includes(`-version`)) {
return { editorPath, args: [`-version`] };
}

if (!inputArgs.includes(`-batchmode`)) {
args.push(`-batchmode`);
}

const match = editorPath.match(/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/);

if (!match) {
throw Error(`Invalid Unity Editor Path: ${editorPath}`);
}

const unityMajorVersion = match.groups?.major;

if (!unityMajorVersion) {
throw Error(`Invalid Unity Major Version: ${editorPath}`);
}

const autoAddNographics = parseInt(unityMajorVersion, 10) > 2018;

if (autoAddNographics && !inputArgs.includes(`-nographics`) && !inputArgs.includes(`-force-graphics`)) {
args.push(`-nographics`);
}

if (!inputArgs.includes(`-buildTarget`)) {
const buildTarget = core.getInput(`build-target`);
if (buildTarget) {
core.debug(`Build Target:\n > ${buildTarget}`);
args.push(`-buildTarget`, buildTarget);
}
}

let projectPath = undefined;
const needsProjectPath = !(
inputArgs.includes(`-createManualActivationFile`) ||
Expand All @@ -51,41 +63,52 @@ export async function ValidateInputs(): Promise<UnityCommand> {
inputArgs.includes(`-serial`) ||
inputArgs.includes(`-version`) ||
inputArgs.includes(`-createProject`));

if (!inputArgs.includes(`-projectPath`) && needsProjectPath) {
projectPath = core.getInput(`project-path`) || UNITY_PROJECT_PATH;

if (process.platform === `win32` && projectPath.endsWith(`\\`)) {
projectPath = projectPath.slice(0, -1);
}

if (!projectPath) {
throw Error(`Missing project-path or UNITY_PROJECT_PATH`);
}

await fs.promises.access(projectPath, fs.constants.R_OK);
core.debug(`Unity Project Path:\n > "${projectPath}"`);
args.push(`-projectPath`, projectPath);
}

if (!inputArgs.includes(`-logFile`)) {
const logsDirectory = projectPath !== undefined
? path.join(projectPath, `Builds`, `Logs`)
: path.join(WORKSPACE, `Logs`);

try {
await fs.promises.access(logsDirectory, fs.constants.R_OK);
} catch (error) {
core.debug(`Creating Logs Directory:\n > "${logsDirectory}"`);
await fs.promises.mkdir(logsDirectory, { recursive: true });
}

const logName = core.getInput(`log-name`) || `Unity`;
const timestamp = new Date().toISOString().replace(/[-:]/g, ``).replace(/\..+/, ``);
const logPath = path.join(logsDirectory, `${logName}-${timestamp}.log`);
core.debug(`Log File Path:\n > "${logPath}"`);
args.push(`-logFile`, logPath);
}

if (!inputArgs.includes(`-automated`)) {
args.push(`-automated`);
}

if (inputArgs) {
args.push(...inputArgs);
}

core.debug(`Args:`);
args.forEach(arg => core.debug(` ${arg}`));

return { editorPath, args };
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface UnityCommand {
editorPath: string;
args: string[];
}

export interface ProcInfo {
pid: number;
ppid: number;
Expand Down
Loading
Loading