-
Notifications
You must be signed in to change notification settings - Fork 1
Handle revisioned API deletion in --delete-unmatched and add integration coverage
#178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/delete-unmatched-parameter-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+394
−46
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
141 changes: 141 additions & 0 deletions
141
tests/integration/all-resource-types/phases/run-phase6-delete-unmatched.ps1
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
| #requires -Version 7.0 | ||
| <# | ||
| .SYNOPSIS | ||
| Phase 6b - Validate publish --delete-unmatched with revisioned APIs. | ||
| .DESCRIPTION | ||
| Removes a revisioned API from extracted artifacts, runs publish with | ||
| --delete-unmatched, and verifies the revisioned API resources are deleted | ||
| from the target APIM instance. | ||
| #> | ||
|
|
||
| [CmdletBinding()] | ||
| param( | ||
| [string]$TargetSubscriptionId, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$TargetResourceGroup, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$TargetApimName, | ||
|
|
||
| [ValidateSet('Info', 'Verbose', 'Debug')] | ||
| [string]$LogLevel = 'Verbose', | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$OverrideFile, | ||
|
|
||
| [string]$ExtractOutputDir = "$PSScriptRoot/extracted-artifacts" | ||
| ) | ||
|
|
||
| $ErrorActionPreference = 'Stop' | ||
| $VerbosePreference = if ($LogLevel -in @('Verbose', 'Debug')) { 'Continue' } else { 'SilentlyContinue' } | ||
| $DebugPreference = if ($LogLevel -eq 'Debug') { 'Continue' } else { 'SilentlyContinue' } | ||
|
|
||
| $phaseRoot = Split-Path $PSScriptRoot -Parent | ||
| $maskingModule = Join-Path $phaseRoot 'modules/LogMasking.psm1' | ||
| $scriptArgModule = Join-Path $phaseRoot 'modules/ScriptRuntime.psm1' | ||
| $apiopsCliModule = Join-Path $phaseRoot 'modules/ApiopsCli.psm1' | ||
|
|
||
| foreach ($requiredFile in @($maskingModule, $scriptArgModule, $apiopsCliModule)) { | ||
| if (-not (Test-Path $requiredFile)) { | ||
| Write-Error "Required file not found: $requiredFile" | ||
| exit 2 | ||
| } | ||
| } | ||
|
|
||
| Import-Module $maskingModule -Force | ||
| Import-Module $scriptArgModule -Force | ||
| Import-Module $apiopsCliModule -Force | ||
|
|
||
| if (-not (Test-Path $ExtractOutputDir)) { | ||
| Write-Error "ExtractOutputDir not found: $ExtractOutputDir" | ||
| exit 2 | ||
| } | ||
|
|
||
| if (-not (Test-Path $OverrideFile)) { | ||
| Write-Error "OverrideFile not found: $OverrideFile" | ||
| exit 2 | ||
| } | ||
|
|
||
| $targetSubscriptionIdValue = Get-BoundParameterValueOrNull -BoundParameters $PSBoundParameters -Name 'TargetSubscriptionId' | ||
| $apiopsLogLevel = Get-ApiopsLogLevel -ScriptLogLevel $LogLevel | ||
| $apiopsAuthArgs = Get-ApiopsAuthArgs | ||
|
|
||
| $apiFoldersToRemove = @( | ||
| 'src-rest-revisioned', | ||
| 'src-rest-revisioned;rev=2' | ||
| ) | ||
|
|
||
| Write-Host "🧪 Delete-unmatched — remove revisioned API artifacts" | ||
| foreach ($apiFolder in $apiFoldersToRemove) { | ||
| $apiDirectory = Join-Path $ExtractOutputDir "apis/$apiFolder" | ||
| if (-not (Test-Path $apiDirectory)) { | ||
| Write-Error "Expected API artifact directory not found: $apiDirectory" | ||
| exit 2 | ||
| } | ||
|
|
||
| Remove-Item -Path $apiDirectory -Recurse -Force | ||
| Write-Host "Removed artifact directory: $apiDirectory" | ||
| } | ||
|
|
||
| Write-Host "🧪 Delete-unmatched — publish with --delete-unmatched" | ||
| $publishArgs = @( | ||
| 'publish', | ||
| '--resource-group', $TargetResourceGroup, | ||
| '--service-name', $TargetApimName, | ||
| '--source', $ExtractOutputDir, | ||
| '--overrides', $OverrideFile, | ||
| '--delete-unmatched', | ||
| '--log-level', $apiopsLogLevel | ||
| ) | ||
| if (-not [string]::IsNullOrWhiteSpace($targetSubscriptionIdValue)) { | ||
| $publishArgs += @('--subscription-id', $targetSubscriptionIdValue) | ||
| } | ||
| $publishArgs += $apiopsAuthArgs | ||
|
|
||
| $replacements = @{ | ||
| $TargetResourceGroup = Protect-ResourceGroupName -Value $TargetResourceGroup | ||
| $TargetApimName = Protect-ApimName -Value $TargetApimName | ||
| $OverrideFile = '.overrides.yaml' | ||
| } | ||
| Add-ArgumentIfSet -Hashtable $replacements -Key $targetSubscriptionIdValue -Value (Protect-SubscriptionId -Value $targetSubscriptionIdValue) | ||
|
|
||
| $publishExitCode = Invoke-MaskedApiopsCommand -Replacements $replacements -Arguments $publishArgs | ||
| if ($publishExitCode -ne 0) { | ||
| Write-Error "Publish with --delete-unmatched failed (exit code $publishExitCode)" | ||
| exit 2 | ||
| } | ||
|
|
||
| Write-Host "🧪 Delete-unmatched — verify APIs are deleted from target APIM" | ||
| foreach ($apiId in $apiFoldersToRemove) { | ||
| $listArgs = @( | ||
| 'apim', 'api', 'list', | ||
| '--resource-group', $TargetResourceGroup, | ||
| '--service-name', $TargetApimName, | ||
| '--query', "[?name=='$apiId'].name", | ||
| '--output', 'tsv' | ||
| ) | ||
| if (-not [string]::IsNullOrWhiteSpace($targetSubscriptionIdValue)) { | ||
| $listArgs += @('--subscription', $targetSubscriptionIdValue) | ||
| } | ||
|
|
||
| $existingApiNames = Invoke-MaskedAzCommand -Replacements $replacements -Arguments $listArgs | ||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Error "Failed to query APIs for validation (api-id: $apiId)" | ||
| exit 2 | ||
| } | ||
|
|
||
| $apiNameMatches = $existingApiNames -split '[\r\n]+' | | ||
| ForEach-Object { $_.Trim() } | | ||
| Where-Object { -not [string]::IsNullOrWhiteSpace($_) -and $_ -eq $apiId } | ||
|
|
||
| if ($apiNameMatches) { | ||
| Write-Error "API still exists after delete-unmatched publish: $apiId" | ||
| exit 2 | ||
| } | ||
| } | ||
|
|
||
| Write-Host "✅ Delete-unmatched validation passed for revisioned API cleanup" | ||
| exit 0 |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name 'Phase 7', not 'Phase '6b'. Update numbers of subsequent phases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in f4e93d9. Delete-unmatched is now labeled Phase 7, teardown is Phase 8, and subsequent references were renumbered across workflow, round-trip orchestrator, phase scripts, and integration README.