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

Commit 5a15e9c

Browse files
@xrtk/unity-action@v4 (#6)
* refactored action from composite to javascript
1 parent 1cd0aae commit 5a15e9c

13 files changed

+4860
-130
lines changed

.github/workflows/validate.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: validate
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.ref }}
16+
17+
jobs:
18+
validate:
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
#max-parallel: 2 # Use this if you're activating pro license with matrix
22+
matrix:
23+
include:
24+
- os: ubuntu-latest
25+
build-target: StandaloneLinux64
26+
- os: windows-latest
27+
build-target: StandaloneWindows64
28+
- os: macos-latest
29+
build-target: StandaloneOSX
30+
31+
steps:
32+
- name: checkout self
33+
uses: actions/checkout@v3
34+
35+
- name: checkout test project
36+
uses: actions/checkout@v3
37+
with:
38+
repository: xrtk/com.xrtk.test
39+
path: test-project
40+
41+
- uses: xrtk/unity-setup@v4
42+
with:
43+
version-file-path: 'test-project/**/ProjectSettings/ProjectVersion.txt'
44+
45+
- uses: xrtk/activate-unity-license@v1
46+
with:
47+
username: ${{ secrets.UNITY_USERNAME }}
48+
password: ${{ secrets.UNITY_PASSWORD }}
49+
serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations
50+
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
51+
52+
- name: xrtk/unity-action
53+
uses: ./
54+
with:
55+
log-name: 'Test'
56+
args: '-quit -batchmode -nographics'
57+
58+
- uses: actions/upload-artifact@v3
59+
name: Upload Artifacts
60+
if: always()
61+
with:
62+
name: '${{ runner.os }}-${{ matrix.build-target }}-Artifacts'
63+
path: '${{ env.UNITY_PROJECT_PATH }}/Builds'
64+
65+
- name: Clean Artifacts
66+
if: always()
67+
run: |
68+
# Clean Artifacts
69+
$artifacts = "${{ env.UNITY_PROJECT_PATH }}/Builds"
70+
71+
if (Test-Path -Path $artifacts) {
72+
Remove-Item $artifacts -Force -Recurse
73+
}
74+
shell: pwsh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
11
# Unity Action (XRTK)
22

3-
An atomic GitHub Action that runs the Unity engine via cli with the provided parameters.
3+
An atomic GitHub Action that runs cli tool for passing commands to the Unity Engine.
44

55
Part of the [Mixed Reality Toolkit (XRTK)](https://github.com/XRTK) open source project.
66

7-
> This action does not have any dependency on the use of XRTK in your Unity project, unless you'd like to use the command line build `-executeMethod` arg
7+
> This action does not require the use of XRTK in your Unity project.
8+
9+
## Related Github Actions
10+
11+
* [xrtk/unity-setup](https://github.com/XRTK/unity-setup) Downloads and installs the unity editor.
12+
* [xrtk/unity-action](https://github.com/XRTK/activate-unity-license) An cli tool for passing commands to the Unity Engine.
13+
* [xrtk/unity-build](https://github.com/XRTK/unity-build) ***(Requires XRTK plugin in Unity Project)***
814

915
## How to use
1016

1117
```yaml
1218
jobs:
13-
activate:
14-
steps:
15-
- uses: xrtk/unity-validate@v2
1619
build:
17-
needs: activate
18-
runs-on: windows-latest
20+
runs-on: ${{ matrix.os }}
1921
strategy:
22+
#max-parallel: 2 # Use this if you're activating pro license with matrix
2023
matrix:
21-
build-target: [ StandaloneWindows64, WSAPlayer, Android, Lumin ]
22-
max-parallel: 1
24+
include:
25+
- os: ubuntu-latest
26+
build-target: StandaloneLinux64
27+
- os: windows-latest
28+
build-target: StandaloneWindows64
29+
- os: macos-latest
30+
build-target: StandaloneOSX
2331

2432
steps:
25-
- uses: xrtk/unity-action@v3
33+
- name: checkout self
34+
uses: actions/checkout@v3
35+
36+
# Installs the Unity Editor based on your project version text file
37+
# sets -> env.UNITY_EDITOR_PATH
38+
# sets -> env.UNITY_PROJECT_PATH
39+
# https://github.com/XRTK/unity-setup
40+
- uses: xrtk/unity-setup@v4
41+
42+
# Activates the installation with the provided credentials
43+
- uses: xrtk/activate-unity-license@v1
44+
with:
45+
# Required
46+
username: ${{ secrets.UNITY_USERNAME }}
47+
password: ${{ secrets.UNITY_PASSWORD }}
48+
# Optional
49+
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
50+
serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations
51+
52+
- uses: xrtk/unity-action@v4
2653
name: '${{ matrix.build-target }}-Tests'
2754
with:
2855
name: '${{ matrix.build-target }}-Tests'
@@ -31,7 +58,7 @@ jobs:
3158
build-target: '${{ matrix.build-target }}'
3259
args: '-batchmode -runEditorTests'
3360

34-
- uses: xrtk/unity-action@v3
61+
- uses: xrtk/unity-action@v4
3562
name: '${{ matrix.build-target }}-Build'
3663
with:
3764
name: '${{ matrix.build-target }}-Build'

action.yml

Lines changed: 6 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -4,131 +4,18 @@ branding:
44
icon: 'at-sign'
55
color: 'blue'
66
inputs:
7-
editor-path:
8-
description: 'Path to the Unity Editor'
9-
required: true
10-
project-path:
11-
description: 'Path to the Unity project'
12-
required: true
137
build-target:
148
description: 'Platform build target'
159
required: false
10+
default: ''
1611
args:
1712
description: 'Unity cli arguments'
1813
required: false
19-
default: '-quit -batchmode'
20-
name:
21-
description: 'Name of the Unity Action'
14+
default: '-quit -batchmode -nographics'
15+
log-name:
16+
description: 'Name of the Unity Log'
2217
required: false
2318
default: 'Unity'
2419
runs:
25-
using: "composite"
26-
steps:
27-
- name: '${{ inputs.name }}'
28-
run: |
29-
# Unity Action
30-
$editorPath = "${{ inputs.editor-path }}"
31-
$projectPath = "${{ inputs.project-path }}"
32-
$buildTarget = "${{ inputs.build-target }}"
33-
$additionalArgs = "${{ inputs.args }}".Trim()
34-
$name = "${{ inputs.name }}"
35-
$buildTargetArgs = ""
36-
37-
if ( -not [string]::IsNullOrEmpty($buildTarget) ) {
38-
$buildTargetArgs = "-buildTarget `"$buildTarget`" "
39-
}
40-
41-
$logDirectory = "$projectPath/Builds/Logs"
42-
43-
if ( -not (Test-Path -Path $logDirectory)) {
44-
$logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object
45-
}
46-
47-
Write-Host "Log Directory: $logDirectory"
48-
49-
$date = Get-Date -Format "yyyyMMddTHHmmss"
50-
$logName = "$logDirectory/$name-$date"
51-
$logPath = "$logName.log"
52-
53-
if( $additionalArgs -like "*runEditorTests" ) {
54-
$testPath = "$logName.xml"
55-
$additionalArgs += " -editorTestsResultFile `"$testPath`""
56-
}
57-
58-
$buildArgs = "$buildTargetArgs-projectPath `"$projectPath`" -logfile `"$logPath`" $additionalArgs"
59-
Write-Host "::group::$editorPath $buildArgs"
60-
61-
$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru
62-
63-
$ljob = Start-Job -ScriptBlock {
64-
param($log)
65-
66-
while ( -not (Test-Path $log -Type Leaf) ) {
67-
Start-Sleep -Milliseconds 1
68-
}
69-
70-
Get-Content "$log" -Wait
71-
} -ArgumentList $logPath
72-
73-
$processId = $process.Id
74-
75-
while ( -not $process.HasExited )
76-
{
77-
# While waiting, Get-Content checks the file once each second
78-
Start-Sleep -Milliseconds 1
79-
Receive-Job $ljob
80-
81-
if ( (Get-Process -Id $processId -ErrorAction SilentlyContinue) -eq $null )
82-
{
83-
Write-Host "Unity process has ended unexpectedly..."
84-
break
85-
}
86-
}
87-
88-
Write-Host "Unity Process $processId Complete!"
89-
90-
# Wait for the last of the log information to be written
91-
$fileLocked = $true
92-
$timeout = New-TimeSpan -Seconds 10
93-
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
94-
95-
do {
96-
try
97-
{
98-
$file = Convert-Path $logPath
99-
$fileStream = [System.IO.File]::Open($file,'Open','Write')
100-
$fileStream.Close()
101-
$fileStream.Dispose()
102-
$fileLocked = $false
103-
}
104-
catch
105-
{
106-
$fileLocked = $true
107-
}
108-
109-
if ( $stopwatch.elapsed -lt $timeout )
110-
{
111-
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
112-
Write-Host "Attempting to cleanup orphaned processes..."
113-
$procsWithParent = Get-CimInstance -ClassName "win32_process" | Select-Object ProcessId,ParentProcessId
114-
$orphaned = $procsWithParent | Where-Object -Property ParentProcessId -NotIn $procsWithParent.ProcessId
115-
$procs = Get-Process -IncludeUserName | Where-Object -Property Id -In $orphaned.ProcessId | Where-Object { $_.UserName -match $env:username }
116-
$procs | ForEach-Object { Stop-Process -Id $_.Id -ErrorAction SilentlyContinue }
117-
}
118-
}
119-
120-
Start-Sleep -Milliseconds 1
121-
} while ( $fileLocked )
122-
123-
Write-Host "End of log stream"
124-
Write-Host "Cleaning up jobs..."
125-
126-
# Clean up job
127-
Receive-Job $ljob
128-
Stop-Job $ljob
129-
Remove-Job $ljob
130-
131-
Write-Host "::endgroup::"
132-
133-
exit $process.ExitCode
134-
shell: pwsh
20+
using: 'node16'
21+
main: 'dist/index.js'

0 commit comments

Comments
 (0)