From cadc7a6aff69b55c79cc0e29d1cdebe51d8e37b7 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Tue, 5 Mar 2024 23:21:23 +0100 Subject: [PATCH] feat: Added Bicep CLI version check to `Set-AVMModule` utility (#1139) ## Description Added Bicep CLI version check to `Set-AVMModule` utility The output looks similar to: ``` You're not using the latest available Bicep CLI version [0.25.53] but [0.25.3]. You can find the latest release at: https://github.com/Azure/bicep/releases/tag/v0.25.53. On Windows, you can use chocolatey to update the Bicep CLI by running 'choco upgrade bicep'. For other OSs, please refer to the Bicep documentation (https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/install). Note: The 'Bicep CLI' version (bicep --version) is not the same as the 'Azure CLI Bicep extension' version (az bicep version). ``` ## Pipeline Reference | Pipeline | | -------- | | [![avm.res.analysis-services.server](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.analysis-services.server.yml/badge.svg?branch=users%2Falsehr%2FbicepCheck&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.analysis-services.server.yml) | --------- Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- avm/utilities/tools/Set-AVMModule.ps1 | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/avm/utilities/tools/Set-AVMModule.ps1 b/avm/utilities/tools/Set-AVMModule.ps1 index 88cae9c114..1e437aad8d 100644 --- a/avm/utilities/tools/Set-AVMModule.ps1 +++ b/avm/utilities/tools/Set-AVMModule.ps1 @@ -28,7 +28,10 @@ Optional. Set this parameter if you don't want to generate the ReadMe file(s) fo Optional. Set this parameter if you don't want to setup the file & folder structure for the module(s). .PARAMETER ThrottleLimit -Optional. The number of parallel threads to use for the generation. Defaults to 5. +Optional. The number of parallel threads to use for the generation. + +.PARAMETER SkipVersionCheck +Optional. Do not check for the latest Bicep CLI version. .EXAMPLE Set-AVMModule -ModuleFolderPath 'C:\avm\res\key-vault\vault' @@ -69,6 +72,9 @@ function Set-AVMModule { [Parameter(Mandatory = $false)] [switch] $SkipFileAndFolderSetup, + [Parameter(Mandatory = $false)] + [switch] $SkipVersionCheck, + [Parameter(Mandatory = $false)] [int] $ThrottleLimit = 5, @@ -103,6 +109,43 @@ function Set-AVMModule { $relevantTemplatePaths = Join-Path $resolvedPath 'main.bicep' } + if (-not $SkipVersionCheck) { + + # Get latest release from Azure/Bicep repository + # ---------------------------------------------- + $latestReleaseUrl = 'https://api.github.com/repos/azure/bicep/releases/latest' + + $latestReleaseObject = Invoke-RestMethod -Uri $latestReleaseUrl -Method 'GET' + $releaseTag = $latestReleaseObject.tag_name + $latestReleaseVersion = [version]($releaseTag -replace 'v', '') + $latestReleaseUrl = $latestReleaseObject.html_url + + # Get latest installed Bicep CLI version + # -------------------------------------- + $latestInstalledVersionOutput = bicep --version + + if ($latestInstalledVersionOutput -match ' ([0-9]+\.[0-9]+\.[0-9]+) ') { + $latestInstalledVersion = [version]$matches[1] + } + + # Compare the versions + # -------------------- + if ($latestInstalledVersion -ne $latestReleaseVersion) { + Write-Warning """ +You're not using the latest available Bicep CLI version [$latestReleaseVersion] but [$latestInstalledVersion]. +You can find the latest release at: $latestReleaseUrl. + +On Windows, you can use winget to update the Bicep CLI by running 'winget update Microsoft.Bicep' or chocolatey via 'choco upgrade bicep'. +For other OSs, please refer to the Bicep documentation (https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/install). + +Note: The 'Bicep CLI' version (bicep --version) is not the same as the 'Azure CLI Bicep extension' version (az bicep version). +""" + } else { + Write-Verbose "You're using the latest available Bicep CLI version [$latestInstalledVersion]." + } + + } + # Load recurring information we'll need for the modules if (-not $SkipReadMe) { . (Join-Path (Get-Item $PSScriptRoot).Parent.FullName 'pipelines' 'sharedScripts' 'helper' 'Get-CrossReferencedModuleList.ps1')