Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fix exit code capture and message
- always auth with hub license client
  • Loading branch information
StephenHodgson authored Aug 11, 2024
1 parent 5f92211 commit 5ff5b2a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 143 deletions.
97 changes: 27 additions & 70 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28668,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 Down Expand Up @@ -28700,69 +28701,24 @@ let client = undefined;

async function getLicensingClient() {
core.debug('Getting Licensing Client...');
let useLicenseClient = false;
const editorPath = process.env.UNITY_EDITOR_PATH;
if (editorPath) {
core.debug(`Unity Editor Path: ${editorPath}`);
await fs.access(editorPath, fs.constants.X_OK);
const version = process.env.UNITY_EDITOR_VERSION || editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Version: ${version}`);
const major = version.split('.')[0];
// if 2019.3 or older, use unity hub licensing client
useLicenseClient = 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 {
useLicenseClient = true;
}
let licenseClientPath;
if (useLicenseClient) {
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;
globs.push('Unity.Licensing.Client');
}
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 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 @@ -28774,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 @@ -28796,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 @@ -28861,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 @@ -28918,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 @@ -28986,7 +28943,7 @@ async function findGlobPattern(pattern) {
}
}

module.exports = { ResolveGlobPath, GetEditorRootPath, GetHubRootPath }
module.exports = { ResolveGlobPath, GetEditorRootPath, 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.0.1",
"version": "1.0.2",
"description": "A GitHub Action to activate a Unity Game Engine license for CI/CD workflows.",
"author": "buildalon",
"license": "MIT",
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
89 changes: 23 additions & 66 deletions src/licensing-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,24 @@ let client = undefined;

async function getLicensingClient() {
core.debug('Getting Licensing Client...');
let useLicenseClient = false;
const editorPath = process.env.UNITY_EDITOR_PATH;
if (editorPath) {
core.debug(`Unity Editor Path: ${editorPath}`);
await fs.access(editorPath, fs.constants.X_OK);
const version = process.env.UNITY_EDITOR_VERSION || editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Version: ${version}`);
const major = version.split('.')[0];
useLicenseClient = 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 {
useLicenseClient = true;
globs.push('Unity.Licensing.Client');
}
let licenseClientPath;
if (useLicenseClient) {
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 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 @@ -81,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 @@ -103,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 @@ -168,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 @@ -225,4 +182,4 @@ async function ReturnLicense(license) {
}
}

module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense };
module.exports = { Version, ShowEntitlements, ActivateLicense, ActivateLicenseWithConfig, ReturnLicense }
2 changes: 1 addition & 1 deletion src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ async function findGlobPattern(pattern) {
}
}

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

0 comments on commit 5ff5b2a

Please sign in to comment.