@@ -38,7 +38,10 @@ param(
3838 [string ]$BumpType ,
3939
4040 [Parameter ()]
41- [switch ]$DryRun
41+ [switch ]$DryRun ,
42+
43+ [Parameter ()]
44+ [switch ]$TestMode # For testing the script without making changes
4245)
4346
4447$ErrorActionPreference = ' Stop'
@@ -63,6 +66,13 @@ function Write-Error {
6366 Write-Host " ✗ $Message " - ForegroundColor Red
6467}
6568
69+ function Write-Debug-Log {
70+ param ([string ]$Message )
71+ if ($TestMode ) {
72+ Write-Host " [DEBUG] $Message " - ForegroundColor DarkGray
73+ }
74+ }
75+
6676function Test-Prerequisites {
6777 Write-Step " Checking prerequisites..."
6878
@@ -191,7 +201,7 @@ Please analyze these commits and provide:
191201 - Keep it concise but informative
192202 - Do not include a version header (that will be added separately)
193203
194- Format your response EXACTLY like this (the markers are important for parsing) :
204+ IMPORTANT: Output ONLY the formatted response below with NO other text before or after :
195205---SUGGESTED_BUMP---
196206patch
197207---RELEASE_NOTES---
@@ -209,15 +219,45 @@ patch
209219 throw " Claude CLI failed: $response "
210220 }
211221
212- # Parse the response
222+ # Parse the response - normalize line endings first
223+ Write-Debug - Log " Raw response type: $ ( $response.GetType ().FullName) "
224+ Write-Debug - Log " Raw response is array: $ ( $response -is [array ]) "
225+ if ($response -is [array ]) {
226+ Write-Debug - Log " Response array count: $ ( $response.Count ) "
227+ }
228+
229+ $responseText = $response -join " `n "
230+ $responseText = $responseText -replace " `r`n " , " `n "
231+
232+ Write-Debug - Log " Response text length: $ ( $responseText.Length ) "
233+ Write-Debug - Log " Response contains SUGGESTED_BUMP: $ ( $responseText.Contains (' ---SUGGESTED_BUMP---' )) "
234+ Write-Debug - Log " Response contains RELEASE_NOTES: $ ( $responseText.Contains (' ---RELEASE_NOTES---' )) "
235+ Write-Debug - Log " Response contains END: $ ( $responseText.Contains (' ---END---' )) "
236+
237+ if ($TestMode ) {
238+ Write-Host " `n [DEBUG] Full response text:" - ForegroundColor DarkGray
239+ Write-Host " ─────────────────────────────────────────" - ForegroundColor DarkGray
240+ Write-Host $responseText - ForegroundColor DarkGray
241+ Write-Host " ─────────────────────────────────────────" - ForegroundColor DarkGray
242+ }
243+
213244 $suggestedBump = $null
214245 $releaseNotes = $null
215246
216- if ($response -match ' ---SUGGESTED_BUMP---\s*(\w+)\s*---RELEASE_NOTES---\s*([\s\S]*?)\s*---END---' ) {
247+ # Extract SUGGESTED_BUMP
248+ if ($responseText -match ' ---SUGGESTED_BUMP---\s*(\w+)' ) {
217249 $suggestedBump = $Matches [1 ].Trim()
218- $releaseNotes = $Matches [ 2 ].Trim()
250+ Write-Debug - Log " Parsed SUGGESTED_BUMP: $suggestedBump "
219251 } else {
220- throw " Failed to parse Claude response. Raw response:`n $response "
252+ throw " Failed to parse SUGGESTED_BUMP from Claude response. Raw response:`n $responseText "
253+ }
254+
255+ # Extract RELEASE_NOTES
256+ if ($responseText -match ' ---RELEASE_NOTES---\s*([\s\S]*?)\s*---END---' ) {
257+ $releaseNotes = $Matches [1 ].Trim()
258+ Write-Debug - Log " Parsed RELEASE_NOTES length: $ ( $releaseNotes.Length ) "
259+ } else {
260+ throw " Failed to parse RELEASE_NOTES from Claude response. Raw response:`n $responseText "
221261 }
222262
223263 Write-Success " Claude suggests: $suggestedBump bump"
@@ -338,8 +378,12 @@ try {
338378 Write-Host " ║ ServiceBusToolset Release Script ║" - ForegroundColor Magenta
339379 Write-Host " ╚═══════════════════════════════════════════════════════════════╝" - ForegroundColor Magenta
340380
341- Test-Prerequisites
342- Test-WorkingDirectory
381+ if ($TestMode ) {
382+ Write-Host " [TEST MODE] Skipping prerequisites and working directory checks" - ForegroundColor Yellow
383+ } else {
384+ Test-Prerequisites
385+ Test-WorkingDirectory
386+ }
343387
344388 $lastTag = Get-LastVersionTag
345389 $commits = Get-CommitsSinceTag - Tag $lastTag
@@ -358,7 +402,12 @@ try {
358402 $confirmed = Confirm-Release - Version $nextVersion - BumpType $effectiveBumpType - ReleaseNotes $claudeResult.ReleaseNotes
359403
360404 if ($confirmed ) {
361- New-Release - Version $nextVersion - ReleaseNotes $claudeResult.ReleaseNotes
405+ if ($TestMode ) {
406+ Write-Host " `n [TEST MODE] Would create release v$nextVersion - skipping actual release" - ForegroundColor Yellow
407+ Write-Success " Test completed successfully! Parsing works correctly."
408+ } else {
409+ New-Release - Version $nextVersion - ReleaseNotes $claudeResult.ReleaseNotes
410+ }
362411 } else {
363412 if (-not $DryRun ) {
364413 Write-Host " `n Release cancelled." - ForegroundColor Yellow
0 commit comments