fix: post deployment parameterized - #671
Closed
Prachig-Microsoft wants to merge 1 commit into
Closed
Conversation
Prachig-Microsoft
requested review from
Avijit-Microsoft,
Prajwal-Microsoft,
Roopan-Microsoft,
Vinay-Microsoft,
aniaroramsft,
dgp10801,
nchandhi and
toherman-msft
as code owners
August 3, 2026 13:31
Contributor
There was a problem hiding this comment.
Pull request overview
This PR parameterizes the infra/scripts/post_deployment.ps1 script (resource group, subscription, API base URL, and CU account name) and adds a regression test to prevent propagating azd error output as a Cognitive Services account name during post-deployment refresh.
Changes:
- Add parameters and helper functions to make
post_deployment.ps1runnable without relying solely onazd env. - Improve schema-registration flow to skip gracefully when an API base URL can’t be resolved.
- Add a PowerShell regression test that stubs
azd/azand validates CU account selection/refresh behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
infra/scripts/post_deployment.ps1 |
Adds parameters + Azure/azd helpers; adjusts schema registration and CU account refresh logic. |
tests/post_deployment_regression.ps1 |
Adds a regression script that stubs CLI calls and validates post-deployment CU refresh behavior. |
Suppressed comments (2)
infra/scripts/post_deployment.ps1:505
- On refresh failure, the script currently logs an empty
az error:string becauseInvoke-AzureClidiscards stderr and$UpdateOutputStris explicitly set to''. Capturing stderr here will make deployment logs actionable when this non-fatal step fails.
$UpdateOutput = Invoke-AzureCli -Arguments @('cognitiveservices', 'account', 'update', '-g', $RESOURCE_GROUP, '-n', $CU_ACCOUNT_NAME, '--tags', 'refresh=true', '--output', 'none') -AllowFailure
if ($UpdateOutput -ne $null) {
Write-Host " [OK] Successfully refreshed Cognitive Services account '$CU_ACCOUNT_NAME'."
} else {
$UpdateOutputStr = ''
Write-Host " [Warn] Could not refresh Cognitive Services account '$CU_ACCOUNT_NAME'. Continuing - this step is non-fatal."
Write-Host " az error: $UpdateOutputStr"
tests/post_deployment_regression.ps1:96
- After moving the listener into the background job, the
finallyblock should no longer reference$listener(it will be undefined).
$listener.Stop()
$listener.Close()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+133
to
+139
| $RESOURCE_GROUP = if ($ResourceGroupName) { $ResourceGroupName } else { Get-AzdEnvironmentValue -Name 'AZURE_RESOURCE_GROUP' } | ||
| if (-not $RESOURCE_GROUP) { | ||
| $RESOURCE_GROUP = (Invoke-AzureCli -Arguments @('group', 'show', '--query', 'name', '-o', 'tsv') -AllowFailure) | ||
| if (-not $RESOURCE_GROUP) { | ||
| $RESOURCE_GROUP = '' | ||
| } | ||
| } |
| return $trimmed.TrimEnd('/') | ||
| } | ||
|
|
||
| return "https://$trimmed" |
Comment on lines
+458
to
+462
| $ShowOutput = Invoke-AzureCli -Arguments @('cognitiveservices', 'account', 'show', '-g', $RESOURCE_GROUP, '-n', $CU_ACCOUNT_NAME, '--output', 'none') -AllowFailure | ||
| if (-not $ShowOutput) { | ||
| $ShowOutputStr = '' | ||
| if ($LASTEXITCODE -ne 0) { | ||
| $ShowOutputStr = 'Azure CLI returned a non-zero exit code.' |
Comment on lines
+61
to
+81
| $listener = [System.Net.HttpListener]::new() | ||
| $listener.Prefixes.Add('http://127.0.0.1:18080/') | ||
| $listener.Start() | ||
|
|
||
| $listenerJob = Start-Job -ScriptBlock { | ||
| param($listener) | ||
| while ($true) { | ||
| try { | ||
| $context = $listener.GetContext() | ||
| $response = $context.Response | ||
| $response.StatusCode = 200 | ||
| $response.ContentType = 'application/json' | ||
| $buffer = [System.Text.Encoding]::UTF8.GetBytes('{"ok":true}') | ||
| $response.ContentLength64 = $buffer.Length | ||
| $response.OutputStream.Write($buffer, 0, $buffer.Length) | ||
| $response.OutputStream.Close() | ||
| } catch { | ||
| break | ||
| } | ||
| } | ||
| } -ArgumentList $listener |
| exit /b 0 | ||
| '@ | Set-Content (Join-Path $stubDir 'az.cmd') -Encoding ASCII | ||
|
|
||
| $env:PATH = "$stubDir;$env:PATH" |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Does this introduce a breaking change?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
Other Information