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

Commit

Permalink
@xrtk/activate-unity-license@v3 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Nov 13, 2023
1 parent ca03736 commit 3fe7510
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 71 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ on:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
group: ${{ github.ref }}

env:
UNITY_PROJECT_PATH: ''

jobs:
validate:
runs-on: ${{ matrix.os }}
strategy:
#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 All @@ -30,17 +32,17 @@ jobs:

steps:
- name: checkout self
uses: actions/checkout@v3
uses: actions/checkout@v4

- run: npm install

- name: checkout test project
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: xrtk/com.xrtk.test
path: test-project

- uses: xrtk/unity-setup@v6
- uses: xrtk/unity-setup@v7.2
with:
version-file-path: 'test-project/**/ProjectSettings/ProjectVersion.txt'

Expand All @@ -52,10 +54,10 @@ jobs:
password: ${{ secrets.UNITY_PASSWORD }}
# Optional
serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
license-type: 'Professional' # Chooses license type to use [ Personal, Professional ]

- name: Unity Build (${{ matrix.build-target }})
uses: xrtk/unity-action@v4
uses: xrtk/unity-action@v6
with:
log-name: 'project-validation'
args: '-quit -nographics -batchmode -executeMethod XRTK.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ jobs:

steps:
- name: checkout self
uses: actions/checkout@v3
uses: actions/checkout@v4

# Installs the Unity Editor based on your project version text file
# sets -> env.UNITY_EDITOR_PATH
# sets -> env.UNITY_PROJECT_PATH
# https://github.com/XRTK/unity-setup
- uses: xrtk/unity-setup@v6
- uses: xrtk/unity-setup@v7.2

# Activates the installation with the provided credentials
- uses: xrtk/activate-unity-license@v2
- uses: xrtk/activate-unity-license@v3
with:
# Required
username: ${{ secrets.UNITY_USERNAME }}
Expand Down
5 changes: 1 addition & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34214,17 +34214,15 @@ async function Run() {
// Let's mask all of it.
var maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);

core.startGroup(`Activate Unity Professional License`);
var args = `-quit -nographics -batchmode -username ${username} -password ${password} -serial ${serial}`;
var args = `-quit -nographics -batchmode -serial ${serial} -username ${username} -password ${password}`;
var exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ProLicenseActivation`);
core.endGroup();
} else if (licenseType.toLowerCase().startsWith('per')) {
// if personal license activate by using requesting activation file
core.startGroup(`Generate Unity License Request File`);
var exitCode = 0;
var args = `-quit -nographics -batchmode -createManualActivationFile`;

try {
exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ManualLicenseRequest`);
} catch (error) {
Expand Down Expand Up @@ -54093,7 +54091,6 @@ var __webpack_exports__ = {};
const core = __nccwpck_require__(2186);
const activate = __nccwpck_require__(3816);
const deactivate = __nccwpck_require__(8162);

const IsPost = !!core.getState('isPost');

const main = async () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

51 changes: 25 additions & 26 deletions dist/unity-action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ param(
[String]$logName = "Unity"
)

try {
$buildArgs = ""
$buildArgs = ""
$process = $null

if ( -not [string]::IsNullOrEmpty($buildTarget) ) {
try {
if (-not [string]::IsNullOrEmpty($buildTarget)) {
$buildArgs += "-buildTarget `"$buildTarget`" "
}

Expand All @@ -27,12 +28,11 @@ try {

$logDirectory = "$projectPath/Builds/Logs"

if ( -not (Test-Path -Path $logDirectory)) {
if (-not (Test-Path -Path $logDirectory)) {
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
}

Write-Host "Log Directory: $logDirectory"

$date = Get-Date -Format "yyyyMMddTHHmmss"
$fullLogName = "$logDirectory/$logName-$date"
$logPath = "$fullLogName.log"
Expand All @@ -41,37 +41,34 @@ try {

$additionalArgs = $additionalArgs.Trim()

if ( $additionalArgs -like "*runEditorTests" ) {
if ($additionalArgs -like "*runEditorTests") {
$testPath = "$fullLogName.xml"
$additionalArgs += " -editorTestsResultFile `"$testPath`""
}

$buildArgs = $buildArgs.Trim()

$buildArgs += " $additionalArgs"

$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru

$ljob = Start-Job -ScriptBlock {
param($log)

while ( -not (Test-Path $log -Type Leaf) ) {
while (-not (Test-Path -Path $log -Type Leaf)) {
Start-Sleep -Milliseconds 1
}

Get-Content "$log" -Wait
Get-Content -Path $log -Wait | Write-Host
} -ArgumentList $logPath

$processId = $process.Id
Write-Output "::debug::Unity Process ID: $processId"
$processId | Out-File -FilePath "$env:GITHUB_WORKSPACE/unity-process-id.txt"

while ( -not $process.HasExited )
{
while (-not $process.HasExited) {
# While waiting, Get-Content checks the file once each second
Start-Sleep -Milliseconds 1
Receive-Job $ljob

if ( $null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue) )
{
if ($null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
break
}
}
Expand All @@ -82,8 +79,7 @@ try {
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

do {
try
{
try {
if (Test-Path -Path $logPath) {
$file = Convert-Path $logPath
$fileStream = [System.IO.File]::Open($file,'Open','Write')
Expand All @@ -93,15 +89,13 @@ try {
} else {
$fileLocked = $false
}
}
catch
{
} catch {
$fileLocked = $true
Start-Sleep -Milliseconds 1
}

if ( $stopwatch.elapsed -lt $timeout )
{
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
if ($stopwatch.elapsed -lt $timeout) {
if ((-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT")) {
$procsWithParent = Get-CimInstance -ClassName "win32_process" | Select-Object ProcessId,ParentProcessId
$orphaned = $procsWithParent | Where-Object -Property ParentProcessId -NotIn $procsWithParent.ProcessId
$procs = Get-Process -IncludeUserName | Where-Object -Property Id -In $orphaned.ProcessId | Where-Object { $_.UserName -match $env:username }
Expand All @@ -110,17 +104,22 @@ try {
}

Start-Sleep -Milliseconds 1
} while ( $fileLocked )
} while ($fileLocked)

Start-Sleep -Milliseconds 1

# Clean up job
Receive-Job $ljob
Stop-Job $ljob
Remove-Job $ljob

exit $process.ExitCode
}
catch {
$errorMessage = $_.Exception.Message
Write-Host "::error::An error occurred running unity-action.ps1: $errorMessage"

if ($process -and (-not $process.HasExited)) {
$process.Kill()
}

exit 1
}
4 changes: 1 addition & 3 deletions src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ async function Run() {
// Let's mask all of it.
var maskedSerial = serial.slice(0, -4) + `XXXX`;
core.setSecret(maskedSerial);

core.startGroup(`Activate Unity Professional License`);
var args = `-quit -nographics -batchmode -username ${username} -password ${password} -serial ${serial}`;
var args = `-quit -nographics -batchmode -serial ${serial} -username ${username} -password ${password}`;
var exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ProLicenseActivation`);
core.endGroup();
} else if (licenseType.toLowerCase().startsWith('per')) {
// if personal license activate by using requesting activation file
core.startGroup(`Generate Unity License Request File`);
var exitCode = 0;
var args = `-quit -nographics -batchmode -createManualActivationFile`;

try {
exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ManualLicenseRequest`);
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const core = require('@actions/core');
const activate = require('./activate');
const deactivate = require('./deactivate');

const IsPost = !!core.getState('isPost');

const main = async () => {
Expand Down
51 changes: 25 additions & 26 deletions src/unity-action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ param(
[String]$logName = "Unity"
)

try {
$buildArgs = ""
$buildArgs = ""
$process = $null

if ( -not [string]::IsNullOrEmpty($buildTarget) ) {
try {
if (-not [string]::IsNullOrEmpty($buildTarget)) {
$buildArgs += "-buildTarget `"$buildTarget`" "
}

Expand All @@ -27,12 +28,11 @@ try {

$logDirectory = "$projectPath/Builds/Logs"

if ( -not (Test-Path -Path $logDirectory)) {
if (-not (Test-Path -Path $logDirectory)) {
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
}

Write-Host "Log Directory: $logDirectory"

$date = Get-Date -Format "yyyyMMddTHHmmss"
$fullLogName = "$logDirectory/$logName-$date"
$logPath = "$fullLogName.log"
Expand All @@ -41,37 +41,34 @@ try {

$additionalArgs = $additionalArgs.Trim()

if ( $additionalArgs -like "*runEditorTests" ) {
if ($additionalArgs -like "*runEditorTests") {
$testPath = "$fullLogName.xml"
$additionalArgs += " -editorTestsResultFile `"$testPath`""
}

$buildArgs = $buildArgs.Trim()

$buildArgs += " $additionalArgs"

$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru

$ljob = Start-Job -ScriptBlock {
param($log)

while ( -not (Test-Path $log -Type Leaf) ) {
while (-not (Test-Path -Path $log -Type Leaf)) {
Start-Sleep -Milliseconds 1
}

Get-Content "$log" -Wait
Get-Content -Path $log -Wait | Write-Host
} -ArgumentList $logPath

$processId = $process.Id
Write-Output "::debug::Unity Process ID: $processId"
$processId | Out-File -FilePath "$env:GITHUB_WORKSPACE/unity-process-id.txt"

while ( -not $process.HasExited )
{
while (-not $process.HasExited) {
# While waiting, Get-Content checks the file once each second
Start-Sleep -Milliseconds 1
Receive-Job $ljob

if ( $null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue) )
{
if ($null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
break
}
}
Expand All @@ -82,8 +79,7 @@ try {
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

do {
try
{
try {
if (Test-Path -Path $logPath) {
$file = Convert-Path $logPath
$fileStream = [System.IO.File]::Open($file,'Open','Write')
Expand All @@ -93,15 +89,13 @@ try {
} else {
$fileLocked = $false
}
}
catch
{
} catch {
$fileLocked = $true
Start-Sleep -Milliseconds 1
}

if ( $stopwatch.elapsed -lt $timeout )
{
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
if ($stopwatch.elapsed -lt $timeout) {
if ((-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT")) {
$procsWithParent = Get-CimInstance -ClassName "win32_process" | Select-Object ProcessId,ParentProcessId
$orphaned = $procsWithParent | Where-Object -Property ParentProcessId -NotIn $procsWithParent.ProcessId
$procs = Get-Process -IncludeUserName | Where-Object -Property Id -In $orphaned.ProcessId | Where-Object { $_.UserName -match $env:username }
Expand All @@ -110,17 +104,22 @@ try {
}

Start-Sleep -Milliseconds 1
} while ( $fileLocked )
} while ($fileLocked)

Start-Sleep -Milliseconds 1

# Clean up job
Receive-Job $ljob
Stop-Job $ljob
Remove-Job $ljob

exit $process.ExitCode
}
catch {
$errorMessage = $_.Exception.Message
Write-Host "::error::An error occurred running unity-action.ps1: $errorMessage"

if ($process -and (-not $process.HasExited)) {
$process.Kill()
}

exit 1
}

0 comments on commit 3fe7510

Please sign in to comment.