Feature/add support for licensing server (#196)

* First take on adding support for sending in unity licensing server url on linux

* Forgot to build dist

* Moved services-config parsing to typescript

* Need to set licensing server env variable for activate.sh

* Forgot unused docker mount directory /resources
pull/201/head v2.1.0
simensan 2022-11-04 12:35:06 +01:00 committed by GitHub
parent 68d1df1d1b
commit 9fe2feb3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 126 additions and 7 deletions

66
dist/index.js generated vendored
View File

@ -94,7 +94,7 @@ function run() {
try {
model_1.Action.checkCompatibility();
const { workspace, actionFolder } = model_1.Action;
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, chownFilesTo, } = model_1.Input.getFromUser();
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
const baseImage = new model_1.ImageTag({ editorVersion, customImage });
const runnerContext = model_1.Action.runnerContext();
try {
@ -110,7 +110,8 @@ function run() {
sshAgent,
gitPrivateToken,
githubToken,
chownFilesTo }, runnerContext));
chownFilesTo,
unityLicensingServer }, runnerContext));
}
finally {
yield model_1.Output.setArtifactsPath(artifactsPath);
@ -208,6 +209,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs_1 = __nccwpck_require__(7147);
const licensing_server_setup_1 = __importDefault(__nccwpck_require__(6089));
const exec_1 = __nccwpck_require__(1514);
const path_1 = __importDefault(__nccwpck_require__(1017));
/**
@ -237,6 +239,9 @@ const Docker = {
run(image, parameters, silent = false) {
return __awaiter(this, void 0, void 0, function* () {
let runCommand = '';
if (parameters.unityLicensingServer !== '') {
licensing_server_setup_1.default.Setup(parameters.unityLicensingServer, parameters.actionFolder);
}
switch (process.platform) {
case 'linux':
runCommand = this.getLinuxCommand(image, parameters);
@ -251,7 +256,7 @@ const Docker = {
});
},
getLinuxCommand(image, parameters) {
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
@ -269,6 +274,7 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_LICENSING_SERVER="${unityLicensingServer}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
@ -299,6 +305,7 @@ const Docker = {
--volume "${workspace}:/github/workspace:z" \
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''} \
${useHostNetwork ? '--net=host' : ''} \
@ -307,7 +314,7 @@ const Docker = {
/bin/bash -c /entrypoint.sh`;
},
getWindowsCommand(image, parameters) {
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
@ -325,6 +332,7 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_LICENSING_SERVER="${unityLicensingServer}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
@ -556,6 +564,7 @@ const Input = {
const unityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
const customImage = (0, core_1.getInput)('customImage') || '';
const rawProjectPath = (0, core_1.getInput)('projectPath') || '.';
const unityLicensingServer = (0, core_1.getInput)('unityLicensingServer') || '';
const customParameters = (0, core_1.getInput)('customParameters') || '';
const testMode = ((0, core_1.getInput)('testMode') || 'all').toLowerCase();
const coverageOptions = (0, core_1.getInput)('coverageOptions') || '';
@ -599,12 +608,61 @@ const Input = {
githubToken,
checkName,
chownFilesTo,
unityLicensingServer,
};
},
};
exports["default"] = Input;
/***/ }),
/***/ 6089:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
class LicensingServerSetup {
static Setup(unityLicensingServer, actionFolder) {
const servicesConfigPath = `${actionFolder}/unity-config/services-config.json`;
const servicesConfigPathTemplate = `${servicesConfigPath}.template`;
if (!fs_1.default.existsSync(servicesConfigPathTemplate)) {
core.error(`Missing services config ${servicesConfigPathTemplate}`);
return;
}
let servicesConfig = fs_1.default.readFileSync(servicesConfigPathTemplate).toString();
servicesConfig = servicesConfig.replace('%URL%', unityLicensingServer);
fs_1.default.writeFileSync(servicesConfigPath, servicesConfig);
}
}
exports["default"] = LicensingServerSetup;
/***/ }),
/***/ 5487:

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,21 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
# Store the exit code from the verify command
UNITY_EXIT_CODE=$?
elif [[ -n "$UNITY_LICENSING_SERVER" ]]; then
#
# Custom Unity License Server
#
echo "Adding licensing server config"
/opt/unity/Editor/Data/Resources/Licensing/Client/Unity.Licensing.Client --acquire-floating > license.txt #is this accessible in a env variable?
UNITY_EXIT_CODE=$?
PARSEDFILE=$(grep -oP '\".*?\"' < license.txt | tr -d '"')
export FLOATING_LICENSE
FLOATING_LICENSE=$(sed -n 2p <<< "$PARSEDFILE")
FLOATING_LICENSE_TIMEOUT=$(sed -n 4p <<< "$PARSEDFILE")
echo "Acquired floating license: \"$FLOATING_LICENSE\" with timeout $FLOATING_LICENSE_TIMEOUT"
# Store the exit code from the verify command
else
#
# NO LICENSE ACTIVATION STRATEGY MATCHED

View File

@ -4,7 +4,13 @@
echo "Changing to \"$ACTIVATE_LICENSE_PATH\" directory."
pushd "$ACTIVATE_LICENSE_PATH"
if [[ -n "$UNITY_SERIAL" ]]; then
if [[ -n "$UNITY_LICENSING_SERVER" ]]; then #
#
# Return any floating license used.
#
echo "Returning floating license: \"$FLOATING_LICENSE\""
/opt/unity/Editor/Data/Resources/Licensing/Client/Unity.Licensing.Client --return-floating "$FLOATING_LICENSE"
elif [[ -n "$UNITY_SERIAL" ]]; then
#
# PROFESSIONAL (SERIAL) LICENSE MODE
#
@ -17,6 +23,5 @@ if [[ -n "$UNITY_SERIAL" ]]; then
-quit \
-returnlicense
fi
# Return to previous working directory
popd

View File

@ -0,0 +1,7 @@
{
"licensingServiceBaseUrl": "%URL%",
"enableEntitlementLicensing": true,
"enableFloatingApi": true,
"clientConnectTimeoutSec": 5,
"clientHandshakeTimeoutSec": 10
}

View File

@ -20,6 +20,7 @@ export async function run() {
githubToken,
checkName,
chownFilesTo,
unityLicensingServer,
} = Input.getFromUser();
const baseImage = new ImageTag({ editorVersion, customImage });
const runnerContext = Action.runnerContext();
@ -39,6 +40,7 @@ export async function run() {
gitPrivateToken,
githubToken,
chownFilesTo,
unityLicensingServer,
...runnerContext,
});
} finally {

View File

@ -1,4 +1,5 @@
import { existsSync, mkdirSync, readFileSync, rmSync } from 'fs';
import LicensingServerSetup from './licensing-server-setup';
import type { RunnerContext } from './action';
import { exec } from '@actions/exec';
import path from 'path';
@ -30,6 +31,11 @@ const Docker = {
async run(image, parameters, silent = false) {
let runCommand = '';
if (parameters.unityLicensingServer !== '') {
LicensingServerSetup.Setup(parameters.unityLicensingServer, parameters.actionFolder);
}
switch (process.platform) {
case 'linux':
runCommand = this.getLinuxCommand(image, parameters);
@ -60,6 +66,7 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
unityLicensingServer,
} = parameters;
const githubHome = path.join(runnerTemporaryPath, '_github_home');
@ -80,6 +87,7 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_LICENSING_SERVER="${unityLicensingServer}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
@ -110,6 +118,7 @@ const Docker = {
--volume "${workspace}:/github/workspace:z" \
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${
sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''
@ -136,6 +145,7 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
unityLicensingServer,
} = parameters;
const githubHome = path.join(runnerTemporaryPath, '_github_home');
@ -156,6 +166,7 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_LICENSING_SERVER="${unityLicensingServer}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \

View File

@ -17,6 +17,7 @@ const Input = {
const unityVersion = getInput('unityVersion') || 'auto';
const customImage = getInput('customImage') || '';
const rawProjectPath = getInput('projectPath') || '.';
const unityLicensingServer = getInput('unityLicensingServer') || '';
const customParameters = getInput('customParameters') || '';
const testMode = (getInput('testMode') || 'all').toLowerCase();
const coverageOptions = getInput('coverageOptions') || '';
@ -67,6 +68,7 @@ const Input = {
githubToken,
checkName,
chownFilesTo,
unityLicensingServer,
};
},
};

View File

@ -0,0 +1,20 @@
import * as core from '@actions/core';
import fs from 'fs';
class LicensingServerSetup {
public static Setup(unityLicensingServer, actionFolder: string) {
const servicesConfigPath = `${actionFolder}/unity-config/services-config.json`;
const servicesConfigPathTemplate = `${servicesConfigPath}.template`;
if (!fs.existsSync(servicesConfigPathTemplate)) {
core.error(`Missing services config ${servicesConfigPathTemplate}`);
return;
}
let servicesConfig = fs.readFileSync(servicesConfigPathTemplate).toString();
servicesConfig = servicesConfig.replace('%URL%', unityLicensingServer);
fs.writeFileSync(servicesConfigPath, servicesConfig);
}
}
export default LicensingServerSetup;