Skip to content

Commit f5ee5d6

Browse files
authored
Split roundtrip workflow into phases with auth refresh
1 parent 59c2e7a commit f5ee5d6

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ jobs:
144144
if: success()
145145
uses: azure/login@v2
146146
with:
147+
# Phase 1 can run for a long time while APIM activates; refresh login
148+
# before extract/publish so apiops receives a fresh federated session.
147149
client-id: ${{ secrets.AZURE_CLIENT_ID }}
148150
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
149151
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
@@ -182,4 +184,4 @@ jobs:
182184
-SourceResourceGroup '${{ env.SOURCE_RG }}' `
183185
-TargetResourceGroup '${{ env.TARGET_RG }}' `
184186
-Location '${{ inputs.location }}' `
185-
-HardDelete
187+
-HardDelete $true

tests/integration/all-resource-types/run-roundtrip-phase1-deploy.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ $state = [ordered]@{
215215
}
216216

217217
$stateDir = Split-Path -Parent $StateFile
218-
if (-not [string]::IsNullOrWhiteSpace($stateDir) -and -not (Test-Path $stateDir)) {
219-
New-Item -ItemType Directory -Path $stateDir -Force | Out-Null
218+
if (-not [string]::IsNullOrWhiteSpace($stateDir)) {
219+
New-Item -ItemType Directory -Path $stateDir -Force -ErrorAction SilentlyContinue | Out-Null
220220
}
221221

222222
$state | ConvertTo-Json -Depth 5 | Set-Content -Path $StateFile -Encoding utf8

tests/integration/all-resource-types/run-roundtrip-phase2-roundtrip.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ function Get-ApiopsLogLevel([string]$ScriptLogLevel) {
3939
}
4040

4141
function Get-ApiopsAuthArgs {
42+
# In CI, we explicitly pass client/tenant to apiops so DefaultAzureCredential
43+
# can use the intended federated identity after long-running deploy phases.
44+
# If env vars are unset (local runs), apiops falls back to default credential chain.
4245
$authArgs = @()
4346

4447
if (-not [string]::IsNullOrWhiteSpace($env:AZURE_CLIENT_ID)) {
@@ -121,6 +124,19 @@ $targetAiResourceId = az monitor app-insights component list --resource-group $t
121124
$targetAiKey = az monitor app-insights component list --resource-group $targetRg --query "[0].instrumentationKey" -o tsv
122125
$targetEhNs = az eventhubs namespace list --resource-group $targetRg --query "[0].name" -o tsv
123126

127+
if (-not $targetKvUri) {
128+
Write-Host "❌ Could not resolve target Key Vault URI in $(Protect-ResourceGroupName -Value $targetRg)"
129+
exit 2
130+
}
131+
if (-not $targetAiResourceId -or -not $targetAiKey) {
132+
Write-Host "❌ Could not resolve target Application Insights details in $(Protect-ResourceGroupName -Value $targetRg)"
133+
exit 2
134+
}
135+
if (-not $targetEhNs) {
136+
Write-Host "❌ Could not resolve target Event Hub namespace in $(Protect-ResourceGroupName -Value $targetRg)"
137+
exit 2
138+
}
139+
124140
$targetEhConnStr = az eventhubs namespace authorization-rule keys list `
125141
--resource-group $targetRg `
126142
--namespace-name $targetEhNs `

tests/integration/all-resource-types/run-roundtrip-phase3-teardown.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ param(
1212

1313
[switch]$SkipTeardown,
1414

15-
[switch]$HardDelete = $true
15+
[bool]$HardDelete = $true
1616
)
1717

1818
$ErrorActionPreference = 'Stop'

tests/integration/all-resource-types/run-roundtrip-test.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
.DESCRIPTION
66
Single entry point that orchestrates phase scripts for deploy, round-trip, and
77
teardown. Works both locally and in CI.
8+
9+
.EXAMPLE
10+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com
11+
12+
.EXAMPLE
13+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com -SkipTeardown
14+
15+
.EXAMPLE
16+
.\run-roundtrip-test.ps1 -PublisherEmail admin@contoso.com -HardDelete
817
#>
918

1019
#requires -Version 7.0

0 commit comments

Comments
 (0)