Skip to content

fix: post deployment parameterized - #671

Closed
Prachig-Microsoft wants to merge 1 commit into
microsoft:mainfrom
Prachig-Microsoft:psl_AVM_CP
Closed

fix: post deployment parameterized#671
Prachig-Microsoft wants to merge 1 commit into
microsoft:mainfrom
Prachig-Microsoft:psl_AVM_CP

Conversation

@Prachig-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

  • ...

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ps1 runnable without relying solely on azd 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/az and 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 because Invoke-AzureCli discards stderr and $UpdateOutputStr is 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 finally block 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"
@Prachig-Microsoft
Prachig-Microsoft deleted the psl_AVM_CP branch August 3, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants