|
| 1 | +function Test-Tooling { |
| 2 | + $checkResults = @() |
| 3 | + $hasFailure = $false |
| 4 | + |
| 5 | + # Check if PowerShell is the correct version |
| 6 | + Write-Verbose "Checking PowerShell version" |
| 7 | + $powerShellVersionTable = $PSVersionTable |
| 8 | + $powerShellVersion = $powerShellVersionTable.PSVersion.ToString() |
| 9 | + if ($powerShellVersionTable.PSVersion.Major -lt 7) { |
| 10 | + $checkResults += @{ |
| 11 | + message = "PowerShell version $powerShellVersion is not supported. Please upgrade to PowerShell 7.4 or higher. Either switch to the `pwsh` prompt or follow the instructions here: https://aka.ms/install-powershell" |
| 12 | + result = "Failure" |
| 13 | + } |
| 14 | + $hasFailure = $true |
| 15 | + } elseif ($powerShellVersionTable.PSVersion.Major -eq 7 -and $powerShellVersionTable.PSVersion.Minor -lt 4) { |
| 16 | + $checkResults += @{ |
| 17 | + message = "PowerShell version $powerShellVersion is not supported. Please upgrade to PowerShell 7.4 or higher. Either switch to the `pwsh` prompt or follow the instructions here: https://aka.ms/install-powershell" |
| 18 | + result = "Failure" |
| 19 | + } |
| 20 | + $hasFailure = $true |
| 21 | + } else { |
| 22 | + $checkResults += @{ |
| 23 | + message = "PowerShell version $powerShellVersion is supported." |
| 24 | + result = "Success" |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + # Check if Git is installed |
| 29 | + Write-Verbose "Checking Git installation" |
| 30 | + $gitPath = Get-Command git -ErrorAction SilentlyContinue |
| 31 | + if ($gitPath) { |
| 32 | + $checkResults += @{ |
| 33 | + message = "Git is installed." |
| 34 | + result = "Success" |
| 35 | + } |
| 36 | + } else { |
| 37 | + $checkResults += @{ |
| 38 | + message = "Git is not installed. Follow the instructions here: https://git-scm.com/downloads" |
| 39 | + result = "Failure" |
| 40 | + } |
| 41 | + $hasFailure = $true |
| 42 | + } |
| 43 | + |
| 44 | + # Check if Azure CLI is installed |
| 45 | + Write-Verbose "Checking Azure CLI installation" |
| 46 | + $azCliPath = Get-Command az -ErrorAction SilentlyContinue |
| 47 | + if ($azCliPath) { |
| 48 | + $checkResults += @{ |
| 49 | + message = "Azure CLI is installed." |
| 50 | + result = "Success" |
| 51 | + } |
| 52 | + } else { |
| 53 | + $checkResults += @{ |
| 54 | + message = "Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli" |
| 55 | + result = "Failure" |
| 56 | + } |
| 57 | + $hasFailure = $true |
| 58 | + } |
| 59 | + |
| 60 | + # Check if Azure CLI is logged in |
| 61 | + Write-Verbose "Checking Azure CLI login status" |
| 62 | + $azCliAccount = $(az account show -o json) | ConvertFrom-Json |
| 63 | + if ($azCliAccount) { |
| 64 | + $checkResults += @{ |
| 65 | + message = "Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))" |
| 66 | + result = "Success" |
| 67 | + } |
| 68 | + } else { |
| 69 | + $checkResults += @{ |
| 70 | + message = "Azure CLI is not logged in. Please login to Azure CLI using 'az login -t `"00000000-0000-0000-0000-000000000000}`"', replacing the empty GUID with your tenant ID." |
| 71 | + result = "Failure" |
| 72 | + } |
| 73 | + $hasFailure = $true |
| 74 | + } |
| 75 | + |
| 76 | + # Check if latest ALZ module is installed |
| 77 | + Write-Verbose "Checking ALZ module version" |
| 78 | + $alzModuleCurrentVersion = Get-InstalledModule -Name ALZ |
| 79 | + $alzModuleLatestVersion = Find-Module -Name ALZ |
| 80 | + if ($alzModuleCurrentVersion.Version -lt $alzModuleLatestVersion.Version) { |
| 81 | + $checkResults += @{ |
| 82 | + message = "ALZ module is not the latest version. Your version: $($alzModuleCurrentVersion.Version), Latest version: $($alzModuleLatestVersion.Version). Please update to the latest version using 'Update-Module ALZ'." |
| 83 | + result = "Failure" |
| 84 | + } |
| 85 | + $hasFailure = $true |
| 86 | + } else { |
| 87 | + $checkResults += @{ |
| 88 | + message = "ALZ module is the latest version ($($alzModuleCurrentVersion.Version))." |
| 89 | + result = "Success" |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + Write-Verbose "Showing check results" |
| 94 | + $checkResults | ForEach-Object {[PSCustomObject]$_} | Format-Table -Property @{ |
| 95 | + Label = "Check Result"; Expression = { |
| 96 | + switch ($_.result) { |
| 97 | + 'Success' { $color = "92"; break } |
| 98 | + 'Failure' { $color = "91"; break } |
| 99 | + default { $color = "0" } |
| 100 | + } |
| 101 | + $e = [char]27 |
| 102 | + "$e[${color}m$($_.result)${e}[0m" |
| 103 | + } |
| 104 | + }, @{ Label = "Check Details"; Expression = {$_.message} } -AutoSize -Wrap |
| 105 | + |
| 106 | + if($hasFailure) { |
| 107 | + Write-InformationColored "Accelerator software requirements have no been met, please review and install the missing software." -ForegroundColor Red -InformationAction Continue |
| 108 | + Write-InformationColored "Cannot continue with Deployment..." -ForegroundColor Red -InformationAction Continue |
| 109 | + throw "Accelerator software requirements have no been met, please review and install the missing software." |
| 110 | + } |
| 111 | +} |
0 commit comments