Skip to content

Commit

Permalink
Feature/add support for licensing server (#196)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
simensan authored Nov 4, 2022
1 parent 68d1df1 commit 9fe2feb
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 7 deletions.
66 changes: 62 additions & 4 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions dist/steps/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions dist/steps/return_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -17,6 +23,5 @@ if [[ -n "$UNITY_SERIAL" ]]; then
-quit \
-returnlicense
fi

# Return to previous working directory
popd
7 changes: 7 additions & 0 deletions dist/unity-config/services-config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"licensingServiceBaseUrl": "%URL%",
"enableEntitlementLicensing": true,
"enableFloatingApi": true,
"clientConnectTimeoutSec": 5,
"clientHandshakeTimeoutSec": 10
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function run() {
githubToken,
checkName,
chownFilesTo,
unityLicensingServer,
} = Input.getFromUser();
const baseImage = new ImageTag({ editorVersion, customImage });
const runnerContext = Action.runnerContext();
Expand All @@ -39,6 +40,7 @@ export async function run() {
gitPrivateToken,
githubToken,
chownFilesTo,
unityLicensingServer,
...runnerContext,
});
} finally {
Expand Down
11 changes: 11 additions & 0 deletions src/model/docker.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -60,6 +66,7 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
unityLicensingServer,
} = parameters;

const githubHome = path.join(runnerTemporaryPath, '_github_home');
Expand All @@ -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}" \
Expand Down Expand Up @@ -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` : ''
Expand All @@ -136,6 +145,7 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
unityLicensingServer,
} = parameters;

const githubHome = path.join(runnerTemporaryPath, '_github_home');
Expand All @@ -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}" \
Expand Down
2 changes: 2 additions & 0 deletions src/model/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') || '';
Expand Down Expand Up @@ -67,6 +68,7 @@ const Input = {
githubToken,
checkName,
chownFilesTo,
unityLicensingServer,
};
},
};
Expand Down
20 changes: 20 additions & 0 deletions src/model/licensing-server-setup.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9fe2feb

Please sign in to comment.