Skip to content

Commit

Permalink
unity-action@v1.0.1
Browse files Browse the repository at this point in the history
- convert to TypeScript
  • Loading branch information
StephenHodgson committed Aug 15, 2024
1 parent 9bedef8 commit 7fa569b
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 159 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Buildalon: Automate Unity
Copyright (c) 2024 Virtual Maker Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
119 changes: 64 additions & 55 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26147,23 +26147,25 @@ exports["default"] = _default;

/***/ }),

/***/ 7229:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
/***/ 7063:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ValidateInputs = ValidateInputs;
const core = __nccwpck_require__(2186);
const fs = (__nccwpck_require__(7147).promises);
const path = __nccwpck_require__(1017);

const fs = __nccwpck_require__(7147);
const WORKSPACE = process.env.GITHUB_WORKSPACE;
const UNITY_EDITOR_PATH = process.env.UNITY_EDITOR_PATH;
const UNITY_PROJECT_PATH = process.env.UNITY_PROJECT_PATH;

async function ValidateInputs() {
let editorPath = core.getInput(`editor-path`) || UNITY_EDITOR_PATH;
if (!editorPath) {
throw Error(`Missing editor-path or UNITY_EDITOR_PATH`);
}
await fs.access(editorPath, fs.constants.X_OK);
await fs.promises.access(editorPath, fs.constants.X_OK);
core.debug(`Unity Editor Path:\n > "${editorPath}"`);
const args = [];
const inputArgsString = core.getInput(`args`);
Expand All @@ -26187,8 +26189,7 @@ async function ValidateInputs() {
}
}
let projectPath = undefined;
const needsProjectPath = !(
inputArgs.includes(`-createManualActivationFile`) ||
const needsProjectPath = !(inputArgs.includes(`-createManualActivationFile`) ||
inputArgs.includes(`-manualLicenseFile`) ||
inputArgs.includes(`-returnLicense`) ||
inputArgs.includes(`-serial`) ||
Expand All @@ -26202,7 +26203,7 @@ async function ValidateInputs() {
if (!projectPath) {
throw Error(`Missing project-path or UNITY_PROJECT_PATH`);
}
await fs.access(projectPath, fs.constants.R_OK);
await fs.promises.access(projectPath, fs.constants.R_OK);
core.debug(`Unity Project Path:\n > "${projectPath}"`);
args.push(`-projectPath`, projectPath);
}
Expand All @@ -26211,10 +26212,11 @@ async function ValidateInputs() {
? path.join(projectPath, `Builds`, `Logs`)
: path.join(WORKSPACE, `Logs`);
try {
await fs.access(logsDirectory, fs.constants.R_OK);
} catch (error) {
await fs.promises.access(logsDirectory, fs.constants.R_OK);
}
catch (error) {
core.debug(`Creating Logs Directory:\n > "${logsDirectory}"`);
await fs.mkdir(logsDirectory, { recursive: true });
await fs.promises.mkdir(logsDirectory, { recursive: true });
}
const logName = core.getInput(`log-name`) || `Unity`;
const timestamp = new Date().toISOString().replace(/[-:]/g, ``).replace(/\..+/, ``);
Expand All @@ -26232,27 +26234,25 @@ async function ValidateInputs() {
return [editorPath, args];
}

module.exports = { ValidateInputs };


/***/ }),

/***/ 8986:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
/***/ 6938:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ExecUnity = ExecUnity;
const exec = __nccwpck_require__(1514);
const core = __nccwpck_require__(2186);
const io = __nccwpck_require__(7436);
const fs = (__nccwpck_require__(7147).promises);
const path = __nccwpck_require__(1017);

const fs = __nccwpck_require__(7147);
const pidFile = path.join(process.env.RUNNER_TEMP, 'unity-process-id.txt');
let isCancelled = false;

async function ExecUnityPwsh(editorPath, args) {
async function ExecUnity(editorPath, args) {
const logPath = getLogFilePath(args);
const pwsh = await io.which('pwsh', true);
const unity = __nccwpck_require__.ab + "unity.ps1";
process.on('SIGINT', async () => {
await TryKillPid(pidFile);
isCancelled = true;
Expand All @@ -26261,55 +26261,61 @@ async function ExecUnityPwsh(editorPath, args) {
await TryKillPid(pidFile);
isCancelled = true;
});
const exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity} -EditorPath '${editorPath}' -Arguments '${args.join(` `)}' -LogPath '${logPath}'`, {
listeners: {
stdline: (data) => {
const line = data.toString().trim();
if (line && line.length > 0) {
core.info(line);
}
}
},
silent: true,
ignoreReturnCode: true
});
let exitCode = 0;
switch (process.platform) {
default:
const unity = __nccwpck_require__.ab + "unity.ps1";
const pwsh = await io.which('pwsh', true);
exitCode = await exec.exec(`"${pwsh}" -Command`, [`${unity} -EditorPath '${editorPath}' -Arguments '${args.join(` `)}' -LogPath '${logPath}'`], {
listeners: {
stdline: (data) => {
const line = data.toString().trim();
if (line && line.length > 0) {
core.info(line);
}
}
},
silent: true,
ignoreReturnCode: true
});
break;
}
if (!isCancelled) {
await TryKillPid(pidFile);
if (exitCode !== 0) {
throw Error(`Unity failed with exit code ${exitCode}`);
}
}
}

function getLogFilePath(args) {
const logFileIndex = args.indexOf('-logFile');
if (logFileIndex === -1) {
throw Error('Missing -logFile argument');
}
return args[logFileIndex + 1];
}

async function TryKillPid(pidFile) {
try {
await fs.access(pidFile, fs.constants.R_OK);
const fileHandle = await fs.promises.open(pidFile, 'r');
try {
const pid = await fs.readFile(pidFile, 'utf8');
const pid = await fileHandle.readFile('utf8');
core.debug(`Attempting to kill Unity process with pid: ${pid}`);
process.kill(pid);
} catch (error) {
process.kill(parseInt(pid));
}
catch (error) {
if (error.code !== 'ENOENT' && error.code !== 'ESRCH') {
core.error(`Failed to kill Unity process:\n${JSON.stringify(error)}`);
}
} finally {
await fs.unlink(pidFile);
}
} catch (error) {
// nothing
finally {
await fileHandle.close();
await fs.promises.unlink(pidFile);
}
}
catch (error) {
}
}

module.exports = { ExecUnityPwsh };


/***/ }),

Expand Down Expand Up @@ -28217,21 +28223,24 @@ module.exports = parseParams
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
const { ValidateInputs } = __nccwpck_require__(7229);
const { ExecUnityPwsh } = __nccwpck_require__(8986);
const core = __nccwpck_require__(2186);
"use strict";
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const inputs_1 = __nccwpck_require__(7063);
const unity_1 = __nccwpck_require__(6938);
const core = __nccwpck_require__(2186);
const main = async () => {
try {
const [editor, args] = await ValidateInputs();
await ExecUnityPwsh(editor, args);
} catch (error) {
const [editor, args] = await (0, inputs_1.ValidateInputs)();
await (0, unity_1.ExecUnity)(editor, args);
}
catch (error) {
core.setFailed(error.message);
}
}

};
main();

})();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/unity.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# execute unity editor with the given path and Arguments
# execute unity editor with the given EditorPath, Arguments, and LogPath
param(
[string]$EditorPath,
[string]$Arguments,
Expand Down
Loading

0 comments on commit 7fa569b

Please sign in to comment.