Files
ProjectMD/git-hooks/post-commit.ps1

147 lines
4.9 KiB
PowerShell
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# git-hooks/post-commit.ps1
# 자동 커밋인지 확인 (무한 루프 방지)
$commitMsg = git log -1 --pretty=%B
if ($commitMsg -match "^\[AUTO\]") {
Write-Host " Auto-generated commit detected. Skipping post-commit hook." -ForegroundColor Gray
exit 0
}
Write-Host ""
Write-Host "🔄 Post-commit: Generating ScriptableObjects..." -ForegroundColor Cyan
# 이전 커밋에서 변경된 CSV 파일 확인
$changedFiles = git diff-tree --no-commit-id --name-only -r HEAD
$csvFiles = $changedFiles | Where-Object { $_ -match "GameData/.*\.csv$" }
if ($csvFiles.Count -eq 0) {
Write-Host " 변경된 CSV 파일이 없습니다. SO 생성 스킵." -ForegroundColor Gray
exit 0
}
Write-Host "📊 처리할 파일:" -ForegroundColor Yellow
$csvFiles | ForEach-Object { Write-Host " - $_" }
Write-Host ""
# Unity 실행 중 확인
$unityProcess = Get-Process -Name "Unity" -ErrorAction SilentlyContinue
if ($unityProcess) {
Write-Host "⚠️ Unity가 실행 중입니다." -ForegroundColor Yellow
Write-Host "💡 Unity를 종료하거나, Unity에서 직접 'GameData > Import All Data'를 실행해주세요." -ForegroundColor Yellow
Write-Host ""
Write-Host "또는 다음 명령어를 실행하세요:" -ForegroundColor Cyan
Write-Host " git commit --amend --no-edit && git reset HEAD~1" -ForegroundColor White
exit 0
}
# Unity 경로 찾기 (Unity Hub 기본 설치 경로)
$unityVersions = @(
"C:\Program Files\Unity\Hub\Editor\2022.3.10f1\Editor\Unity.exe",
"C:\Program Files\Unity\Hub\Editor\2023.2.0f1\Editor\Unity.exe"
# 필요한 버전 추가
)
$unityPath = $null
foreach ($path in $unityVersions) {
if (Test-Path $path) {
$unityPath = $path
break
}
}
# Unity Hub에서 설치된 모든 버전 검색
if (-not $unityPath) {
$hubPath = "C:\Program Files\Unity\Hub\Editor"
if (Test-Path $hubPath) {
$editors = Get-ChildItem -Path $hubPath -Directory |
ForEach-Object { Join-Path $_.FullName "Editor\Unity.exe" } |
Where-Object { Test-Path $_ }
if ($editors.Count -gt 0) {
$unityPath = $editors[0]
}
}
}
if (-not $unityPath) {
Write-Host "❌ Unity 실행 파일을 찾을 수 없습니다." -ForegroundColor Red
Write-Host "💡 Unity를 수동으로 열고 'GameData > Import All Data'를 실행한 후," -ForegroundColor Yellow
Write-Host " 변경된 SO를 커밋해주세요." -ForegroundColor Yellow
exit 0
}
Write-Host "🎮 Unity CLI로 SO 생성 중..." -ForegroundColor Cyan
Write-Host "Unity: $unityPath" -ForegroundColor Gray
$projectPath = (Get-Location).Path + "\UnityProject"
$logFile = (Get-Location).Path + "\DataTools\unity_import.log"
# Unity Batch Mode 실행
$unityArgs = @(
"-quit",
"-batchmode",
"-nographics",
"-projectPath", "`"$projectPath`"",
"-executeMethod", "DataImporter.ImportAllDataCLI",
"-logFile", "`"$logFile`""
)
$process = Start-Process -FilePath $unityPath -ArgumentList $unityArgs -Wait -PassThru -NoNewWindow
if ($process.ExitCode -ne 0) {
Write-Host "❌ SO 생성 실패!" -ForegroundColor Red
Write-Host "💡 로그 파일을 확인하세요: $logFile" -ForegroundColor Yellow
exit 1
}
Write-Host "✅ SO 생성 완료!" -ForegroundColor Green
Write-Host ""
# 변경된 SO 파일 확인
git add UnityProject/Assets/Data/ScriptableObjects/ 2>$null
$status = git status --porcelain UnityProject/Assets/Data/ScriptableObjects/
if ([string]::IsNullOrWhiteSpace($status)) {
Write-Host " 변경된 SO 파일이 없습니다." -ForegroundColor Gray
exit 0
}
Write-Host "📦 변경된 SO:" -ForegroundColor Yellow
git status --porcelain UnityProject/Assets/Data/ScriptableObjects/ | ForEach-Object { Write-Host " $_" }
Write-Host ""
# SO 파일 자동 스테이징 및 커밋
Write-Host "🚀 SO 파일 자동 커밋 중..." -ForegroundColor Cyan
# Meta 파일도 함께 추가
git add UnityProject/Assets/Data/ScriptableObjects/**/*.meta 2>$null
# 변경 파일 목록
$changedList = $csvFiles -join "`n"
# 자동 커밋
$commitHash = git rev-parse --short HEAD
$commitMessage = @"
[AUTO] Update ScriptableObjects from CSV
Generated from commit: $commitHash
Changed files:
$changedList
"@
git commit -m $commitMessage 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ SO 자동 커밋 완료!" -ForegroundColor Green
Write-Host ""
$currentBranch = git branch --show-current
Write-Host "💡 다음 명령어로 Push할 수 있습니다:" -ForegroundColor Cyan
Write-Host " git push origin $currentBranch" -ForegroundColor White
} else {
Write-Host "❌ SO 자동 커밋 실패!" -ForegroundColor Red
Write-Host "💡 수동으로 SO를 커밋해주세요:" -ForegroundColor Yellow
Write-Host " git add UnityProject/Assets/Data/ScriptableObjects/" -ForegroundColor White
Write-Host " git commit -m 'Update SO'" -ForegroundColor White
}
exit 0