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

Commit 3fe7510

Browse files
@xrtk/activate-unity-license@v3 (#8)
1 parent ca03736 commit 3fe7510

File tree

8 files changed

+65
-71
lines changed

8 files changed

+65
-71
lines changed

.github/workflows/validate.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ on:
1010

1111
# Allows you to run this workflow manually from the Actions tab
1212
workflow_dispatch:
13-
1413
concurrency:
1514
group: ${{ github.ref }}
1615

16+
env:
17+
UNITY_PROJECT_PATH: ''
18+
1719
jobs:
1820
validate:
1921
runs-on: ${{ matrix.os }}
2022
strategy:
21-
#max-parallel: 2 # Use this if you're activating pro license with matrix
23+
max-parallel: 2 # Use this if you're activating pro license with matrix
2224
matrix:
2325
include:
2426
- os: ubuntu-latest
@@ -30,17 +32,17 @@ jobs:
3032

3133
steps:
3234
- name: checkout self
33-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3436

3537
- run: npm install
3638

3739
- name: checkout test project
38-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
3941
with:
4042
repository: xrtk/com.xrtk.test
4143
path: test-project
4244

43-
- uses: xrtk/unity-setup@v6
45+
- uses: xrtk/unity-setup@v7.2
4446
with:
4547
version-file-path: 'test-project/**/ProjectSettings/ProjectVersion.txt'
4648

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

5759
- name: Unity Build (${{ matrix.build-target }})
58-
uses: xrtk/unity-action@v4
60+
uses: xrtk/unity-action@v6
5961
with:
6062
log-name: 'project-validation'
6163
args: '-quit -nographics -batchmode -executeMethod XRTK.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject'

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ jobs:
5252

5353
steps:
5454
- name: checkout self
55-
uses: actions/checkout@v3
55+
uses: actions/checkout@v4
5656

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

6363
# Activates the installation with the provided credentials
64-
- uses: xrtk/activate-unity-license@v2
64+
- uses: xrtk/activate-unity-license@v3
6565
with:
6666
# Required
6767
username: ${{ secrets.UNITY_USERNAME }}

dist/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34214,17 +34214,15 @@ async function Run() {
3421434214
// Let's mask all of it.
3421534215
var maskedSerial = serial.slice(0, -4) + `XXXX`;
3421634216
core.setSecret(maskedSerial);
34217-
3421834217
core.startGroup(`Activate Unity Professional License`);
34219-
var args = `-quit -nographics -batchmode -username ${username} -password ${password} -serial ${serial}`;
34218+
var args = `-quit -nographics -batchmode -serial ${serial} -username ${username} -password ${password}`;
3422034219
var exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ProLicenseActivation`);
3422134220
core.endGroup();
3422234221
} else if (licenseType.toLowerCase().startsWith('per')) {
3422334222
// if personal license activate by using requesting activation file
3422434223
core.startGroup(`Generate Unity License Request File`);
3422534224
var exitCode = 0;
3422634225
var args = `-quit -nographics -batchmode -createManualActivationFile`;
34227-
3422834226
try {
3422934227
exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ManualLicenseRequest`);
3423034228
} catch (error) {
@@ -54093,7 +54091,6 @@ var __webpack_exports__ = {};
5409354091
const core = __nccwpck_require__(2186);
5409454092
const activate = __nccwpck_require__(3816);
5409554093
const deactivate = __nccwpck_require__(8162);
54096-
5409754094
const IsPost = !!core.getState('isPost');
5409854095

5409954096
const main = async () => {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/unity-action.ps1

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ param(
77
[String]$logName = "Unity"
88
)
99

10-
try {
11-
$buildArgs = ""
10+
$buildArgs = ""
11+
$process = $null
1212

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

@@ -27,12 +28,11 @@ try {
2728

2829
$logDirectory = "$projectPath/Builds/Logs"
2930

30-
if ( -not (Test-Path -Path $logDirectory)) {
31+
if (-not (Test-Path -Path $logDirectory)) {
3132
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
3233
}
3334

3435
Write-Host "Log Directory: $logDirectory"
35-
3636
$date = Get-Date -Format "yyyyMMddTHHmmss"
3737
$fullLogName = "$logDirectory/$logName-$date"
3838
$logPath = "$fullLogName.log"
@@ -41,37 +41,34 @@ try {
4141

4242
$additionalArgs = $additionalArgs.Trim()
4343

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

4949
$buildArgs = $buildArgs.Trim()
50-
5150
$buildArgs += " $additionalArgs"
52-
5351
$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru
54-
5552
$ljob = Start-Job -ScriptBlock {
5653
param($log)
5754

58-
while ( -not (Test-Path $log -Type Leaf) ) {
55+
while (-not (Test-Path -Path $log -Type Leaf)) {
5956
Start-Sleep -Milliseconds 1
6057
}
6158

62-
Get-Content "$log" -Wait
59+
Get-Content -Path $log -Wait | Write-Host
6360
} -ArgumentList $logPath
6461

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

67-
while ( -not $process.HasExited )
68-
{
66+
while (-not $process.HasExited) {
6967
# While waiting, Get-Content checks the file once each second
7068
Start-Sleep -Milliseconds 1
7169
Receive-Job $ljob
7270

73-
if ( $null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue) )
74-
{
71+
if ($null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
7572
break
7673
}
7774
}
@@ -82,8 +79,7 @@ try {
8279
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
8380

8481
do {
85-
try
86-
{
82+
try {
8783
if (Test-Path -Path $logPath) {
8884
$file = Convert-Path $logPath
8985
$fileStream = [System.IO.File]::Open($file,'Open','Write')
@@ -93,15 +89,13 @@ try {
9389
} else {
9490
$fileLocked = $false
9591
}
96-
}
97-
catch
98-
{
92+
} catch {
9993
$fileLocked = $true
94+
Start-Sleep -Milliseconds 1
10095
}
10196

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

112106
Start-Sleep -Milliseconds 1
113-
} while ( $fileLocked )
107+
} while ($fileLocked)
114108

115109
Start-Sleep -Milliseconds 1
116-
117110
# Clean up job
118111
Receive-Job $ljob
119112
Stop-Job $ljob
120113
Remove-Job $ljob
121-
122114
exit $process.ExitCode
123115
}
124116
catch {
117+
$errorMessage = $_.Exception.Message
118+
Write-Host "::error::An error occurred running unity-action.ps1: $errorMessage"
119+
120+
if ($process -and (-not $process.HasExited)) {
121+
$process.Kill()
122+
}
123+
125124
exit 1
126125
}

src/activate.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@ async function Run() {
4848
// Let's mask all of it.
4949
var maskedSerial = serial.slice(0, -4) + `XXXX`;
5050
core.setSecret(maskedSerial);
51-
5251
core.startGroup(`Activate Unity Professional License`);
53-
var args = `-quit -nographics -batchmode -username ${username} -password ${password} -serial ${serial}`;
52+
var args = `-quit -nographics -batchmode -serial ${serial} -username ${username} -password ${password}`;
5453
var exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ProLicenseActivation`);
5554
core.endGroup();
5655
} else if (licenseType.toLowerCase().startsWith('per')) {
5756
// if personal license activate by using requesting activation file
5857
core.startGroup(`Generate Unity License Request File`);
5958
var exitCode = 0;
6059
var args = `-quit -nographics -batchmode -createManualActivationFile`;
61-
6260
try {
6361
exitCode = await exec.exec(`"${pwsh}" -Command`, `${unity_action} -editorPath "${editorPath}" -projectPath "${projectPath}" -additionalArgs "${args}" -logName ManualLicenseRequest`);
6462
} catch (error) {

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const core = require('@actions/core');
22
const activate = require('./activate');
33
const deactivate = require('./deactivate');
4-
54
const IsPost = !!core.getState('isPost');
65

76
const main = async () => {

src/unity-action.ps1

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ param(
77
[String]$logName = "Unity"
88
)
99

10-
try {
11-
$buildArgs = ""
10+
$buildArgs = ""
11+
$process = $null
1212

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

@@ -27,12 +28,11 @@ try {
2728

2829
$logDirectory = "$projectPath/Builds/Logs"
2930

30-
if ( -not (Test-Path -Path $logDirectory)) {
31+
if (-not (Test-Path -Path $logDirectory)) {
3132
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
3233
}
3334

3435
Write-Host "Log Directory: $logDirectory"
35-
3636
$date = Get-Date -Format "yyyyMMddTHHmmss"
3737
$fullLogName = "$logDirectory/$logName-$date"
3838
$logPath = "$fullLogName.log"
@@ -41,37 +41,34 @@ try {
4141

4242
$additionalArgs = $additionalArgs.Trim()
4343

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

4949
$buildArgs = $buildArgs.Trim()
50-
5150
$buildArgs += " $additionalArgs"
52-
5351
$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru
54-
5552
$ljob = Start-Job -ScriptBlock {
5653
param($log)
5754

58-
while ( -not (Test-Path $log -Type Leaf) ) {
55+
while (-not (Test-Path -Path $log -Type Leaf)) {
5956
Start-Sleep -Milliseconds 1
6057
}
6158

62-
Get-Content "$log" -Wait
59+
Get-Content -Path $log -Wait | Write-Host
6360
} -ArgumentList $logPath
6461

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

67-
while ( -not $process.HasExited )
68-
{
66+
while (-not $process.HasExited) {
6967
# While waiting, Get-Content checks the file once each second
7068
Start-Sleep -Milliseconds 1
7169
Receive-Job $ljob
7270

73-
if ( $null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue) )
74-
{
71+
if ($null -eq (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
7572
break
7673
}
7774
}
@@ -82,8 +79,7 @@ try {
8279
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
8380

8481
do {
85-
try
86-
{
82+
try {
8783
if (Test-Path -Path $logPath) {
8884
$file = Convert-Path $logPath
8985
$fileStream = [System.IO.File]::Open($file,'Open','Write')
@@ -93,15 +89,13 @@ try {
9389
} else {
9490
$fileLocked = $false
9591
}
96-
}
97-
catch
98-
{
92+
} catch {
9993
$fileLocked = $true
94+
Start-Sleep -Milliseconds 1
10095
}
10196

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

112106
Start-Sleep -Milliseconds 1
113-
} while ( $fileLocked )
107+
} while ($fileLocked)
114108

115109
Start-Sleep -Milliseconds 1
116-
117110
# Clean up job
118111
Receive-Job $ljob
119112
Stop-Job $ljob
120113
Remove-Job $ljob
121-
122114
exit $process.ExitCode
123115
}
124116
catch {
117+
$errorMessage = $_.Exception.Message
118+
Write-Host "::error::An error occurred running unity-action.ps1: $errorMessage"
119+
120+
if ($process -and (-not $process.HasExited)) {
121+
$process.Kill()
122+
}
123+
125124
exit 1
126125
}

0 commit comments

Comments
 (0)