game-ci / game-ci/unity3d-gitlab-ci-example-mirror
Draft: completely scripted activation
- Dominant language
- C#
- Stars
- 243
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Hey there,
since all your content has helped me alot with setting up dockerized unity I wanted to share my working approach to activating unity by script.
node/puppeteer script:
```javascript
const puppeteer = require('puppeteer');
const fs = require('fs');
try {
fs.mkdirSync('debug_images');
console.log('created debug folder.');
} catch (e) {
console.log('debug folder already present.');
}
(async () => {
const browser = await puppeteer.launch({
args: ["--no-sandbox"]
});
const page = await browser.newPage();
// open manual page & wait for login redirect
await page.goto('https://license.unity3d.com/manual');
const mailInputSelector = '#conversations_create_session_form_email',
passInputSelector = '#conversations_create_session_form_password';
await page.waitForSelector(mailInputSelector);
// enter credentials
await page.type(mailInputSelector, process.env.UNITY_USERNAME);
await page.type(passInputSelector, process.env.UNITY_PASSWORD);
await page.screenshot({ path: 'debug_images/01_entered_credentials.png' });
// click submit
await page.click('input[name=commit]');
// wait for license upload form
const licenseUploadfield = '#licenseFile';
await page.waitForSelector(licenseUploadfield);
await page.screenshot({ path: 'debug_images/02_opened_form.png' });
// enalbe interception
await page.setRequestInterception(true);
// upload license
page.once("request", interceptedRequest => {
interceptedRequest.continue({
method: "POST",
postData: fs.readFileSync(process.env.UNITY_ACTIVATION_FILE, 'utf8'),
headers: { "Content-Type": "text/xml" },
});
});
await page.goto('https://license.unity3d.com/genesis/activation/create-transaction');
await page.screenshot({ path: 'debug_images/03_created_transaction.png' });
// set license to be personal
page.once("request", interceptedRequest => {
interceptedRequest.continue({
method: "PUT",
postData: JSON.stringify({ transaction: { serial: { type: "personal" } } }),
headers: { "Content-Type": "application/json" }
});
});
await page.goto('https://license.unity3d.com/genesis/activation/update-transaction');
await page.screenshot({ path: 'debug_images/04_updated_transaction.png' });
// get license content
page.once("request", interceptedRequest => {
interceptedRequest.continue({
method: "POST",
postData: JSON.stringify({}),
headers: { "Content-Type": "application/json" }
});
});
page.on('response', async response => {
// write license
try {
const data = await response.text();
const dataJson = await JSON.parse(data);
fs.writeFileSync(process.env.UNITY_LICENSE_FILE, dataJson.xml);
console.log('license file written.');
await page.screenshot({ path: 'debug_images/05_received_license.png' });
} catch (e) {
console.log(e);
console.log('failed to write license file.');
}
});
await page.goto('https://license.unity3d.com/genesis/activation/download-license');
await page.waitFor(1000);
await browser.close();
})();
```
And then there's just a small shell script handling the rest. Please note that (only?) Unity 2018.3 cli supports manual generation of activation file, which comes in handy here.
```sh
#!/bin/sh
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/opt/Unity/Editor/Unity -batchmode -createManualActivationFile -nographics -logfile
find -name "Unity*" -exec mv {} ../$UNITY_ACTIVATION_FILE \;
if [ $? -ne 0 ]
then
echo "error while preparing generated license activation file."
exit 3
fi
cd ../
# run puppeteer activation macro
node index.js
if [ $? -ne 0 ]
then
echo "error while retrieving license."
exit 3
fi
mv $UNITY_LICENSE_FILE /root/.local/share/unity3d/Unity/
if [ $? -eq 0 ]
then
echo "license file installed."
exit 0
fi
```
Involved env vars:
```
UNITY_USERNAME=XXXXX@XXXXX.XXX
UNITY_PASSWORD=XXXXXXXXXXXXX
UNITY_ACTIVATION_FILE=unity3d.alf
UNITY_LICENSE_FILE=Unity_lic.ulf
```
You might want to take a look at how to implement this into your images 👍
Best
Alex
Contributor guide
Research direction
Start by reviewing the inline Node/Puppeteer script in index.js and the accompanying shell activation script, including the UNITY_* environment variables and Unity batch-mode commands. The issue does not define a specific repository change or acceptance criteria, so first establish how this approach should be integrated into the Docker images and what successful scripted activation must demonstrate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, javascript, node.js, shell, unity
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100