Skip to content

Commit

Permalink
feat: Added Bicep CLI version check to Set-AVMModule utility (Azure…
Browse files Browse the repository at this point in the history
…#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

<!-- Insert your Pipeline Status Badge below -->

| 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 <[email protected]>
  • Loading branch information
2 people authored and hundredacres committed Mar 12, 2024
1 parent b1df829 commit cadc7a6
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion avm/utilities/tools/Set-AVMModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -69,6 +72,9 @@ function Set-AVMModule {
[Parameter(Mandatory = $false)]
[switch] $SkipFileAndFolderSetup,

[Parameter(Mandatory = $false)]
[switch] $SkipVersionCheck,

[Parameter(Mandatory = $false)]
[int] $ThrottleLimit = 5,

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit cadc7a6

Please sign in to comment.