Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
refactor again
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Jul 18, 2024
1 parent addc93d commit e766ff7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 61 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
#max-parallel: 2 # Use this if you're activating pro license with matrix
# max-parallel: 2 # Use this if you're activating pro license with matrix
matrix:
include:
- os: ubuntu-latest
Expand Down Expand Up @@ -58,13 +58,10 @@ jobs:
- name: xrtk/activate-unity-license
uses: ./
with:
# Required
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
username: ${{ secrets.UNITY_USERNAME }}
password: ${{ secrets.UNITY_PASSWORD }}
# Optional
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
# serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations
auth-key: ${{ secrets.UNITY_2FA_KEY }} # required for personal activations
# serial: ${{ secrets.UNITY_SERIAL }} # Required for pro activations

- name: Unity Build (${{ matrix.build-target }})
uses: xrtk/unity-action@v6
Expand Down
98 changes: 71 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26155,7 +26155,6 @@ exports["default"] = _default;
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const fs = __nccwpck_require__(7147);
const path = __nccwpck_require__(1017);
const licenseClient = __nccwpck_require__(917);
Expand All @@ -26168,6 +26167,7 @@ async function Run() {
return;
} else {
core.debug('Attempting to activate Unity License...');
await licenseClient.version();
core.saveState('isPost', true);
}

Expand All @@ -26189,32 +26189,20 @@ async function Run() {
throw Error('Missing password input');
}

const client = licenseClient.getLicensingClient();
core.debug(`Unity Licensing Client Path: ${client}`);
await exec.exec(`"${client}" --version`);

const serial = core.getInput('serial');
const licenseType = core.getInput('license-type');
var args = `--activate-ulf --username "${username}" --password "${password}"`;

if (licenseType.toLowerCase().startsWith('pro')) {
const serial = core.getInput('serial');

if (!serial) {
throw Error('Missing serial input');
}

const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
args += ` --serial ${serial}`;
if (licenseType.toLowerCase().startsWith('pro') && !serial) {
throw Error('Missing serial input');
}

await exec.exec(`"${client}" ${args}`);
await licenseClient.activateLicense(username, password, serial);

if (!licenseClient.hasExistingLicense()) {
throw Error('Unable to find Unity License!');
}

await exec.exec(`"${client}" --showEntitlements`);
await licenseClient.showEntitlements();
} catch (error) {
core.setFailed(`Unity License Activation Failed! ${error.message}`);
GetLogs();
Expand Down Expand Up @@ -26266,16 +26254,13 @@ module.exports = { Run };
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const licensingClient = __nccwpck_require__(917);

async function Run() {
try {
if (licensingClient.hasExistingLicense()) {
console.info(`::group::Returning Unity License`);
const client = licensingClient.getLicensingClient();
await exec.exec(`"${client}" --return-ulf`);
await exec.exec(`"${client}" --showEntitlements`);
await licensingClient.returnLicense();
console.info(`::endgroup::`);
}
} catch (error) {
Expand All @@ -26292,16 +26277,17 @@ module.exports = { Run }
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const fs = __nccwpck_require__(7147);
const path = __nccwpck_require__(1017);
const platform = process.platform;

function getLicensingClient() {
const getLicensingClient = () => {
// 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
var editorPath = platform !== 'darwin' ? path.resolve(process.env.UNITY_EDITOR_PATH, '..') : path.resolve(process.env.UNITY_EDITOR_PATH, '..', '..');
let editorPath = platform !== 'darwin' ? path.resolve(process.env.UNITY_EDITOR_PATH, '..') : path.resolve(process.env.UNITY_EDITOR_PATH, '..', '..');
const version = editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Editor Path: ${editorPath}`);
core.debug(`Unity Version: ${version}`);
Expand All @@ -26310,7 +26296,7 @@ function getLicensingClient() {
throw Error(`Unity Editor not found at path: ${editorPath}`);
}

var licenseClientPath;
let licenseClientPath;

switch (platform) {
case 'win32':
Expand Down Expand Up @@ -26339,7 +26325,40 @@ function getLicensingClient() {
}

return licenseClientPath;
}
};

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

const client = getLicensingClient();

async function execWithMask(command) {
let output = '';
let error = '';
try {
await exec.exec(command, [], {
silent: true,
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
}
});

} finally {
core.info(maskSerialInOutput(output));
if (error !== '') {
throw Error(error);
}
}
};

function hasExistingLicense() {
core.debug('Checking for existing Unity License activation...');
Expand Down Expand Up @@ -26418,7 +26437,32 @@ function hasExistingLicense() {
return false;
}

module.exports = { getLicensingClient, hasExistingLicense };
async function version() {
await execWithMask(`"${client}" --version`);
}

async function showEntitlements() {
await execWithMask(`"${client}" --showEntitlements`);
}

async function activateLicense(username, password, serial) {
let args = `--activate-ulf --username "${username}" --password "${password}"`;

if (serial !== undefined && serial !== '') {
args += ` --serial "${serial}"`;
const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
}

await execWithMask(`"${client}" ${args}`);
}

async function returnLicense() {
await execWithMask(`"${client}" --return-ulf`);
await showEntitlements();
}

module.exports = { hasExistingLicense, version, showEntitlements, activateLicense, returnLicense };


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

Large diffs are not rendered by default.

24 changes: 6 additions & 18 deletions src/activate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require("fs");
const path = require('path');
const licenseClient = require('./licensing-client');
Expand All @@ -12,6 +11,7 @@ async function Run() {
return;
} else {
core.debug('Attempting to activate Unity License...');
await licenseClient.version();
core.saveState('isPost', true);
}

Expand All @@ -33,32 +33,20 @@ async function Run() {
throw Error('Missing password input');
}

const client = licenseClient.getLicensingClient();
core.debug(`Unity Licensing Client Path: ${client}`);
await exec.exec(`"${client}" --version`);

const serial = core.getInput('serial');
const licenseType = core.getInput('license-type');
var args = `--activate-ulf --username "${username}" --password "${password}"`;

if (licenseType.toLowerCase().startsWith('pro')) {
const serial = core.getInput('serial');

if (!serial) {
throw Error('Missing serial input');
}

const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
args += ` --serial ${serial}`;
if (licenseType.toLowerCase().startsWith('pro') && !serial) {
throw Error('Missing serial input');
}

await exec.exec(`"${client}" ${args}`);
await licenseClient.activateLicense(username, password, serial);

if (!licenseClient.hasExistingLicense()) {
throw Error('Unable to find Unity License!');
}

await exec.exec(`"${client}" --showEntitlements`);
await licenseClient.showEntitlements();
} catch (error) {
core.setFailed(`Unity License Activation Failed! ${error.message}`);
GetLogs();
Expand Down
5 changes: 1 addition & 4 deletions src/deactivate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
const licensingClient = require('./licensing-client');

async function Run() {
try {
if (licensingClient.hasExistingLicense()) {
console.info(`::group::Returning Unity License`);
const client = licensingClient.getLicensingClient();
await exec.exec(`"${client}" --return-ulf`);
await exec.exec(`"${client}" --showEntitlements`);
await licensingClient.returnLicense();
console.info(`::endgroup::`);
}
} catch (error) {
Expand Down
69 changes: 64 additions & 5 deletions src/licensing-client.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require("fs");
const path = require('path');
const platform = process.platform;

function getLicensingClient() {
const getLicensingClient = () => {
// 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
var editorPath = platform !== 'darwin' ? path.resolve(process.env.UNITY_EDITOR_PATH, '..') : path.resolve(process.env.UNITY_EDITOR_PATH, '..', '..');
let editorPath = platform !== 'darwin' ? path.resolve(process.env.UNITY_EDITOR_PATH, '..') : path.resolve(process.env.UNITY_EDITOR_PATH, '..', '..');
const version = editorPath.match(/(\d+\.\d+\.\d+[a-z]?\d?)/)[0];
core.debug(`Unity Editor Path: ${editorPath}`);
core.debug(`Unity Version: ${version}`);
Expand All @@ -17,7 +18,7 @@ function getLicensingClient() {
throw Error(`Unity Editor not found at path: ${editorPath}`);
}

var licenseClientPath;
let licenseClientPath;

switch (platform) {
case 'win32':
Expand Down Expand Up @@ -46,7 +47,40 @@ function getLicensingClient() {
}

return licenseClientPath;
}
};

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

const client = getLicensingClient();

async function execWithMask(command) {
let output = '';
let error = '';
try {
await exec.exec(command, [], {
silent: true,
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
}
});

} finally {
core.info(maskSerialInOutput(output));
if (error !== '') {
throw Error(error);
}
}
};

function hasExistingLicense() {
core.debug('Checking for existing Unity License activation...');
Expand Down Expand Up @@ -125,4 +159,29 @@ function hasExistingLicense() {
return false;
}

module.exports = { getLicensingClient, hasExistingLicense };
async function version() {
await execWithMask(`"${client}" --version`);
}

async function showEntitlements() {
await execWithMask(`"${client}" --showEntitlements`);
}

async function activateLicense(username, password, serial) {
let args = `--activate-ulf --username "${username}" --password "${password}"`;

if (serial !== undefined && serial !== '') {
args += ` --serial "${serial}"`;
const maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);
}

await execWithMask(`"${client}" ${args}`);
}

async function returnLicense() {
await execWithMask(`"${client}" --return-ulf`);
await showEntitlements();
}

module.exports = { hasExistingLicense, version, showEntitlements, activateLicense, returnLicense };

0 comments on commit e766ff7

Please sign in to comment.