Skip to content

Commit df36e25

Browse files
unity-action@v2.0.0 (#10)
- removed pwsh unity exec implementation for a pure typescript one - 30% increase in performance from old v1 pwsh implementation
1 parent 167a24f commit df36e25

17 files changed

+939
-375
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.sh text eol=lf
2+
text=auto

.github/workflows/build-options.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"os": [
3+
"ubuntu-latest",
4+
"windows-latest",
5+
"macos-latest"
6+
],
7+
"unity-version": [
8+
"2022.3.x",
9+
"6000.0.x",
10+
"6000.1.x"
11+
],
12+
"include": [
13+
{
14+
"os": "ubuntu-latest",
15+
"build-target": "StandaloneLinux64"
16+
},
17+
{
18+
"os": "windows-latest",
19+
"build-target": "StandaloneWindows64"
20+
},
21+
{
22+
"os": "macos-latest",
23+
"build-target": "StandaloneOSX"
24+
}
25+
]
26+
}

.github/workflows/build.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: build
2+
permissions:
3+
contents: read
4+
on:
5+
workflow_call:
6+
inputs:
7+
matrix:
8+
required: true
9+
type: string
10+
secrets:
11+
UNITY_USERNAME:
12+
required: true
13+
UNITY_PASSWORD:
14+
required: true
15+
jobs:
16+
build:
17+
name: ${{ matrix.name }}
18+
strategy:
19+
matrix: ${{ fromJSON(inputs.matrix) }}
20+
fail-fast: false
21+
runs-on: ${{ matrix.os }}
22+
permissions:
23+
contents: read
24+
env:
25+
UNITY_PROJECT_PATH: ${{ github.workspace }}/Test Project
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: buildalon/unity-setup@v1
29+
with:
30+
version-file: None
31+
build-targets: ${{ matrix.build-target }}
32+
unity-version: ${{ matrix.unity-version }}
33+
- name: Get Unity Template
34+
id: template
35+
shell: bash
36+
run: ./.github/workflows/scripts/get-unity-template.sh 'com.unity.template.3d(-cross-platform)?'
37+
- uses: buildalon/activate-unity-license@v1
38+
with:
39+
license: Personal
40+
username: ${{ secrets.UNITY_USERNAME }}
41+
password: ${{ secrets.UNITY_PASSWORD }}
42+
- uses: ./ # buildalon/unity-actions
43+
name: Create Test Project
44+
with:
45+
log-name: create-test-project
46+
args: '-quit -nographics -batchmode -createProject "${{ env.UNITY_PROJECT_PATH }}" -cloneFromTemplate "${{ steps.template.outputs.TEMPLATE_PATH }}"'
47+
- name: Add Build Pipeline Package
48+
run: |
49+
npm install -g openupm-cli
50+
openupm add com.virtualmaker.buildalon
51+
working-directory: ${{ env.UNITY_PROJECT_PATH }}
52+
shell: bash
53+
- uses: ./ # buildalon/unity-actions
54+
name: ${{ matrix.build-target }}-Validate
55+
with:
56+
build-target: ${{ matrix.build-target }}
57+
project-path: ${{ env.UNITY_PROJECT_PATH }}
58+
log-name: ${{ matrix.build-target }}-Validate
59+
args: '-quit -nographics -batchmode -executeMethod Buildalon.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject -importTMProEssentialsAsset'
60+
- uses: ./ # buildalon/unity-action
61+
name: ${{ matrix.build-target }}-Build
62+
with:
63+
build-target: ${{ matrix.build-target }}
64+
project-path: ${{ env.UNITY_PROJECT_PATH }}
65+
log-name: ${{ matrix.build-target }}-Build
66+
args: '-quit -nographics -batchmode -executeMethod Buildalon.Editor.BuildPipeline.UnityPlayerBuildTools.StartCommandLineBuild -sceneList Assets/Scenes/SampleScene.unity'
67+
- uses: actions/upload-artifact@v4
68+
name: Upload Artifacts
69+
if: always()
70+
with:
71+
name: ${{ github.run_number }}.${{ github.run_attempt }} ${{ matrix.unity-version }} ${{ matrix.name }} Artifacts
72+
path: |
73+
${{ github.workspace }}/**/*.log
74+
${{ github.workspace }}/**/Builds/${{ matrix.build-target }}/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# This script is used to fetch the Unity template from the editor path in env variables.
3+
set -e
4+
5+
if [ -z "$UNITY_EDITOR_PATH" ]; then
6+
echo "UNITY_EDITOR_PATH is not set. Please set it to the path of your Unity editor."
7+
exit 1
8+
fi
9+
10+
PACKAGE="$1"
11+
12+
if [ -z "$PACKAGE" ]; then
13+
echo "Usage: $0 <package-name-or-regex>"
14+
echo "Example: $0 'com.unity.template.3d'"
15+
echo " $0 'com.unity.template.3d-cross-platform'"
16+
echo " $0 'com.unity.template.3d*' (regex supported)"
17+
echo " $0 'com.unity.template.3d(-cross-platform)?' (regex supported)"
18+
exit 1
19+
fi
20+
21+
EDITOR_ROOT=$(dirname "${UNITY_EDITOR_PATH}")
22+
EDITOR_ROOT=${EDITOR_ROOT//\\//\/}
23+
TEMPLATE_DIR="${EDITOR_ROOT}/Data/Resources/PackageManager/ProjectTemplates"
24+
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
25+
26+
if [[ "${OS_NAME}" == "darwin" ]]; then
27+
TEMPLATE_DIR=$(dirname "${EDITOR_ROOT}")/Resources/PackageManager/ProjectTemplates
28+
fi
29+
30+
if [ ! -d "${TEMPLATE_DIR}" ]; then
31+
echo "Template directory not found: ${TEMPLATE_DIR}"
32+
exit 1
33+
fi
34+
35+
PACKAGES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null)
36+
37+
if [ -z "${PACKAGES}" ]; then
38+
echo "No templates found in ${TEMPLATE_DIR}"
39+
else
40+
echo "Available templates:"
41+
echo "${PACKAGES}" | while IFS= read -r pkg; do
42+
echo " - $(basename \""${pkg}"\")"
43+
done
44+
fi
45+
46+
MATCHES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null | grep -E "${PACKAGE}.*[0-9]+\.[0-9]+\.[0-9]+\.tgz")
47+
TEMPLATE_PATH=$(echo "${MATCHES}" | awk '{ print length, $0 }' | sort -nr | cut -d" " -f2- | head -n 1)
48+
49+
if [ -z "${TEMPLATE_PATH}" ]; then
50+
echo "${PACKAGE} path not found in ${TEMPLATE_DIR}!"
51+
exit 1
52+
fi
53+
54+
TEMPLATE_PATH=${TEMPLATE_PATH//\\//\/}
55+
56+
echo "TEMPLATE_PATH=${TEMPLATE_PATH}"
57+
echo "TEMPLATE_PATH=${TEMPLATE_PATH}" >> "${GITHUB_OUTPUT}"

.github/workflows/validate.yml

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,39 @@
11
name: validate
22
on:
3-
schedule:
4-
- cron: '0 0 * * 0' # Every Sunday at midnight
53
push:
64
branches: ['main']
75
pull_request:
86
branches: ['*']
9-
# Allows you to run this workflow manually from the Actions tab
107
workflow_dispatch:
118
concurrency:
129
group: ${{ github.workflow }}-${{ github.ref }}
1310
cancel-in-progress: true
1411
jobs:
15-
build:
16-
timeout-minutes: 60
17-
env:
18-
TEMPLATE_PATH: ''
19-
UNITY_EDITOR_PATH: '' # set from unity-setup step
20-
UNITY_PROJECT_PATH: '' # set from unity-setup step
21-
runs-on: ${{ matrix.os }}
22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
os: [ubuntu-latest, windows-latest, macos-latest]
26-
unity-version: [2022.3.x, 6000.0.x, 6000.1.x]
27-
include: # for each os specify the build targets
28-
- os: ubuntu-latest
29-
build-target: StandaloneLinux64
30-
- os: windows-latest
31-
build-target: StandaloneWindows64
32-
- os: macos-latest
33-
build-target: StandaloneOSX
12+
setup:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
3416
steps:
3517
- uses: actions/checkout@v4
36-
- run: 'npm install -g openupm-cli'
37-
# Installs the Unity Editor based on your project version text file
38-
# sets -> env.UNITY_EDITOR_PATH
39-
# sets -> env.UNITY_PROJECT_PATH
40-
- uses: buildalon/unity-setup@v1
41-
with:
42-
version-file: 'None'
43-
build-targets: ${{ matrix.build-target }}
44-
unity-version: ${{ matrix.unity-version }}
45-
- name: Find Unity Template Path
46-
run: |
47-
$rootPath = $env:UNITY_EDITOR_PATH -replace "Editor.*", ""
48-
Write-Host "ROOT_PATH=$rootPath"
49-
$templatePath = Get-ChildItem -Recurse -Filter "com.unity.template.3d*.tgz" -Path $rootPath | Select-Object -First 1 | Select-Object -ExpandProperty FullName
50-
Write-Host "TEMPLATE_PATH=$templatePath"
51-
echo "TEMPLATE_PATH=$templatePath" >> $env:GITHUB_ENV
52-
shell: pwsh
53-
# Activates the installation with the provided credentials
54-
- uses: buildalon/activate-unity-license@v1
55-
with:
56-
license: 'Personal'
57-
username: ${{ secrets.UNITY_USERNAME }}
58-
password: ${{ secrets.UNITY_PASSWORD }}
59-
- uses: ./ # buildalon/unity-action
60-
name: Create Test Project
6118
with:
62-
log-name: 'create-test-project'
63-
args: '-quit -nographics -batchmode -createProject "${{ github.workspace }}/Test Project" -cloneFromTemplate "${{ env.TEMPLATE_PATH }}"'
64-
- run: 'openupm add com.utilities.buildpipeline'
65-
name: Add Build Pipeline Package
66-
working-directory: ${{ github.workspace }}/Test Project
67-
- uses: ./ # buildalon/unity-action
68-
name: '${{ matrix.build-target }}-Build'
19+
sparse-checkout: .github/
20+
- uses: RageAgainstThePixel/job-builder@v1
21+
id: setup-jobs
6922
with:
70-
project-path: ${{ github.workspace }}/Test Project
71-
log-name: '${{ matrix.build-target }}-Build'
72-
build-target: '${{ matrix.build-target }}'
73-
args: '-quit -nographics -batchmode -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.StartCommandLineBuild -sceneList Assets/Scenes/SampleScene.unity'
74-
- uses: actions/upload-artifact@v4
75-
name: Upload Artifacts
76-
if: always()
77-
with:
78-
name: '${{ github.run_number }}.${{ github.run_attempt }}-${{ runner.os }}-${{ matrix.build-target }}-${{ matrix.unity-version }}-Artifacts'
79-
path: |
80-
${{ github.workspace }}/**/*.log
81-
${{ github.workspace }}/**/Builds/${{ matrix.build-target }}/
23+
build-options: ./.github/workflows/build-options.json
24+
group-by: 'unity-version'
25+
outputs:
26+
jobs: ${{ steps.setup-jobs.outputs.jobs }}
27+
validate:
28+
if: ${{ needs.setup.outputs.jobs }}
29+
needs: setup
30+
name: build ${{ matrix.jobs.name }}
31+
permissions:
32+
contents: read
33+
strategy:
34+
matrix: ${{ fromJSON(needs.setup.outputs.jobs) }}
35+
fail-fast: false
36+
secrets: inherit
37+
uses: ./.github/workflows/build.yml
38+
with:
39+
matrix: ${{ toJSON(matrix.jobs.matrix) }}

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,3 @@ jobs:
4242
| `build-target` | The build target to use when executing arguments. | false | |
4343
| `args` | The [arguments](https://docs.unity3d.com/Manual/EditorCommandLineArguments.html) to use when executing commands to the editor. | true | `-quit -batchmode -nographics` |
4444
| `log-name` | The name of the log file to create when running the commands. | false | `Unity-yyyyMMddTHHmmss` |
45-
46-
### Stats
47-
48-
![Alt](https://repobeats.axiom.co/api/embed/5ad3fcf233ce7e81c71f645c5da45ab0f2fa7ac8.svg "Repobeats analytics image")

0 commit comments

Comments
 (0)