Skip to content

Commit 1176d3c

Browse files
authored
Merge pull request #237 from Nonanti/unity-integration
Unity Engine Integration - Fixes #231
2 parents adbc9a6 + 840f672 commit 1176d3c

File tree

62 files changed

+5998
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5998
-355
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
name: BitMono.Build
2+
on:
3+
create:
4+
tags:
5+
- "*"
6+
push:
7+
branches: [ main ]
8+
paths:
9+
- '.github/workflows/BitMono.Build.yaml'
10+
- 'props/SharedPackages.props'
11+
- 'props/SharedProjectProps.props'
12+
- 'props/SharedTestProps.props'
13+
- 'src/**'
14+
- 'test/**'
15+
pull_request:
16+
paths:
17+
- '.github/workflows/BitMono.Build.yaml'
18+
- 'props/SharedPackages.props'
19+
- 'props/SharedProjectProps.props'
20+
- 'props/SharedTestProps.props'
21+
- 'src/**'
22+
- 'test/**'
23+
24+
jobs:
25+
Build:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
target-framework: [net9.0, net8.0, net7.0, net6.0, net462, netstandard2.1, netstandard2.0]
30+
runtime: [linux-x64, win-x64, linux-arm64, win-arm64, osx-x64, osx-arm64, win-x86]
31+
exclude:
32+
# Exclude win-x86 builds for .NET Standard as they're architecture-independent
33+
- runtime: win-x86
34+
target-framework: netstandard2.0
35+
- runtime: win-x86
36+
target-framework: netstandard2.1
37+
outputs:
38+
version: ${{ steps.project-build.outputs.version }}
39+
is_prerelease: ${{ steps.project-build.outputs.is_prerelease }}
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v5
43+
with:
44+
fetch-depth: 0
45+
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v5
48+
env:
49+
# Disable the .NET logo in the console output.
50+
DOTNET_NOLOGO: true
51+
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
52+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
53+
# Disable sending .NET CLI telemetry to Microsoft.
54+
DOTNET_CLI_TELEMETRY_OPTOUT: true
55+
DOTNET_INSTALL_DIR: ${{ github.workspace }}/.dotnet
56+
with:
57+
dotnet-version: 9.x
58+
59+
- name: Build Project
60+
uses: ./.github/actions/project-build
61+
id: project-build
62+
with:
63+
project_path: src/BitMono.CLI/BitMono.CLI.csproj
64+
nuget_push: false
65+
target_framework: ${{ matrix.target-framework }}
66+
runtime_version: ${{ matrix.runtime }}
67+
github_token: ${{ secrets.PAT }}
68+
69+
- name: Install zip (for Linux/macOS)
70+
run: |
71+
if [[ "${{ matrix.runtime }}" =~ ^linux ]]; then
72+
sudo apt-get install -y zip
73+
elif [[ "${{ matrix.runtime }}" =~ ^osx ]]; then
74+
if ! command -v zip &> /dev/null; then
75+
echo "zip is not available on this macOS runner, and it should be pre-installed."
76+
exit 1
77+
fi
78+
fi
79+
80+
- name: Zip artifacts
81+
run: |
82+
cd ./src/BitMono.CLI/bin/Release/${{ matrix.target-framework }}/${{ matrix.runtime }} && \
83+
zip -qq -r ./BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }}.zip *
84+
85+
- name: Upload build
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }}
89+
path: "./src/BitMono.CLI/bin/Release/${{ matrix.target-framework }}/${{ matrix.runtime }}/BitMono-v${{ steps.project-build.outputs.version }}-CLI-${{ matrix.target-framework }}-${{ matrix.runtime }}.zip"
90+
if-no-files-found: error
91+
92+
UnityPackage:
93+
needs: Build
94+
runs-on: windows-latest
95+
strategy:
96+
matrix:
97+
unity-version: [
98+
2019.4.40f1,
99+
2020.3.48f1,
100+
2021.3.45f1,
101+
2022.3.50f1,
102+
6.0.0f1,
103+
6.1.0f1,
104+
6.2.0f1
105+
]
106+
steps:
107+
- name: Checkout code
108+
uses: actions/checkout@v5
109+
with:
110+
fetch-depth: 0
111+
112+
- name: Setup .NET
113+
uses: actions/setup-dotnet@v5
114+
env:
115+
DOTNET_NOLOGO: true
116+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
117+
DOTNET_CLI_TELEMETRY_OPTOUT: true
118+
with:
119+
dotnet-version: 9.x
120+
121+
- name: Build BitMono.CLI for Unity Package
122+
uses: ./.github/actions/project-build
123+
id: cli-build
124+
with:
125+
project_path: src/BitMono.CLI/BitMono.CLI.csproj
126+
nuget_push: false
127+
target_framework: net462
128+
runtime_version: win-x64
129+
github_token: ${{ secrets.PAT }}
130+
131+
- name: Copy Unity files to test project
132+
run: |
133+
# Sync your source files to the Unity test project
134+
xcopy "src\BitMono.Unity\*" "test\BitMono.Unity.TestProject\Assets\BitMono.Unity\" /E /I /Y
135+
# Copy the built CLI to the test project
136+
xcopy "src\BitMono.CLI\bin\Release\net462\win-x64\*" "test\BitMono.Unity.TestProject\Assets\BitMono.Unity\BitMono.CLI\" /E /I /Y
137+
138+
- name: Setup Unity for Package Export
139+
uses: game-ci/unity-builder@v4
140+
env:
141+
PACKAGE_VERSION: ${{ needs.Build.outputs.version }}
142+
UNITY_VERSION: ${{ matrix.unity-version }}
143+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
144+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
145+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
146+
with:
147+
unityVersion: ${{ matrix.unity-version }}
148+
targetPlatform: StandaloneWindows64
149+
buildMethod: BitMono.Editor.PackageExporter.ExportPackage
150+
projectPath: test/BitMono.Unity.TestProject
151+
buildName: BitMono-Unity-Package
152+
allowDirtyBuild: true
153+
154+
- name: Verify .unitypackage was created
155+
run: |
156+
if (Test-Path "BitMono-Unity-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}.unitypackage") {
157+
Write-Host "Unity package created successfully"
158+
Get-ChildItem "BitMono-Unity-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}.unitypackage" | ForEach-Object { Write-Host "File size: $([math]::Round($_.Length / 1MB, 2)) MB" }
159+
} else {
160+
Write-Error "Unity package not found!"
161+
Get-ChildItem -Recurse -Name "*.unitypackage" | ForEach-Object { Write-Host "Found: $_" }
162+
exit 1
163+
}
164+
165+
- name: Create Unity Package Directory
166+
run: |
167+
mkdir unity-package-temp
168+
mkdir unity-package-temp\Editor
169+
170+
- name: Copy Unity Package Files
171+
run: |
172+
copy "src\BitMono.Unity\Editor\*.cs" ".\unity-package-temp\Editor\"
173+
copy "src\BitMono.Unity\Editor\*.asmdef" ".\unity-package-temp\Editor\" 2>nul || echo "No .asmdef files found"
174+
175+
copy "src\BitMono.Unity\package.json" ".\unity-package-temp\"
176+
copy "src\BitMono.Unity\BitMonoConfig.asset" ".\unity-package-temp\" 2>nul || echo "No BitMonoConfig.asset found"
177+
178+
mkdir ".\unity-package-temp\BitMono.CLI" 2>nul || echo "Directory already exists"
179+
xcopy "src\BitMono.CLI\bin\Release\net462\win-x64\*" ".\unity-package-temp\BitMono.CLI\" /E /I /Y
180+
181+
- name: Update Package Version and Unity Version
182+
run: |
183+
# Extract Unity version from matrix (e.g., 2019.4.40f1 -> 2019.4)
184+
$unityVersion = '${{ matrix.unity-version }}'
185+
$unityShort = $unityVersion -replace '^(\d+\.\d+)\..*', '$1'
186+
187+
# Update package.json using PowerShell (cross-platform compatible)
188+
$packageJson = Get-Content '.\unity-package-temp\package.json' -Raw | ConvertFrom-Json
189+
$packageJson.version = '${{ needs.Build.outputs.version }}'
190+
$packageJson.unity = $unityShort
191+
$packageJson | ConvertTo-Json -Depth 10 | Set-Content '.\unity-package-temp\package.json'
192+
193+
Write-Host "Updated package.json:"
194+
Write-Host " Version: ${{ needs.Build.outputs.version }}"
195+
Write-Host " Unity: $unityShort"
196+
197+
- name: Test Unity Package Compatibility
198+
run: |
199+
# Test package.json syntax and Unity version compatibility
200+
powershell -Command "
201+
$packageJson = Get-Content '.\unity-package-temp\package.json' -Raw | ConvertFrom-Json
202+
Write-Host 'Testing Unity version compatibility...'
203+
Write-Host 'Package Unity version: ' $packageJson.unity
204+
Write-Host 'Package Unity release: ' $packageJson.unityRelease
205+
Write-Host 'Target Unity version: ${{ matrix.unity-version }}'
206+
"
207+
208+
- name: Create UPM Package (Modern Unity Package Manager)
209+
run: |
210+
# Create a proper UPM package structure
211+
mkdir upm-package
212+
mkdir upm-package\Editor
213+
214+
# Copy files to UPM structure
215+
copy "unity-package-temp\Editor\*.cs" "upm-package\Editor\"
216+
copy "unity-package-temp\Editor\*.asmdef" "upm-package\Editor\"
217+
copy "unity-package-temp\package.json" "upm-package\"
218+
copy "unity-package-temp\BitMonoConfig.asset" "upm-package\" 2>nul || echo "No BitMonoConfig.asset found"
219+
mkdir "upm-package\BitMono.CLI" 2>nul || echo "Directory already exists"
220+
xcopy "unity-package-temp\BitMono.CLI\*" "upm-package\BitMono.CLI\" /E /I /Y
221+
222+
# Create UPM tarball using tar (better compatibility than .zip)
223+
cd upm-package
224+
tar -czf ..\BitMono-Unity-UPM-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}.tgz *
225+
cd ..
226+
227+
- name: Upload Unity Packages
228+
uses: actions/upload-artifact@v4
229+
with:
230+
name: BitMono-Unity-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}
231+
path: |
232+
BitMono-Unity-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}.unitypackage
233+
BitMono-Unity-UPM-v${{ needs.Build.outputs.version }}-Unity${{ matrix.unity-version }}.tgz
234+
if-no-files-found: error
235+
236+
Release:
237+
if: github.event_name == 'create' && github.event.ref_type == 'tag'
238+
needs: [Build, UnityPackage]
239+
runs-on: ubuntu-latest
240+
steps:
241+
- name: Download all artifacts
242+
uses: actions/download-artifact@v5
243+
with:
244+
path: ./artifacts
245+
246+
- name: List downloaded artifacts
247+
run: |
248+
echo "Downloaded artifacts:"
249+
find ./artifacts -type f -name "*.zip" -o -name "*.unitypackage"
250+
echo ""
251+
echo "Unity packages by version:"
252+
find ./artifacts -name "*Unity*.unitypackage" | sort
253+
254+
- name: Create Release
255+
uses: ncipollo/release-action@v1
256+
with:
257+
name: BitMono Release v${{ needs.Build.outputs.version }}
258+
tag: ${{ needs.Build.outputs.version }}
259+
artifacts: "./artifacts/**/*.zip,./artifacts/**/*.unitypackage,./artifacts/**/*.tgz"
260+
token: ${{ secrets.PAT }}
261+
prerelease: ${{ needs.Build.outputs.is_prerelease }}
262+
allowUpdates: true
263+
draft: true
264+

.github/workflows/BitMono.CLI.yaml

Lines changed: 0 additions & 112 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# BitMono artifacts
77
src/BitMono.CLI/BitMono-v*.zip
88

9+
# Ignore temporaries from GameCI
10+
/[Aa]rtifacts/
11+
/[Cc]odeCoverage/
12+
913
# User-specific files
1014
*.rsuser
1115
*.suo

0 commit comments

Comments
 (0)