데이터 파이프라인 구축

This commit is contained in:
2026-01-22 16:28:09 +09:00
parent 88a3f4c4e0
commit 3e6e5f0043
18 changed files with 1615 additions and 2 deletions

5
git-hooks/post-commit Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
# git-hooks/post-commit
powershell.exe -ExecutionPolicy Bypass -File "./git-hooks/post-commit.ps1"
exit $?

147
git-hooks/post-commit.ps1 Normal file
View File

@@ -0,0 +1,147 @@
# 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

6
git-hooks/pre-commit Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
# git-hooks/pre-commit
# Git이 실행하는 파일 (확장자 없음, sh 헤더 필요)
powershell.exe -ExecutionPolicy Bypass -File "./git-hooks/pre-commit.ps1"
exit $?

49
git-hooks/pre-commit.ps1 Normal file
View File

@@ -0,0 +1,49 @@
# git-hooks/pre-commit.ps1
Write-Host "🔍 Pre-commit: Validating game data..." -ForegroundColor Cyan
# 변경된 CSV 파일 확인
$changedFiles = git diff --cached --name-only --diff-filter=ACM
$CSVFiles = $changedFiles | Where-Object { $_ -match "GameData/.*\.csv$" }
if ($CSVFiles.Count -eq 0) {
Write-Host " 변경된 CSV 파일이 없습니다." -ForegroundColor Gray
exit 0
}
Write-Host "📊 검증할 파일:" -ForegroundColor Yellow
$CSVFiles | ForEach-Object { Write-Host " - $_" }
Write-Host ""
# Python 설치 확인
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
Write-Host "❌ Python이 설치되어 있지 않습니다." -ForegroundColor Red
Write-Host "💡 https://www.python.org/downloads/ 에서 Python을 설치하세요." -ForegroundColor Yellow
exit 1
}
# 검증 스크립트 실행
Push-Location DataTools
try {
python validate_data.py
$exitCode = $LASTEXITCODE
Pop-Location
if ($exitCode -ne 0) {
Write-Host ""
Write-Host "❌ 데이터 검증 실패!" -ForegroundColor Red
Write-Host "💡 CSV 파일을 수정 후 다시 커밋해주세요." -ForegroundColor Yellow
exit 1
}
Write-Host "✅ 데이터 검증 통과!" -ForegroundColor Green
exit 0
}
catch {
Pop-Location
Write-Host "❌ 검증 중 오류 발생: $_" -ForegroundColor Red
exit 1
}