Skip to content

Commit 6cfa91b

Browse files
fix: Update deployment scripts to use PowerShell and enhance use case selection
1 parent 8c7bb05 commit 6cfa91b

2 files changed

Lines changed: 85 additions & 50 deletions

File tree

.github/workflows/job-deploy-windows.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ jobs:
348348
azd auth login --client-id "${{ secrets.AZURE_CLIENT_ID }}" --federated-credential-provider "github" --tenant-id "${{ secrets.AZURE_TENANT_ID }}"
349349
350350
- name: Run Post deployment scripts
351-
shell: bash
351+
shell: pwsh
352352
env:
353353
INPUT_RESOURCE_GROUP_NAME: ${{ inputs.RESOURCE_GROUP_NAME }}
354354
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
@@ -357,29 +357,29 @@ jobs:
357357
BACKEND_URL: ${{ steps.get_output_windows.outputs.BACKEND_URL }}
358358
AZURE_STORAGE_ACCOUNT_NAME: ${{ steps.get_output_windows.outputs.AZURE_STORAGE_ACCOUNT_NAME }}
359359
AZURE_AI_SEARCH_NAME: ${{ steps.get_output_windows.outputs.AZURE_AI_SEARCH_NAME }}
360-
# Needed by post_deploy.sh to resolve the principal id when the workflow
360+
# Needed by post_deploy.ps1 to resolve the principal id when the workflow
361361
# is signed in as a service principal (no interactive user).
362362
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
363363
run: |
364-
set -e
365-
# Use the same login pattern as selecting_team_config_and_data.sh:
366-
# confirm an Azure CLI session is active. The preceding "Refresh Azure
364+
$ErrorActionPreference = "Stop"
365+
# Confirm an Azure CLI session is active. The preceding "Refresh Azure
367366
# login" step re-establishes credentials, so we only verify here.
368-
if az account show >/dev/null 2>&1; then
369-
echo "Already authenticated with Azure."
370-
else
371-
echo "ERROR: Not authenticated with Azure. The 'Refresh Azure login' step must run before this step."
367+
az account show 2>$null | Out-Null
368+
if ($LASTEXITCODE -ne 0) {
369+
Write-Error "Not authenticated with Azure. The 'Refresh Azure login' step must run before this step."
372370
exit 1
373-
fi
374-
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
371+
}
372+
Write-Host "Already authenticated with Azure."
373+
az account set --subscription "$env:AZURE_SUBSCRIPTION_ID"
375374
376-
# Run the unified post-deploy script non-interactively.
377-
# --use-case 7 installs all use cases; --resource-group enables fallbacks
375+
# Run the unified PowerShell post-deploy script non-interactively.
376+
# -UseCase 7 installs all use cases; -ResourceGroup enables fallbacks
378377
# to deployment outputs / naming-convention if azd env values are missing.
379-
bash infra/scripts/post_deploy.sh \
380-
--resource-group "$INPUT_RESOURCE_GROUP_NAME" \
381-
--use-case 7 \
382-
--non-interactive
378+
./infra/scripts/post_deploy.ps1 `
379+
-ResourceGroup "$env:INPUT_RESOURCE_GROUP_NAME" `
380+
-UseCase 7 `
381+
-NonInteractive
382+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
383383
384384
- name: Generate Deployment Summary
385385
if: always()

infra/scripts/post_deploy.ps1

Lines changed: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
#>
2424

2525
param(
26-
[string]$ResourceGroup
26+
[string]$ResourceGroup,
27+
[ValidateSet("1", "2", "3", "4", "5", "6", "7", "all", "All", "ALL")]
28+
[string]$UseCase,
29+
[switch]$NonInteractive
2730
)
2831

2932
Set-StrictMode -Version Latest
@@ -491,7 +494,7 @@ try {
491494
$currentSubscriptionId = az account show --query id -o tsv
492495
$currentSubscriptionName = az account show --query name -o tsv
493496

494-
if ($script:azSubscriptionId -and $currentSubscriptionId -ne $script:azSubscriptionId) {
497+
if (-not $NonInteractive -and $script:azSubscriptionId -and $currentSubscriptionId -ne $script:azSubscriptionId) {
495498
Write-Host "Current subscription is $currentSubscriptionName ( $currentSubscriptionId )."
496499
$confirmation = Read-Host "Do you want to continue with this subscription? (y/n)"
497500
if ($confirmation -notin @("y", "Y")) {
@@ -553,37 +556,56 @@ try {
553556
}
554557

555558
# ── Use case selection ────────────────────────────────────────────────────
556-
Write-Host ""
557-
Write-Host "==============================================="
558-
Write-Host "Available Use Cases:"
559-
Write-Host "==============================================="
560-
Write-Host "1. RFP Evaluation"
561-
Write-Host "2. Retail Customer Satisfaction"
562-
Write-Host "3. HR Employee Onboarding"
563-
Write-Host "4. Marketing Press Release"
564-
Write-Host "5. Contract Compliance Review"
565-
Write-Host "6. Content Generation"
566-
Write-Host "7. All"
567-
Write-Host "==============================================="
568-
Write-Host ""
559+
$useCaseLabels = @{
560+
"1" = "RFP Evaluation"
561+
"2" = "Retail Customer Satisfaction"
562+
"3" = "HR Employee Onboarding"
563+
"4" = "Marketing Press Release"
564+
"5" = "Contract Compliance Review"
565+
"6" = "Content Generation"
566+
"7" = "All"
567+
}
568+
569+
if ($UseCase) {
570+
$useCaseSelection = if ($UseCase -in @("all", "All", "ALL")) { "7" } else { $UseCase }
571+
$selectedUseCase = $useCaseLabels[$useCaseSelection]
572+
Write-Host "Use case pre-selected via -UseCase parameter: $selectedUseCase ($useCaseSelection)"
573+
} elseif ($NonInteractive) {
574+
Write-Host "Error: -UseCase is required when running with -NonInteractive." -ForegroundColor Red
575+
exit 1
576+
} else {
577+
Write-Host ""
578+
Write-Host "==============================================="
579+
Write-Host "Available Use Cases:"
580+
Write-Host "==============================================="
581+
Write-Host "1. RFP Evaluation"
582+
Write-Host "2. Retail Customer Satisfaction"
583+
Write-Host "3. HR Employee Onboarding"
584+
Write-Host "4. Marketing Press Release"
585+
Write-Host "5. Contract Compliance Review"
586+
Write-Host "6. Content Generation"
587+
Write-Host "7. All"
588+
Write-Host "==============================================="
589+
Write-Host ""
569590

570-
do {
571-
$useCaseSelection = Read-Host "Please enter the number of the use case you would like to install (1-7)"
572-
switch ($useCaseSelection) {
573-
"1" { $selectedUseCase = "RFP Evaluation"; $useCaseValid = $true }
574-
"2" { $selectedUseCase = "Retail Customer Satisfaction"; $useCaseValid = $true }
575-
"3" { $selectedUseCase = "HR Employee Onboarding"; $useCaseValid = $true }
576-
"4" { $selectedUseCase = "Marketing Press Release"; $useCaseValid = $true }
577-
"5" { $selectedUseCase = "Contract Compliance Review"; $useCaseValid = $true }
578-
"6" { $selectedUseCase = "Content Generation"; $useCaseValid = $true }
579-
"7" { $selectedUseCase = "All"; $useCaseValid = $true }
580-
"all" { $useCaseSelection = "7"; $selectedUseCase = "All"; $useCaseValid = $true }
581-
default {
582-
$useCaseValid = $false
583-
Write-Host "Invalid selection. Please enter a number from 1-7." -ForegroundColor Red
591+
do {
592+
$useCaseSelection = Read-Host "Please enter the number of the use case you would like to install (1-7)"
593+
switch ($useCaseSelection) {
594+
"1" { $selectedUseCase = "RFP Evaluation"; $useCaseValid = $true }
595+
"2" { $selectedUseCase = "Retail Customer Satisfaction"; $useCaseValid = $true }
596+
"3" { $selectedUseCase = "HR Employee Onboarding"; $useCaseValid = $true }
597+
"4" { $selectedUseCase = "Marketing Press Release"; $useCaseValid = $true }
598+
"5" { $selectedUseCase = "Contract Compliance Review"; $useCaseValid = $true }
599+
"6" { $selectedUseCase = "Content Generation"; $useCaseValid = $true }
600+
"7" { $selectedUseCase = "All"; $useCaseValid = $true }
601+
"all" { $useCaseSelection = "7"; $selectedUseCase = "All"; $useCaseValid = $true }
602+
default {
603+
$useCaseValid = $false
604+
Write-Host "Invalid selection. Please enter a number from 1-7." -ForegroundColor Red
605+
}
584606
}
585-
}
586-
} while (-not $useCaseValid)
607+
} while (-not $useCaseValid)
608+
}
587609

588610
Write-Host ""
589611
Write-Host "==============================================="
@@ -600,9 +622,22 @@ try {
600622
Write-Host ""
601623

602624
# ── Signed-in user principal id (for backend API auth header) ─────────────
603-
$script:userPrincipalId = az ad signed-in-user show --query id -o tsv
625+
# In CI the workflow logs in as a service principal (OIDC), so
626+
# `az ad signed-in-user show` returns nothing. Fall back to an explicit
627+
# USER_PRINCIPAL_ID env var, then to the SP object id looked up via
628+
# AZURE_CLIENT_ID.
629+
if ($env:USER_PRINCIPAL_ID) {
630+
$script:userPrincipalId = $env:USER_PRINCIPAL_ID
631+
Write-Host "Using principal id from USER_PRINCIPAL_ID env var."
632+
} else {
633+
$script:userPrincipalId = az ad signed-in-user show --query id -o tsv 2>$null
634+
if (-not $script:userPrincipalId -and $env:AZURE_CLIENT_ID) {
635+
Write-Host "No interactive user — falling back to service principal object id (AZURE_CLIENT_ID=$($env:AZURE_CLIENT_ID))."
636+
$script:userPrincipalId = az ad sp show --id $env:AZURE_CLIENT_ID --query id -o tsv 2>$null
637+
}
638+
}
604639
if (-not $script:userPrincipalId) {
605-
Write-Host "Error: Could not retrieve signed-in user principal id." -ForegroundColor Red
640+
Write-Host "Error: Could not retrieve signed-in user principal id. In CI, set USER_PRINCIPAL_ID or ensure AZURE_CLIENT_ID is exported and the SP is visible to Microsoft Graph." -ForegroundColor Red
606641
exit 1
607642
}
608643

0 commit comments

Comments
 (0)