Skip to content

Commit 183fd45

Browse files
authored
support: post release cleanup (#8)
* fix: unity editor package - refactor fixed64 rawvalue property to fix serialization issues with unity * task: add build scripts - update git config
1 parent 93eae3e commit 183fd45

35 files changed

Lines changed: 803 additions & 276 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
param (
2+
[string]$OutputPath = "UnityPackages",
3+
[string]$UnityVersion = "2022.3.20f1"
4+
)
5+
6+
# Import shared functions
7+
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
8+
. .\utilities.ps1
9+
10+
# Locate solution directory and switch to it
11+
$solutionDir = Get-SolutionDirectory
12+
Set-Location $solutionDir
13+
14+
$packageName = "FixedMathSharp.$env:GitVersion_FullSemVer.unitypackage"
15+
$packagePath = "$solutionDir\$OutputPath\$packageName"
16+
17+
$fixedMathSharpPluginsPath = "$solutionDir\src\FixedMathSharp.Editor\bin\Release\net48"
18+
$unityProjectPath = "$solutionDir\FMS_UnityProject"
19+
$unityAssetsPath = "$unityProjectPath\Assets\FixedMathSharp"
20+
$unityPluginsPath = "$unityAssetsPath\Plugins"
21+
22+
# Ensure a fresh Unity project by deleting the directory if it exists
23+
if (Test-Path $unityProjectPath) {
24+
Write-Host "Deleting existing Unity project directory at $unityProjectPath..."
25+
Remove-Item -Recurse -Force $unityProjectPath
26+
}
27+
28+
# Recreate necessary folders
29+
@($unityAssetsPath, $unityPluginsPath, $packagePath) | ForEach-Object {
30+
if (-Not (Test-Path $_)) { New-Item -ItemType Directory -Path $_ }
31+
}
32+
33+
# Ensure GitVersion environment variables are set
34+
Ensure-GitVersion-Environment $UnityVersion
35+
36+
# Build the project with the version information applied
37+
Build-Project -Configuration "Release"
38+
39+
# Copy DLLs (including PDB and XML) to Unity Plugins folder
40+
Copy-Item "$fixedMathSharpPluginsPath\*" $unityPluginsPath -Recurse -ErrorAction SilentlyContinue
41+
42+
# Copy Unity editor-specific scripts to the Assets folder
43+
Copy-Item "$solutionDir\src\FixedMathSharp.Editor\Editor" $unityAssetsPath -Recurse -ErrorAction SilentlyContinue
44+
45+
$unityExePath = "C:\Program Files\Unity\Hub\Editor\$env:UnityVersion\Editor\Unity.exe"
46+
$unityArgs = @(
47+
"-quit", # Quit after the operation completes
48+
"-batchmode", # Run in batch mode (no UI)
49+
"-projectPath", "$unityProjectPath", # Path to the Unity project
50+
"-exportPackage", "Assets", "$packagePath"
51+
)
52+
53+
Write-Host "Packing to $packagePath..."
54+
55+
# Run Unity to create the package
56+
Start-Process $unityExePath -ArgumentList $unityArgs -Wait -NoNewWindow
57+
58+
if ($LASTEXITCODE -ne 0) {
59+
Write-Host "Package creation failed." -ForegroundColor Red
60+
exit 1
61+
}
62+
63+
Write-Host "Package $packageName created successfully!" -ForegroundColor Green
64+
65+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
param (
2+
[string]$BuildType = "Release",
3+
[string]$UnityVersion = "2022.3.20f1"
4+
)
5+
6+
# Import shared functions
7+
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
8+
. .\utilities.ps1
9+
10+
# Locate solution directory and switch to it
11+
$solutionDir = Get-SolutionDirectory
12+
Set-Location $solutionDir
13+
14+
# Ensure GitVersion environment variables are set
15+
Ensure-GitVersion-Environment $UnityVersion
16+
17+
# Build the project with the version information applied
18+
Build-Project -Configuration $BuildType

.assets/scripts/utilities.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
function Get-SolutionDirectory {
2+
param ([string]$StartPath = $(Get-Location))
3+
4+
$currentPath = $StartPath
5+
while ($true) {
6+
if (Test-Path (Join-Path $currentPath "FixedMathSharp.sln")) {
7+
return $currentPath
8+
}
9+
$parent = [System.IO.Directory]::GetParent($currentPath)
10+
if ($parent -eq $null) { break }
11+
$currentPath = $parent.FullName
12+
}
13+
throw "Solution directory not found."
14+
}
15+
16+
function Ensure-GitVersion-Environment {
17+
param ([string]$UnityVersion = "2022.3.20f1")
18+
19+
# Ensure GitVersion is installed and available
20+
if (-not (Get-Command "dotnet-gitversion" -ErrorAction SilentlyContinue)) {
21+
Write-Host "GitVersion is not installed. Install it with:"
22+
Write-Host "dotnet tool install -g GitVersion.Tool"
23+
exit 1
24+
}
25+
26+
Write-Host "Fetching version information using GitVersion..."
27+
28+
# Capture GitVersion output as JSON and convert it to PowerShell objects
29+
$gitVersionOutput = dotnet-gitversion -output json | ConvertFrom-Json
30+
31+
if ($null -eq $gitVersionOutput) {
32+
Write-Host "ERROR: Failed to get version information from GitVersion." -ForegroundColor Red
33+
exit 1
34+
}
35+
36+
# Extract key version properties
37+
$semVer = $gitVersionOutput.FullSemVer
38+
$assemblySemVer = $gitVersionOutput.AssemblySemVer
39+
$assemblySemFileVer = $gitVersionOutput.AssemblySemFileVer
40+
$infoVersion = $gitVersionOutput.InformationalVersion
41+
42+
# Set environment variables for the build process
43+
[System.Environment]::SetEnvironmentVariable('GitVersion_FullSemVer', $semVer, 'Process')
44+
[System.Environment]::SetEnvironmentVariable('GitVersion_AssemblySemVer', $assemblySemVer, 'Process')
45+
[System.Environment]::SetEnvironmentVariable('GitVersion_AssemblySemFileVer', $assemblySemFileVer, 'Process')
46+
[System.Environment]::SetEnvironmentVariable('GitVersion_InformationalVersion', $infoVersion, 'Process')
47+
[System.Environment]::SetEnvironmentVariable('UnityVersion', $UnityVersion, 'Process')
48+
49+
Write-Host "Environment variables set:"
50+
Write-Host " GitVersion_FullSemVer = $semVer"
51+
Write-Host " GitVersion_AssemblySemVer = $assemblySemVer"
52+
Write-Host " GitVersion_AssemblySemFileVer = $assemblySemFileVer"
53+
Write-Host " GitVersion_InformationalVersion = $infoVersion"
54+
Write-Host " UnityVersion = $UnityVersion"
55+
}
56+
57+
function Build-Project {
58+
param (
59+
[string]$SolutionPath = "FixedMathSharp.sln",
60+
[string]$Configuration = "Release"
61+
)
62+
63+
Write-Host "Building $SolutionPath in $Configuration mode..."
64+
# Clean and build the project with the selected configuration
65+
dotnet clean
66+
dotnet build $SolutionPath -c $Configuration
67+
68+
if ($LASTEXITCODE -ne 0) {
69+
Write-Host "Build failed." -ForegroundColor Red
70+
exit 1
71+
}
72+
73+
Write-Host "Build succeeded!" -ForegroundColor Green
74+
}

.gitattributes

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto eol=lf
3+
4+
# Declare files that will always have LF line endings on checkout.
5+
*.sh text eol=lf
6+
7+
# Don't check these into the repo as LF to work around TeamCity bug
8+
*.xml -text
9+
*.targets -text
10+
11+
# Custom for Visual Studio
12+
*.cs diff=csharp
13+
*.sln
14+
*.csproj
15+
*.vbproj
16+
*.fsproj
17+
*.dbproj
18+
19+
# Denote all files that are truly binary and should not be modified.
20+
*.dll binary
21+
*.exe binary
22+
*.png binary
23+
*.ico binary
24+
*.snk binary
25+
*.pdb binary
26+
*.svg binary
27+
28+
# Don't check for trailing whitespace at end of lines in the doc pages
29+
*.md -whitespace=blank-at-eol

.github/workflows/dotnet.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ jobs:
2727
steps:
2828
- name: Checkout repository
2929
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
persist-credentials: false # Ensure credentials aren't retained
3033

3134
- name: Setup .NET
3235
uses: actions/setup-dotnet@v4
3336
with:
3437
dotnet-version: 8.0.x
38+
39+
- name: Install GitVersion
40+
uses: gittools/actions/gitversion/setup@v3.0.0
41+
with:
42+
versionSpec: '6.x'
3543

3644
- name: Cache NuGet packages
3745
uses: actions/cache@v3
@@ -41,13 +49,20 @@ jobs:
4149
restore-keys: |
4250
${{ runner.os }}-nuget-
4351
52+
- name: Determine Version
53+
run: |
54+
chown -R $(whoami) $(pwd)
55+
dotnet-gitversion /output json
56+
4457
- name: Restore dependencies
4558
run: dotnet restore
4659

4760
- name: Build Solution
4861
env:
4962
UnityManagedPath: \opt\unity\Editor\Data\Managed
50-
run: dotnet build --configuration Release --no-restore
63+
run: |
64+
echo "Version:${{ env.GitVersion_FullSemVer }}\nAssembley Version:${{ env.GitVersion_AssemblySemFileVer }}"
65+
dotnet build --configuration Release --no-restore
5166
5267
- name: Upload Test Artifacts
5368
uses: actions/upload-artifact@v3
@@ -73,4 +88,4 @@ jobs:
7388
- name: Test
7489
run: |
7590
dotnet --info
76-
dotnet test ${{ github.workspace }}\tests\FixedMathSharp.Tests\bin\Release\net471\FixedMathSharp.Tests.dll --verbosity normal
91+
dotnet test ${{ github.workspace }}\tests\FixedMathSharp.Tests\bin\Release\net48\FixedMathSharp.Tests.dll --verbosity normal

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
.vs/
2-
src/FixedMathSharp.Editor/bin/
3-
src/FixedMathSharp.Editor/obj/
4-
src/FixedMathSharp/bin/
5-
src/FixedMathSharp/obj/
6-
tests/FixedMathSharp.Tests/bin/
7-
tests/FixedMathSharp.Tests/obj/
2+
UnityPackages/
3+
FMS_UnityProject/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
obj/

src/FixedMathSharp.Editor/Attributes/FixedNumberAngleAttribute.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#if UNITY_EDITOR
2-
using UnityEngine;
1+
using UnityEngine;
32

4-
namespace FixedMathSharp.Unity
3+
namespace FixedMathSharp
54
{
65
/// <summary>
76
/// Attribute to represent a fixed number angle in degrees.
@@ -31,5 +30,4 @@ public FixedNumberAngleAttribute(double timescale = 1d, double max = -1d)
3130
Max = max;
3231
}
3332
}
34-
}
35-
#endif
33+
}

src/FixedMathSharp.Editor/Attributes/FixedNumberAttribute.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#if UNITY_EDITOR || UNITY_5_3_OR_NEWER
2-
using UnityEngine;
1+
using UnityEngine;
32

4-
namespace FixedMathSharp.Unity
3+
namespace FixedMathSharp
54
{
65
public class FixedNumberAttribute : PropertyAttribute
76
{
@@ -18,5 +17,4 @@ public FixedNumberAttribute(double timescale = 1d, bool ranged = false, long min
1817
Min = min;
1918
}
2019
}
21-
}
22-
#endif
20+
}

src/FixedMathSharp.Editor/Attributes/VectorRotationAttribute.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#if UNITY_EDITOR
2-
using UnityEngine;
1+
using UnityEngine;
32

4-
namespace FixedMathSharp.Unity
3+
namespace FixedMathSharp
54
{
65
/// <summary>
76
/// Attribute to represent a fixed number angle in degrees.
@@ -16,5 +15,4 @@ public VectorRotationAttribute(double timescale = 1d)
1615
Timescale = timescale;
1716
}
1817
}
19-
}
20-
#endif
18+
}

0 commit comments

Comments
 (0)