-
-
Save piotrmacha/46c0e765405c94ceafd96c64f573d40c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Root = Resolve-Path -Path "C:/Build/Repository/Gothic II NH/_work/NH" | |
$CP1250 = [System.Text.Encoding]::GetEncoding(1250) | |
$UTF8 = [System.Text.Encoding]::UTF8 | |
[Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() | |
$Branch = $ENV:BRANCH | |
$Version = $ENV:VERSION | |
$Locale = $ENV:LOCALE | |
if ([string]::IsNullOrEmpty($Version)) { | |
$Date = Get-Date -Format "yyyy.MM.dd.HH.mm" | |
$Version = "$Branch-$Date-dev" | |
} | |
# Pull selected branch | |
$Branch = $Branch -replace '^origin\/','' | |
Write-Host "Pulling git repository from $Branch" -ForegroundColor DarkGray | |
git -C "$Root" checkout main | |
if ($Branch -ne "main") { | |
git -C "$Root" branch --delete $Branch | |
} | |
git -C "$Root" fetch --all | |
git -C "$Root" checkout $Branch | |
git -C "$Root" pull | |
# Compile all assets | |
Write-Host "Running: gmbt compile --full" -ForegroundColor Cyan | |
$BuildProcess = [System.Diagnostics.Process]@{ | |
StartInfo = @{ | |
FileName = 'gmbt' | |
Arguments = "compile --full --hooks-forward-parameter=`"$Locale`" -V detailed" | |
RedirectStandardOutput = $true | |
RedirectStandardError = $true | |
UseShellExecute = $false | |
WorkingDirectory = $Root | |
} | |
} | |
Register-ObjectEvent $BuildProcess -EventName OutputDataReceived -MessageData $stdout -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkGray | |
} | Out-Null | |
Register-ObjectEvent $BuildProcess -EventName ErrorDataReceived -MessageData $stderr -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkRed | |
} | Out-Null | |
$BuildProcess.Start() | Out-Null | |
$BuildProcess.BeginOutputReadLine() | |
$BuildProcess.BeginErrorReadLine() | |
while (-not $BuildProcess.HasExited) { | |
# Empty loop to let output event handlers print | |
} | |
Wait-Process -Id $BuildProcess.Id | |
Write-Host "Compilation successfuly." -ForegroundColor Green | |
# Run game to compile DAT files | |
Write-Host "Running: gmbt test --merge=none" -ForegroundColor Cyan | |
$global:TestDone = $false | |
$global:TestTimerStart = $false | |
$global:TestTimerEnd = $null | |
$TestProcess = [System.Diagnostics.Process]@{ | |
StartInfo = @{ | |
FileName = 'gmbt' | |
Arguments = 'test --merge=none -V detailed' | |
RedirectStandardOutput = $true | |
RedirectStandardError = $true | |
UseShellExecute = $false | |
WorkingDirectory = $Root | |
} | |
} | |
Register-ObjectEvent $TestProcess -EventName OutputDataReceived -MessageData $stdout -Action { | |
$line = $Event.SourceEventArgs.Data | |
if ($line.Trim() -like "Skompilowano:*") { | |
Write-Host "Got compilation confirmation. Waiting for 10s..." -ForegroundColor Cyan | |
$global:TestTimerStart = $true | |
$global:TestTimerEnd = (Get-Date).AddSeconds(10) | |
} | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkGray | |
} | Out-Null | |
Register-ObjectEvent $TestProcess -EventName ErrorDataReceived -MessageData $stderr -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkRed | |
} | Out-Null | |
$TestProcess.Start() | Out-Null | |
$TestProcess.BeginOutputReadLine() | |
$TestProcess.BeginErrorReadLine() | |
while (-not $global:TestDone) { | |
if ($global:TestTimerStart) { | |
if ($global:TestTimerEnd -lt (Get-Date)) { | |
$global:TestDone = $true | |
} | |
} | |
} | |
Write-Host "Compilation confirmed. Killing Gothic2.exe" -ForegroundColor Green | |
$G2 = Get-Process -Name "Gothic2" | |
if ($G2) { | |
Stop-Process -Id $G2.Id -Force | |
} | |
Wait-Process -Id $TestProcess.Id | |
Write-Host "Test finished successfuly." -ForegroundColor Green | |
# Pack assets to NH.mod | |
Write-Host "Running: gmbt pack --skipmerge" -ForegroundColor Cyan | |
$PackProcess = [System.Diagnostics.Process]@{ | |
StartInfo = @{ | |
FileName = 'gmbt' | |
Arguments = 'pack --skipmerge -V detailed' | |
RedirectStandardOutput = $true | |
RedirectStandardError = $true | |
UseShellExecute = $false | |
WorkingDirectory = $Root | |
} | |
} | |
Register-ObjectEvent $PackProcess -EventName OutputDataReceived -MessageData $stdout -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkGray | |
} | Out-Null | |
Register-ObjectEvent $PackProcess -EventName ErrorDataReceived -MessageData $stderr -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkRed | |
} | Out-Null | |
$PackProcess.Start() | Out-Null | |
$PackProcess.BeginOutputReadLine() | |
$PackProcess.BeginErrorReadLine() | |
while (-not $PackProcess.HasExited) { | |
# Empty loop to let output event handlers print | |
} | |
Write-Host "Package built successfuly." -ForegroundColor Green | |
# Build release package | |
Write-Host "Running: ./BuildRelease.ps1 release/NH.ini $Version" -ForegroundColor Cyan | |
$ReleaseProcess = [System.Diagnostics.Process]@{ | |
StartInfo = @{ | |
FileName = 'powershell' | |
Arguments = './BuildRelease.ps1 release/NH.ini $Version' | |
RedirectStandardOutput = $true | |
RedirectStandardError = $true | |
UseShellExecute = $false | |
WorkingDirectory = $Root | |
} | |
} | |
Register-ObjectEvent $ReleaseProcess -EventName OutputDataReceived -MessageData $stdout -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkGray | |
} | Out-Null | |
Register-ObjectEvent $ReleaseProcess -EventName ErrorDataReceived -MessageData $stderr -Action { | |
$line = $Event.SourceEventArgs.Data | |
$line = "`t" + $line | |
Write-Host $line -ForegroundColor DarkRed | |
} | Out-Null | |
$ReleaseProcess.Start() | Out-Null | |
$ReleaseProcess.BeginOutputReadLine() | |
$ReleaseProcess.BeginErrorReadLine() | |
while (-not $ReleaseProcess.HasExited) { | |
# Empty loop to let output event handlers print | |
} | |
# Generate descriptor files | |
$GitLog = $(git -C "$Root" log -n 5 --no-merges --pretty="format:<NL>%H %ai %s" --encoding=UTF-8).Replace("<NL>", "`n") | |
$Changes = "Build: $ENV:BUILD_NUMBER`nBuild tag: $ENV:BUILD_TAG`nData: $(Get-Date -Format "dd.MM.yyyy HH:mm:ss")`nGit log:$GitLog" | |
$zips = Get-ChildItem "$Root/release/output/" -Filter *.zip -Recurse | |
foreach ($zip in $zips) { | |
Write-Host "Release built at: $zip." -ForegroundColor Green | |
Set-Content -Path "$Root/release/output/$($zip).txt" -Value $Changes -Encoding utf8 | |
} | |
# Archive the release package and generate descriptor | |
if (-not (Test-Path -Path "./archives")) { | |
mkdir "./archives" | |
} | |
Remove-Item -Path "./archives/*" | |
foreach ($zip in $zips) { | |
Copy-Item -Path "$Root/release/output/$zip" -Destination "./archives/" | |
Copy-Item -Path "$Root/release/output/$zip.txt" -Destination "./archives/" | |
} | |
Write-Host "Done." -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment