Moved services-config parsing to typescript

pull/196/head
Simen Sandvaer 2022-10-22 21:59:51 +02:00
parent d3bff596c3
commit 77f0ddb2dd
6 changed files with 82 additions and 10 deletions

56
dist/index.js generated vendored
View File

@ -151,12 +151,16 @@ 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));
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);
@ -171,7 +175,7 @@ const Docker = {
});
},
getLinuxCommand(image, parameters) {
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
@ -187,7 +191,6 @@ 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}" \
@ -219,6 +222,7 @@ const Docker = {
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/resources:/resources: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' : ''} \
@ -526,6 +530,54 @@ const Input = {
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

@ -82,10 +82,6 @@ elif [[ -n "$UNITY_LICENSING_SERVER" ]]; then
# Custom Unity License Server
#
echo "Adding licensing server config"
pushd /resources
cat services-config.json.template | tr -d '\r' | awk "{sub(/%URL%/,\"$UNITY_LICENSING_SERVER\")}1" > services-config.json
mkdir -p /usr/share/unity3d/config/
mv services-config.json /usr/share/unity3d/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=$?
@ -96,7 +92,6 @@ elif [[ -n "$UNITY_LICENSING_SERVER" ]]; then
echo "Acquired floating license: \"$FLOATING_LICENSE\" with timeout $FLOATING_LICENSE_TIMEOUT"
# Store the exit code from the verify command
popd
else
#
# NO LICENSE ACTIVATION STRATEGY MATCHED

View File

@ -1,10 +1,16 @@
import { existsSync, mkdirSync } from 'fs';
import LicensingServerSetup from './licensing-server-setup';
import { exec } from '@actions/exec';
import path from 'path';
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);
@ -34,7 +40,6 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
unityLicensingServer,
} = parameters;
const githubHome = path.join(runnerTemporaryPath, '_github_home');
@ -53,7 +58,6 @@ 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}" \
@ -85,6 +89,7 @@ const Docker = {
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/resources:/resources: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` : ''

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;