Skip to content

Commit 97cb43c

Browse files
committed
Improving DockerBuild.ps1 and RunClaude.ps1.
1 parent 0991803 commit 97cb43c

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

DockerBuild.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ param(
143143
[string]$RegistryImage, # Use a pre-built image from a registry, skipping Dockerfile build entirely.
144144
[switch]$NoInit, # Do not generate or call Init.g.ps1 (skips git config, safe.directory, etc).
145145
[string]$Isolation = 'hyperv', # Docker isolation mode (process or hyperv). Memory/CPU limits only apply to hyperv.
146-
[string]$Memory = '16g', # Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
146+
[string]$Memory = '32g', # Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
147147
[int]$Cpus = [Environment]::ProcessorCount, # Docker CPU limit. Only used with hyperv isolation.
148148
[string[]]$Mount, # Additional directories to mount from host (readonly by default, append :w for writable). Supports * and ** glob patterns.
149149
[string[]]$Env, # Additional environment variables to pass from host to container.

eng/RunClaude.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ if ($Prompt)
198198
$Prompt | Set-Content -Path $promptFile -Encoding UTF8 -NoNewline
199199
Write-Host "Running Claude with prompt from file: $promptFile" -ForegroundColor Cyan
200200

201+
# Tag TeamCity build with the prompt
202+
if ($env:IS_TEAMCITY_AGENT -eq "true" -or $env:IS_TEAMCITY_AGENT -eq "1") {
203+
# Escape special characters for TeamCity service message format
204+
$tagValue = $Prompt -replace '\|','||' -replace "'","|'" -replace '\[','|[' -replace '\]','|]' -replace "`n",'|n' -replace "`r",'|r'
205+
# Truncate to avoid excessively long tags
206+
if ($tagValue.Length -gt 200) { $tagValue = $tagValue.Substring(0, 200) + "..." }
207+
Write-Host "##teamcity[addBuildTag tag='$tagValue']"
208+
}
209+
201210
# Stream JSON output for human-readable real-time monitoring
202211
$processArgs = "-p --output-format stream-json --verbose --model $Model --dangerously-skip-permissions $mcpConfigArg"
203212

@@ -217,8 +226,37 @@ if ($Prompt)
217226
$process.StandardInput.Write($promptContent)
218227
$process.StandardInput.Close()
219228

229+
# Set up log file for raw JSON output
230+
$logDir = Join-Path (Resolve-Path "$PSScriptRoot\..").Path "artifacts\logs"
231+
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
232+
$timestamp = (Get-Date).ToString("yyyy-MM-dd-HHmmss")
233+
$logFile = Join-Path $logDir "claude-$timestamp.log.json"
234+
$logWriter = [System.IO.StreamWriter]::new($logFile, $false, [System.Text.Encoding]::UTF8)
235+
$logWriter.WriteLine("[")
236+
$isFirstJsonLine = $true
237+
220238
# Read and parse stdout line by line (real-time streaming)
221239
while ($null -ne ($line = $process.StandardOutput.ReadLine())) {
240+
# Write to log file in real-time
241+
if (-not [string]::IsNullOrWhiteSpace($line)) {
242+
try {
243+
$obj = $line | ConvertFrom-Json
244+
$indented = $obj | ConvertTo-Json -Depth 100
245+
if (-not $isFirstJsonLine) {
246+
$logWriter.WriteLine(",")
247+
}
248+
$logWriter.Write($indented)
249+
$isFirstJsonLine = $false
250+
} catch {
251+
# Non-JSON line - write as raw string
252+
if (-not $isFirstJsonLine) {
253+
$logWriter.WriteLine(",")
254+
}
255+
$logWriter.Write("`"$($line -replace '\\','\\\\' -replace '"','\"')`"")
256+
$isFirstJsonLine = $false
257+
}
258+
$logWriter.Flush()
259+
}
222260
ConvertFrom-ClaudeJsonLine -Line $line
223261
}
224262

@@ -229,6 +267,12 @@ if ($Prompt)
229267
$process.WaitForExit()
230268
$exitCode = $process.ExitCode
231269

270+
# Close JSON log file
271+
$logWriter.WriteLine()
272+
$logWriter.WriteLine("]")
273+
$logWriter.Close()
274+
Write-Host "Claude output log: $logFile" -ForegroundColor Green
275+
232276
# Clean up prompt file
233277
Remove-Item $promptFile -ErrorAction SilentlyContinue
234278

src/PostSharp.Engineering.BuildTools/Resources/DockerBuild.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ param(
143143
[string]$RegistryImage, # Use a pre-built image from a registry, skipping Dockerfile build entirely.
144144
[switch]$NoInit, # Do not generate or call Init.g.ps1 (skips git config, safe.directory, etc).
145145
[string]$Isolation = 'hyperv', # Docker isolation mode (process or hyperv). Memory/CPU limits only apply to hyperv.
146-
[string]$Memory = '16g', # Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
146+
[string]$Memory = '32g', # Docker memory limit (e.g., "8g"). Only used with hyperv isolation.
147147
[int]$Cpus = [Environment]::ProcessorCount, # Docker CPU limit. Only used with hyperv isolation.
148148
[string[]]$Mount, # Additional directories to mount from host (readonly by default, append :w for writable). Supports * and ** glob patterns.
149149
[string[]]$Env, # Additional environment variables to pass from host to container.

src/PostSharp.Engineering.BuildTools/Resources/RunClaude.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ if ($Prompt)
198198
$Prompt | Set-Content -Path $promptFile -Encoding UTF8 -NoNewline
199199
Write-Host "Running Claude with prompt from file: $promptFile" -ForegroundColor Cyan
200200

201+
# Tag TeamCity build with the prompt
202+
if ($env:IS_TEAMCITY_AGENT -eq "true" -or $env:IS_TEAMCITY_AGENT -eq "1") {
203+
# Escape special characters for TeamCity service message format
204+
$tagValue = $Prompt -replace '\|','||' -replace "'","|'" -replace '\[','|[' -replace '\]','|]' -replace "`n",'|n' -replace "`r",'|r'
205+
# Truncate to avoid excessively long tags
206+
if ($tagValue.Length -gt 200) { $tagValue = $tagValue.Substring(0, 200) + "..." }
207+
Write-Host "##teamcity[addBuildTag tag='$tagValue']"
208+
}
209+
201210
# Stream JSON output for human-readable real-time monitoring
202211
$processArgs = "-p --output-format stream-json --verbose --model $Model --dangerously-skip-permissions $mcpConfigArg"
203212

@@ -217,8 +226,37 @@ if ($Prompt)
217226
$process.StandardInput.Write($promptContent)
218227
$process.StandardInput.Close()
219228

229+
# Set up log file for raw JSON output
230+
$logDir = Join-Path (Resolve-Path "$PSScriptRoot\..").Path "artifacts\logs"
231+
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
232+
$timestamp = (Get-Date).ToString("yyyy-MM-dd-HHmmss")
233+
$logFile = Join-Path $logDir "claude-$timestamp.log.json"
234+
$logWriter = [System.IO.StreamWriter]::new($logFile, $false, [System.Text.Encoding]::UTF8)
235+
$logWriter.WriteLine("[")
236+
$isFirstJsonLine = $true
237+
220238
# Read and parse stdout line by line (real-time streaming)
221239
while ($null -ne ($line = $process.StandardOutput.ReadLine())) {
240+
# Write to log file in real-time
241+
if (-not [string]::IsNullOrWhiteSpace($line)) {
242+
try {
243+
$obj = $line | ConvertFrom-Json
244+
$indented = $obj | ConvertTo-Json -Depth 100
245+
if (-not $isFirstJsonLine) {
246+
$logWriter.WriteLine(",")
247+
}
248+
$logWriter.Write($indented)
249+
$isFirstJsonLine = $false
250+
} catch {
251+
# Non-JSON line - write as raw string
252+
if (-not $isFirstJsonLine) {
253+
$logWriter.WriteLine(",")
254+
}
255+
$logWriter.Write("`"$($line -replace '\\','\\\\' -replace '"','\"')`"")
256+
$isFirstJsonLine = $false
257+
}
258+
$logWriter.Flush()
259+
}
222260
ConvertFrom-ClaudeJsonLine -Line $line
223261
}
224262

@@ -229,6 +267,12 @@ if ($Prompt)
229267
$process.WaitForExit()
230268
$exitCode = $process.ExitCode
231269

270+
# Close JSON log file
271+
$logWriter.WriteLine()
272+
$logWriter.WriteLine("]")
273+
$logWriter.Close()
274+
Write-Host "Claude output log: $logFile" -ForegroundColor Green
275+
232276
# Clean up prompt file
233277
Remove-Item $promptFile -ErrorAction SilentlyContinue
234278

0 commit comments

Comments
 (0)