Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fix exit code capture and messages
- always auth with hub license client
  • Loading branch information
StephenHodgson authored Aug 12, 2024
1 parent 1b38f54 commit aa29afa
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 183 deletions.
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: activate-unity-license
description: 'A GitHub Action to activate a Unity Game Engine license for CI/CD workflows.'
description: A GitHub Action to activate a Unity Game Engine license for CI/CD workflows.
branding:
color: blue
icon: log-in
inputs:
license:
description: 'Must be one of `Personal`, `Professional`, `Floating`.'
Expand Down
118 changes: 29 additions & 89 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28600,10 +28600,6 @@ const core = __nccwpck_require__(2186);
async function Activate() {
let license = undefined;
try {
const editorPath = process.env.UNITY_EDITOR_PATH;
if (!editorPath) {
throw Error("Missing UNITY_EDITOR_PATH!");
}
core.saveState('isPost', true);
await licenseClient.Version();
let activeLicenses = await licenseClient.ShowEntitlements();
Expand Down Expand Up @@ -28672,9 +28668,10 @@ async function Deactivate() {
const activeLicenses = await licensingClient.ShowEntitlements();
if (license !== undefined &&
!activeLicenses.includes(license.toLowerCase())) {
core.warning(`${license} was never activated.`);
throw Error(`Unity ${license} License is not activated!`);
} else {
await licensingClient.ReturnLicense(license);
}
await licensingClient.ReturnLicense(license);
}
finally {
core.endGroup();
Expand All @@ -28694,7 +28691,7 @@ module.exports = { Deactivate }
/***/ 917:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const { ResolveGlobPath, GetEditorRootPath, GetHubRootPath } = __nccwpck_require__(4345);
const { ResolveGlobPath, GetHubRootPath } = __nccwpck_require__(4345);
const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const fs = (__nccwpck_require__(7147).promises);
Expand All @@ -28704,63 +28701,24 @@ let client = undefined;

async function getLicensingClient() {
core.debug('Getting Licensing Client...');
const editorPath = process.env.UNITY_EDITOR_PATH;
const version = process.env.UNITY_EDITOR_VERSION || editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Editor Path: ${editorPath}`);
core.debug(`Unity Version: ${version}`);
await fs.access(editorPath, fs.constants.X_OK);
let licenseClientPath;
const major = version.split('.')[0];
// if 2019.3 or older, use unity hub licensing client
if (major < 2020) {
const unityHubPath = process.env.UNITY_HUB_PATH || process.env.HOME;
core.debug(`Unity Hub Path: ${unityHubPath}`);
await fs.access(unityHubPath, fs.constants.R_OK);
// C:\Program Files\Unity Hub\UnityLicensingClient_V1
// /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub/UnityLicensingClient_V1
// ~/Applications/Unity\ Hub.AppImage/UnityLicensingClient_V1
const rootHubPath = await GetHubRootPath(unityHubPath);
const globs = [rootHubPath, '**'];
if (process.platform === 'win32') {
globs.push('Unity.Licensing.Client.exe');
} else {
globs.push('Unity.Licensing.Client');
}
licenseClientPath = await ResolveGlobPath(globs);
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
}
else {
// Windows: <UnityEditorDir>\Data\Resources\Licensing\Client
// macOS (Editor versions 2021.3.19f1 or later): <UnityEditorDir>/Contents/Frameworks/UnityLicensingClient.app/Contents/MacOS/
// macOS (Editor versions earlier than 2021.3.19f1): <UnityEditorDir>/Contents/Frameworks/UnityLicensingClient.app/Contents/Resources/
// Linux: <UnityEditorDir>/Data/Resources/Licensing/Client/
const rootEditorPath = await GetEditorRootPath(editorPath);
core.debug(`Root Editor Path: ${rootEditorPath}`);
const globs = [rootEditorPath];
switch (process.platform) {
case 'win32':
globs.push('Data\\Resources\\Licensing\\Client\\Unity.Licensing.Client.exe');
break;
case 'darwin':
globs.push('Contents', 'Frameworks', 'UnityLicensingClient.app', '**', 'Unity.Licensing.Client');
break;
case 'linux':
globs.push('Data', 'Resources', 'Licensing', 'Client', 'Unity.Licensing.Client');
}
try {
licenseClientPath = path.resolve(...globs);
core.debug(`Testing Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.R_OK);
} catch (error) {
licenseClientPath = await ResolveGlobPath(globs);
}
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
const unityHubPath = process.env.UNITY_HUB_PATH || process.env.HOME;
core.debug(`Unity Hub Path: ${unityHubPath}`);
await fs.access(unityHubPath, fs.constants.R_OK);
// C:\Program Files\Unity Hub\UnityLicensingClient_V1
// /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub/UnityLicensingClient_V1
// ~/Applications/Unity\ Hub.AppImage/UnityLicensingClient_V1
const rootHubPath = await GetHubRootPath(unityHubPath);
const globs = [rootHubPath, '**'];
if (process.platform === 'win32') {
globs.push('Unity.Licensing.Client.exe');
} else {
globs.push('Unity.Licensing.Client');
}
};
const licenseClientPath = await ResolveGlobPath(globs);
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
}

async function execWithMask(args) {
if (!client) {
Expand All @@ -28772,15 +28730,16 @@ async function execWithMask(args) {
try {
core.info(`[command]"${client}" ${args.join(' ')}`);
exitCode = await exec.exec(`"${client}"`, args, {
silent: true,
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
output += data.toString();
}
}
},
silent: true,
ignoreReturnCode: true
});
} finally {
const maskedOutput = maskSerialInOutput(output);
Expand All @@ -28794,15 +28753,15 @@ async function execWithMask(args) {
}
}
return output;
};
}

function maskSerialInOutput(output) {
return output.replace(/([\w-]+-XXXX)/g, (_, serial) => {
const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
return serial;
});
};
}

function getExitCodeMessage(exitCode) {
switch (exitCode) {
Expand Down Expand Up @@ -28859,7 +28818,7 @@ const servicesPath = {
win32: path.join(process.env.PROGRAMDATA || '', 'Unity', 'config'),
darwin: path.join('/Library', 'Application Support', 'Unity', 'config'),
linux: path.join('/usr', 'share', 'unity3d', 'config')
};
}

async function Version() {
await execWithMask([`--version`]);
Expand Down Expand Up @@ -28916,7 +28875,7 @@ async function ReturnLicense(license) {
}
}

module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense };
module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense }


/***/ }),
Expand Down Expand Up @@ -28946,25 +28905,6 @@ async function GetHubRootPath(hubPath) {
return hubRootPath;
}

async function GetEditorRootPath(editorPath) {
core.debug(`searching for editor root path: ${editorPath}`);
let editorRootPath = editorPath;
switch (process.platform) {
case 'darwin':
editorRootPath = path.join(editorPath, '../../../');
break;
case 'win32':
editorRootPath = path.join(editorPath, '../');
break
case 'linux':
editorRootPath = path.join(editorPath, '../');
break;
}
await fs.access(editorRootPath, fs.constants.R_OK);
core.debug(`found editor root path: ${editorRootPath}`);
return editorRootPath;
}

async function ResolveGlobPath(globs) {
const globPath = path.join(...globs);
const result = await findGlobPattern(globPath);
Expand All @@ -28984,7 +28924,7 @@ async function findGlobPattern(pattern) {
}
}

module.exports = { ResolveGlobPath, GetEditorRootPath, GetHubRootPath }
module.exports = { ResolveGlobPath, GetHubRootPath };


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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "activate-unity-license",
"version": "1.1.1",
"version": "1.1.2",
"description": "A GitHub Action to activate a Unity Game Engine license for CI/CD workflows.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
4 changes: 0 additions & 4 deletions src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ const core = require('@actions/core');
async function Activate() {
let license = undefined;
try {
const editorPath = process.env.UNITY_EDITOR_PATH;
if (!editorPath) {
throw Error("Missing UNITY_EDITOR_PATH!");
}
core.saveState('isPost', true);
await licenseClient.Version();
let activeLicenses = await licenseClient.ShowEntitlements();
Expand Down
5 changes: 3 additions & 2 deletions src/deactivate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ async function Deactivate() {
const activeLicenses = await licensingClient.ShowEntitlements();
if (license !== undefined &&
!activeLicenses.includes(license.toLowerCase())) {
core.warning(`${license} was never activated.`);
throw Error(`Unity ${license} License is not activated!`);
} else {
await licensingClient.ReturnLicense(license);
}
await licensingClient.ReturnLicense(license);
}
finally {
core.endGroup();
Expand Down
88 changes: 25 additions & 63 deletions src/licensing-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ResolveGlobPath, GetEditorRootPath, GetHubRootPath } = require('./utility');
const { ResolveGlobPath, GetHubRootPath } = require('./utility');
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require("fs").promises;
Expand All @@ -8,63 +8,24 @@ let client = undefined;

async function getLicensingClient() {
core.debug('Getting Licensing Client...');
const editorPath = process.env.UNITY_EDITOR_PATH;
const version = process.env.UNITY_EDITOR_VERSION || editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Editor Path: ${editorPath}`);
core.debug(`Unity Version: ${version}`);
await fs.access(editorPath, fs.constants.X_OK);
let licenseClientPath;
const major = version.split('.')[0];
// if 2019.3 or older, use unity hub licensing client
if (major < 2020) {
const unityHubPath = process.env.UNITY_HUB_PATH || process.env.HOME;
core.debug(`Unity Hub Path: ${unityHubPath}`);
await fs.access(unityHubPath, fs.constants.R_OK);
// C:\Program Files\Unity Hub\UnityLicensingClient_V1
// /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub/UnityLicensingClient_V1
// ~/Applications/Unity\ Hub.AppImage/UnityLicensingClient_V1
const rootHubPath = await GetHubRootPath(unityHubPath);
const globs = [rootHubPath, '**'];
if (process.platform === 'win32') {
globs.push('Unity.Licensing.Client.exe');
} else {
globs.push('Unity.Licensing.Client');
}
licenseClientPath = await ResolveGlobPath(globs);
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
}
else {
// Windows: <UnityEditorDir>\Data\Resources\Licensing\Client
// macOS (Editor versions 2021.3.19f1 or later): <UnityEditorDir>/Contents/Frameworks/UnityLicensingClient.app/Contents/MacOS/
// macOS (Editor versions earlier than 2021.3.19f1): <UnityEditorDir>/Contents/Frameworks/UnityLicensingClient.app/Contents/Resources/
// Linux: <UnityEditorDir>/Data/Resources/Licensing/Client/
const rootEditorPath = await GetEditorRootPath(editorPath);
core.debug(`Root Editor Path: ${rootEditorPath}`);
const globs = [rootEditorPath];
switch (process.platform) {
case 'win32':
globs.push('Data\\Resources\\Licensing\\Client\\Unity.Licensing.Client.exe');
break;
case 'darwin':
globs.push('Contents', 'Frameworks', 'UnityLicensingClient.app', '**', 'Unity.Licensing.Client');
break;
case 'linux':
globs.push('Data', 'Resources', 'Licensing', 'Client', 'Unity.Licensing.Client');
}
try {
licenseClientPath = path.resolve(...globs);
core.debug(`Testing Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.R_OK);
} catch (error) {
licenseClientPath = await ResolveGlobPath(globs);
}
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
const unityHubPath = process.env.UNITY_HUB_PATH || process.env.HOME;
core.debug(`Unity Hub Path: ${unityHubPath}`);
await fs.access(unityHubPath, fs.constants.R_OK);
// C:\Program Files\Unity Hub\UnityLicensingClient_V1
// /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub/UnityLicensingClient_V1
// ~/Applications/Unity\ Hub.AppImage/UnityLicensingClient_V1
const rootHubPath = await GetHubRootPath(unityHubPath);
const globs = [rootHubPath, '**'];
if (process.platform === 'win32') {
globs.push('Unity.Licensing.Client.exe');
} else {
globs.push('Unity.Licensing.Client');
}
};
const licenseClientPath = await ResolveGlobPath(globs);
core.debug(`Unity Licensing Client Path: ${licenseClientPath}`);
await fs.access(licenseClientPath, fs.constants.X_OK);
return licenseClientPath;
}

async function execWithMask(args) {
if (!client) {
Expand All @@ -76,15 +37,16 @@ async function execWithMask(args) {
try {
core.info(`[command]"${client}" ${args.join(' ')}`);
exitCode = await exec.exec(`"${client}"`, args, {
silent: true,
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
output += data.toString();
}
}
},
silent: true,
ignoreReturnCode: true
});
} finally {
const maskedOutput = maskSerialInOutput(output);
Expand All @@ -98,15 +60,15 @@ async function execWithMask(args) {
}
}
return output;
};
}

function maskSerialInOutput(output) {
return output.replace(/([\w-]+-XXXX)/g, (_, serial) => {
const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
return serial;
});
};
}

function getExitCodeMessage(exitCode) {
switch (exitCode) {
Expand Down Expand Up @@ -163,7 +125,7 @@ const servicesPath = {
win32: path.join(process.env.PROGRAMDATA || '', 'Unity', 'config'),
darwin: path.join('/Library', 'Application Support', 'Unity', 'config'),
linux: path.join('/usr', 'share', 'unity3d', 'config')
};
}

async function Version() {
await execWithMask([`--version`]);
Expand Down Expand Up @@ -220,4 +182,4 @@ async function ReturnLicense(license) {
}
}

module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense };
module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense }
Loading

0 comments on commit aa29afa

Please sign in to comment.