Skip to content
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

feat: Implemented post-deployment validation #668

Merged
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
20ac8b7
Added skeleton
AlexanderSehr Nov 7, 2023
4939b4d
Implemented first new tests
AlexanderSehr Nov 7, 2023
4e1d86f
Changed to warning
AlexanderSehr Nov 8, 2023
94fff0b
Expanded test verbosity & added additional tets
AlexanderSehr Nov 8, 2023
c18ce6b
Finalized further tests
AlexanderSehr Nov 8, 2023
a343694
Update to latest
AlexanderSehr Nov 8, 2023
3a6f0a2
Update to latest
AlexanderSehr Nov 8, 2023
4ab6a5b
Added module name + small fix
AlexanderSehr Nov 8, 2023
9bb64bd
Fixed kvlt
AlexanderSehr Nov 8, 2023
68e2bd2
Small caching fix
AlexanderSehr Nov 8, 2023
1a013c2
Small fix and enabled passthru of warnings to GH
AlexanderSehr Nov 8, 2023
1c2fc8a
More updates
AlexanderSehr Nov 8, 2023
d9c6dd5
Update to latest
AlexanderSehr Nov 8, 2023
dd0c343
Updated test names
AlexanderSehr Nov 8, 2023
2ebd458
JSON rollback
AlexanderSehr Nov 8, 2023
f6caf7e
Updated regex
AlexanderSehr Nov 8, 2023
f56f66a
Removed assertion
AlexanderSehr Nov 8, 2023
282b640
Update to latest
AlexanderSehr Nov 8, 2023
c025f52
Update avm/utilities/pipelines/staticValidation/compliance/module.tes…
AlexanderSehr Nov 9, 2023
405901a
Update avm/utilities/pipelines/staticValidation/compliance/module.tes…
AlexanderSehr Nov 9, 2023
904c82f
Merge branch 'main' into users/alsehr/testFileCompliance
AlexanderSehr Nov 9, 2023
ef24d1f
Rollback of unrelated changes
AlexanderSehr Nov 9, 2023
9393aa1
Merge branch 'Azure:main' into main
AlexanderSehr Nov 9, 2023
cb39086
Merge branch 'Azure:main' into main
AlexanderSehr Nov 9, 2023
89eac40
Merge branch 'Azure:main' into main
AlexanderSehr Nov 10, 2023
712a673
Merge branch 'Azure:main' into main
AlexanderSehr Nov 13, 2023
55e095f
Resolved conflict
AlexanderSehr Nov 14, 2023
3121335
Update to latest
AlexanderSehr Nov 14, 2023
e9d736c
Merge branch 'Azure:main' into main
AlexanderSehr Nov 15, 2023
abfa1b9
Merge branch 'Azure:main' into main
AlexanderSehr Nov 15, 2023
c6707f6
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
246f9ba
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
6e9729d
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
26ea9f6
Merge branch 'Azure:main' into main
AlexanderSehr Nov 17, 2023
c2d183b
Merge branch 'Azure:main' into main
AlexanderSehr Nov 18, 2023
0c6650e
Merge branch 'Azure:main' into main
AlexanderSehr Nov 19, 2023
65094a5
Merge branch 'Azure:main' into main
AlexanderSehr Nov 21, 2023
968cd9a
Merge branch 'Azure:main' into main
AlexanderSehr Nov 21, 2023
09b3be5
Added post-validation for publishing
AlexanderSehr Nov 24, 2023
7025728
Enabled publish test
AlexanderSehr Nov 24, 2023
1bb25d3
Disabled pipeline steps for testing
AlexanderSehr Nov 24, 2023
9aca8ca
Shuffled steps
AlexanderSehr Nov 24, 2023
7856aec
Disabled additional steps
AlexanderSehr Nov 24, 2023
d078a04
Update to latest
AlexanderSehr Nov 24, 2023
d665622
Update to latest
AlexanderSehr Nov 24, 2023
3c9589b
Merge branch 'Azure:main' into main
AlexanderSehr Nov 24, 2023
24a7a9a
undid temp test changes
AlexanderSehr Nov 24, 2023
4b88eb0
Update to latest
AlexanderSehr Nov 24, 2023
3abc1a3
Update to latest
AlexanderSehr Nov 24, 2023
02209e3
Merge branch 'main' into users/alsehr/postDeploymentValidation
AlexanderSehr Nov 24, 2023
eb34ddf
Merge branch 'Azure:main' into main
AlexanderSehr Nov 25, 2023
3d4f5c6
Added pipeline to main for testing
AlexanderSehr Nov 26, 2023
70154f3
Merge branch 'Azure:main' into main
AlexanderSehr Nov 27, 2023
18bd2ad
Merge branch 'Azure:main' into main
AlexanderSehr Nov 27, 2023
8aaa784
Merge branch 'main' into users/alsehr/postDeploymentValidation
ChrisSidebotham Nov 28, 2023
940b34f
Merge branch 'Azure:main' into main
AlexanderSehr Nov 28, 2023
1b0cd0b
Merge branch 'main' into users/alsehr/postDeploymentValidation
ChrisSidebotham Nov 29, 2023
fbb840f
Merge branch 'Azure:main' into main
AlexanderSehr Nov 29, 2023
381e366
Merge branch 'Azure:main' into main
AlexanderSehr Nov 29, 2023
768158f
Centralized urls
AlexanderSehr Dec 1, 2023
a336d3d
Merge branch 'main' into users/alsehr/postDeploymentValidation
AlexanderSehr Dec 1, 2023
50ec94e
Update to latest
AlexanderSehr Dec 1, 2023
a905528
Update to latest
AlexanderSehr Dec 1, 2023
d6b3ac9
Merge branch 'main' into users/alsehr/postDeploymentValidation
eriqua Dec 2, 2023
18881b6
Addressed comments
AlexanderSehr Dec 2, 2023
4e3b614
Merge branch 'main' into users/alsehr/postDeploymentValidation
eriqua Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .github/actions/templates/avm-publishModule/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ runs:
bicep --version

- name: "Publish module to public bicep registry"
id: publish_step
uses: azure/powershell@v1
with:
azPSVersion: "latest"
Expand All @@ -68,8 +69,33 @@ runs:
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

# Get the modified child resources
Publish-ModuleFromPathToPBR @functionInput -Verbose
if($publishOutputs = Publish-ModuleFromPathToPBR @functionInput -Verbose) {
Write-Output ('{0}={1}' -f 'version', $publishOutputs.version) >> $env:GITHUB_OUTPUT
Write-Output ('{0}={1}' -f 'module_path', $publishOutputs.module_path) >> $env:GITHUB_OUTPUT
}

Write-Output '::endgroup::'

# TODO Add publish validation (as per PBR pipeline template 'publish-module.yml')
- name: "Validate publish"
uses: azure/powershell@v1
if: ${{ steps.publish_step.outputs.version != '' && steps.publish_step.outputs.module_path != '' }}
with:
azPSVersion: "latest"
inlineScript: |
# Grouping task logs
Write-Output '::group::Validate publish'

# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'pipelines' 'publish' 'Confirm-ModuleIsPublished.ps1')

$functionInput = @{
Version = "${{ steps.publish_step.outputs.version }}"
ModulePath = "${{ steps.publish_step.outputs.module_path }}"
}

Write-Verbose "Invoke function with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

Confirm-ModuleIsPublished @functionInput -Verbose

Write-Output '::endgroup::'
74 changes: 74 additions & 0 deletions avm/utilities/pipelines/publish/Confirm-ModuleIsPublished.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<#
.SYNOPSIS
Check if a module in a given path is published in a given version

.DESCRIPTION
Check if a module in a given path is published in a given version. Tries to find the module for a maximum of 6 minutes.
eriqua marked this conversation as resolved.
Show resolved Hide resolved

.PARAMETER Version
Mandatory. The version of the module to check for. For example: '0.2.0'

.PARAMETER ModulePath
eriqua marked this conversation as resolved.
Show resolved Hide resolved
Mandatory. The path of the module to check for. For example: 'avm/res/key-vault/vault'

.EXAMPLE
Confirm-ModuleIsPublished -Version '0.2.0' -ModulePath 'avm/res/key-vault/vault' -Verbose

Check if module 'key-vault/vault' has been published with version '0.2.0
#>
function Confirm-ModuleIsPublished {

[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $Version,

[Parameter(Mandatory)]
[string] $ModulePath
)

$catalogUrl = 'https://mcr.microsoft.com/v2/_catalog'
$time_limit_seconds = 3600
$end_time = (Get-Date).AddSeconds($time_limit_seconds)
$retry_seconds = 5


while ($true) {
$catalogContentRaw = (Invoke-WebRequest -Uri $catalogUrl -UseBasicParsing).Content
$bicepCatalogContent = ($catalogContentRaw | ConvertFrom-Json).repositories | Select-String 'bicep/'
Write-Verbose ("Bicep modules found in MCR catalog:`n{0}" -f ($bicepCatalogContent | Out-String))

if ($bicepCatalogContent -match "bicep/$ModulePath") {
Write-Verbose "Passed: Found module [$ModulePath] in the MCR catalog" -Verbose
break
} else {
Write-Error "Error: Module [$ModulePath] is not in the MCR catalog. Retrying in [$retry_seconds] seconds"
Start-Sleep -Seconds $retry_seconds
}

if ((Get-Date) -ge $end_time) {
throw "Time limit reached. Failed to validate publish of module in path [$ModulePath] within the specified time."
}
}

while ($true) {
$existingTagsUrl = "https://mcr.microsoft.com/v2/bicep/$ModulePath/tags/list"
AlexanderSehr marked this conversation as resolved.
Show resolved Hide resolved
$tagsContentRaw = (Invoke-WebRequest -Uri $existingTagsUrl -UseBasicParsing).Content
$tagsContent = ($tagsContentRaw | ConvertFrom-Json).tags

Write-Verbose ("Tags for module in path [$ModulePath] found in MCR catalog:`n{0}" -f ($tagsContent | Out-String))

if ($tagsContent -match $Version) {
Write-Host "Passed: Found new tag [$Version] for published module"
break
} else {
Write-Host "Error: Could not find new tag [$Version] for published module. Retrying in [$retry_seconds] seconds"
Start-Sleep -Seconds $retry_seconds
}

if ((Get-Date) -ge $end_time) {
Write-Host 'Time limit reached. Failed to validate publish within the specified time.'
exit 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ function Publish-ModuleFromPathToPBR {
Write-Verbose "Publish Input:`n $($publishInput | ConvertTo-Json -Depth 10)" -Verbose

bicep publish @publishInput

return @{
version = $targetVersion
module_path = $publishedModuleName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Get-ModifiedFileList {
Write-Verbose 'Gathering modified files from the previous head' -Verbose
$Diff = git diff --name-only --diff-filter=AM HEAD^ HEAD
}
$ModifiedFiles = $Diff | Get-Item -Force
$ModifiedFiles = $Diff ? ($Diff | Get-Item -Force) : @()

return $ModifiedFiles
}
Expand Down