diff --git a/.github/actions/templates/avm-publishModule/action.yml b/.github/actions/templates/avm-publishModule/action.yml index 7192a29073..b2470500de 100644 --- a/.github/actions/templates/avm-publishModule/action.yml +++ b/.github/actions/templates/avm-publishModule/action.yml @@ -67,8 +67,10 @@ runs: Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose if($publishOutputs = Publish-ModuleFromPathToPBR @functionInput -Verbose) { - Write-Output ('{0}={1}' -f 'version', $publishOutputs.version) >> $env:GITHUB_OUTPUT - Write-Output ('{0}={1}' -f 'publishedModuleName', $publishOutputs.publishedModuleName) >> $env:GITHUB_OUTPUT + $publishOutputs.Keys | Foreach-Object { + Write-Verbose ('Passing pipeline variable [{0}] with value [{1}]' -f $_, $publishOutputs.$_) -Verbose + Write-Output ('{0}={1}' -f $_, $publishOutputs.$_) >> $env:GITHUB_OUTPUT + } } Write-Output '::endgroup::' @@ -88,6 +90,7 @@ runs: $functionInput = @{ Version = "${{ steps.publish_step.outputs.version }}" PublishedModuleName = "${{ steps.publish_step.outputs.publishedModuleName }}" + GitTagName = "${{ steps.publish_step.outputs.gitTagName }}" } Write-Verbose "Invoke function with" -Verbose diff --git a/avm/utilities/pipelines/publish/Confirm-ModuleIsPublished.ps1 b/avm/utilities/pipelines/publish/Confirm-ModuleIsPublished.ps1 index 22b8045560..645b5adc91 100644 --- a/avm/utilities/pipelines/publish/Confirm-ModuleIsPublished.ps1 +++ b/avm/utilities/pipelines/publish/Confirm-ModuleIsPublished.ps1 @@ -11,6 +11,9 @@ Mandatory. The version of the module to check for. For example: '0.2.0' .PARAMETER PublishedModuleName Mandatory. The path of the module to check for. For example: 'avm/res/key-vault/vault' +.PARAMETER GitTagName +Mandatory. The tag name of the module's git tag to check for. For example: 'avm/res/event-hub/namespace/0.2.0' + .EXAMPLE Confirm-ModuleIsPublished -Version '0.2.0' -PublishedModuleName 'avm/res/key-vault/vault' -Verbose @@ -24,7 +27,10 @@ function Confirm-ModuleIsPublished { [string] $Version, [Parameter(Mandatory)] - [string] $PublishedModuleName + [string] $PublishedModuleName, + + [Parameter(Mandatory)] + [string] $GitTagName ) $baseUrl = 'https://mcr.microsoft.com/v2' @@ -36,6 +42,16 @@ function Confirm-ModuleIsPublished { $retry_seconds = 60 $index = 0 + ####################################### + ## Confirm module tag is created ## + ####################################### + $existingTag = git ls-remote --tags origin $GitTagName + if (-not $existingTag) { + throw "Tag [$GitTagName] was not successfully created. Please review." + } else { + Write-Verbose "Passed: Found Git tag [$GitTagName]" -Verbose + } + ##################################### ## Confirm module is published ## ##################################### diff --git a/avm/utilities/pipelines/publish/Publish-ModuleFromPathToPBR.ps1 b/avm/utilities/pipelines/publish/Publish-ModuleFromPathToPBR.ps1 index d66f55502f..9767b14faf 100644 --- a/avm/utilities/pipelines/publish/Publish-ModuleFromPathToPBR.ps1 +++ b/avm/utilities/pipelines/publish/Publish-ModuleFromPathToPBR.ps1 @@ -61,10 +61,10 @@ function Publish-ModuleFromPathToPBR { $publishedModuleName = Get-BRMRepositoryName -TemplateFilePath $TemplateFilePath # 4.Create release tag - $tagName = New-ModuleReleaseTag -ModuleFolderPath $moduleFolderPath -TargetVersion $targetVersion + $gitTagName = New-ModuleReleaseTag -ModuleFolderPath $moduleFolderPath -TargetVersion $targetVersion # 5. Get the documentation link - $documentationUri = Get-ModuleReadmeLink -TagName $tagName -ModuleFolderPath $moduleFolderPath + $documentationUri = Get-ModuleReadmeLink -TagName $gitTagName -ModuleFolderPath $moduleFolderPath # 6. Replace telemetry version value (in Bicep) $tokenConfiguration = @{ @@ -108,5 +108,6 @@ function Publish-ModuleFromPathToPBR { return @{ version = $targetVersion publishedModuleName = $publishedModuleName + gitTagName = $gitTagName } } diff --git a/avm/utilities/pipelines/publish/helper/New-ModuleReleaseTag.ps1 b/avm/utilities/pipelines/publish/helper/New-ModuleReleaseTag.ps1 index a1d1f8ab23..d8bfe0b8cc 100644 --- a/avm/utilities/pipelines/publish/helper/New-ModuleReleaseTag.ps1 +++ b/avm/utilities/pipelines/publish/helper/New-ModuleReleaseTag.ps1 @@ -38,16 +38,16 @@ function New-ModuleReleaseTag { $wellFormattedTag = git check-ref-format --normalize $tagName if (-not $wellFormattedTag) { throw "Tag [$tagName] is not well formatted." - # TODO: Handle exception if tag not formatted correctly } # 3 Check tag not already existing $existingTag = git ls-remote --tags origin $tagName if ($existingTag) { - throw "Tag [$tagName] already exists" - # TODO: Handle exception if tag already existing + Write-Verbose "Tag [$tagName] already exists" -Verbose + return $tagName } + # 3 Create local tag Write-Verbose "Creating release tag: [$tagName]" -Verbose git tag $tagName @@ -56,6 +56,10 @@ function New-ModuleReleaseTag { Write-Verbose "Publishing release tag: [$tagName]" -Verbose git push origin $tagName + if ($LASTEXITCODE -ne 0) { + throw 'Git Tag creation failed. Please review error log.' + } + # 5 Return tag return $tagName }