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

Commit

Permalink
@xrtk/unity-action@v4 (#6)
Browse files Browse the repository at this point in the history
* refactored action from composite to javascript
  • Loading branch information
StephenHodgson authored Nov 9, 2022
1 parent 1cd0aae commit 5a15e9c
Show file tree
Hide file tree
Showing 13 changed files with 4,860 additions and 130 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: validate

on:
push:
branches:
- 'main'
pull_request:
branches:
- '*'

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

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

jobs:
validate:
runs-on: ${{ matrix.os }}
strategy:
#max-parallel: 2 # Use this if you're activating pro license with matrix
matrix:
include:
- os: ubuntu-latest
build-target: StandaloneLinux64
- os: windows-latest
build-target: StandaloneWindows64
- os: macos-latest
build-target: StandaloneOSX

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

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

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

- uses: xrtk/activate-unity-license@v1
with:
username: ${{ secrets.UNITY_USERNAME }}
password: ${{ secrets.UNITY_PASSWORD }}
serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]

- name: xrtk/unity-action
uses: ./
with:
log-name: 'Test'
args: '-quit -batchmode -nographics'

- uses: actions/upload-artifact@v3
name: Upload Artifacts
if: always()
with:
name: '${{ runner.os }}-${{ matrix.build-target }}-Artifacts'
path: '${{ env.UNITY_PROJECT_PATH }}/Builds'

- name: Clean Artifacts
if: always()
run: |
# Clean Artifacts
$artifacts = "${{ env.UNITY_PROJECT_PATH }}/Builds"
if (Test-Path -Path $artifacts) {
Remove-Item $artifacts -Force -Recurse
}
shell: pwsh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
# Unity Action (XRTK)

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

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

> 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
> This action does not require the use of XRTK in your Unity project.
## Related Github Actions

* [xrtk/unity-setup](https://github.com/XRTK/unity-setup) Downloads and installs the unity editor.
* [xrtk/unity-action](https://github.com/XRTK/activate-unity-license) An cli tool for passing commands to the Unity Engine.
* [xrtk/unity-build](https://github.com/XRTK/unity-build) ***(Requires XRTK plugin in Unity Project)***

## How to use

```yaml
jobs:
activate:
steps:
- uses: xrtk/unity-validate@v2
build:
needs: activate
runs-on: windows-latest
runs-on: ${{ matrix.os }}
strategy:
#max-parallel: 2 # Use this if you're activating pro license with matrix
matrix:
build-target: [ StandaloneWindows64, WSAPlayer, Android, Lumin ]
max-parallel: 1
include:
- os: ubuntu-latest
build-target: StandaloneLinux64
- os: windows-latest
build-target: StandaloneWindows64
- os: macos-latest
build-target: StandaloneOSX

steps:
- uses: xrtk/unity-action@v3
- name: checkout self
uses: actions/checkout@v3

# 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@v4

# Activates the installation with the provided credentials
- uses: xrtk/activate-unity-license@v1
with:
# Required
username: ${{ secrets.UNITY_USERNAME }}
password: ${{ secrets.UNITY_PASSWORD }}
# Optional
license-type: 'Personal' # Chooses license type to use [ Personal, Professional ]
serial: ${{ secrets.UNITY_SERIAL }} # Required for pro/plus activations

- uses: xrtk/unity-action@v4
name: '${{ matrix.build-target }}-Tests'
with:
name: '${{ matrix.build-target }}-Tests'
Expand All @@ -31,7 +58,7 @@ jobs:
build-target: '${{ matrix.build-target }}'
args: '-batchmode -runEditorTests'

- uses: xrtk/unity-action@v3
- uses: xrtk/unity-action@v4
name: '${{ matrix.build-target }}-Build'
with:
name: '${{ matrix.build-target }}-Build'
Expand Down
125 changes: 6 additions & 119 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,131 +4,18 @@ branding:
icon: 'at-sign'
color: 'blue'
inputs:
editor-path:
description: 'Path to the Unity Editor'
required: true
project-path:
description: 'Path to the Unity project'
required: true
build-target:
description: 'Platform build target'
required: false
default: ''
args:
description: 'Unity cli arguments'
required: false
default: '-quit -batchmode'
name:
description: 'Name of the Unity Action'
default: '-quit -batchmode -nographics'
log-name:
description: 'Name of the Unity Log'
required: false
default: 'Unity'
runs:
using: "composite"
steps:
- name: '${{ inputs.name }}'
run: |
# Unity Action
$editorPath = "${{ inputs.editor-path }}"
$projectPath = "${{ inputs.project-path }}"
$buildTarget = "${{ inputs.build-target }}"
$additionalArgs = "${{ inputs.args }}".Trim()
$name = "${{ inputs.name }}"
$buildTargetArgs = ""
if ( -not [string]::IsNullOrEmpty($buildTarget) ) {
$buildTargetArgs = "-buildTarget `"$buildTarget`" "
}
$logDirectory = "$projectPath/Builds/Logs"
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"
$logName = "$logDirectory/$name-$date"
$logPath = "$logName.log"
if( $additionalArgs -like "*runEditorTests" ) {
$testPath = "$logName.xml"
$additionalArgs += " -editorTestsResultFile `"$testPath`""
}
$buildArgs = "$buildTargetArgs-projectPath `"$projectPath`" -logfile `"$logPath`" $additionalArgs"
Write-Host "::group::$editorPath $buildArgs"
$process = Start-Process -FilePath "$editorPath" -ArgumentList "$buildArgs" -PassThru
$ljob = Start-Job -ScriptBlock {
param($log)
while ( -not (Test-Path $log -Type Leaf) ) {
Start-Sleep -Milliseconds 1
}
Get-Content "$log" -Wait
} -ArgumentList $logPath
$processId = $process.Id
while ( -not $process.HasExited )
{
# While waiting, Get-Content checks the file once each second
Start-Sleep -Milliseconds 1
Receive-Job $ljob
if ( (Get-Process -Id $processId -ErrorAction SilentlyContinue) -eq $null )
{
Write-Host "Unity process has ended unexpectedly..."
break
}
}
Write-Host "Unity Process $processId Complete!"
# Wait for the last of the log information to be written
$fileLocked = $true
$timeout = New-TimeSpan -Seconds 10
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
do {
try
{
$file = Convert-Path $logPath
$fileStream = [System.IO.File]::Open($file,'Open','Write')
$fileStream.Close()
$fileStream.Dispose()
$fileLocked = $false
}
catch
{
$fileLocked = $true
}
if ( $stopwatch.elapsed -lt $timeout )
{
if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) {
Write-Host "Attempting to cleanup orphaned processes..."
$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 }
$procs | ForEach-Object { Stop-Process -Id $_.Id -ErrorAction SilentlyContinue }
}
}
Start-Sleep -Milliseconds 1
} while ( $fileLocked )
Write-Host "End of log stream"
Write-Host "Cleaning up jobs..."
# Clean up job
Receive-Job $ljob
Stop-Job $ljob
Remove-Job $ljob
Write-Host "::endgroup::"
exit $process.ExitCode
shell: pwsh
using: 'node16'
main: 'dist/index.js'
Loading

0 comments on commit 5a15e9c

Please sign in to comment.