From cb23b8813f0b92ab04e4a28f46436134b751e3ca Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Tue, 21 Jan 2025 11:02:22 +0000 Subject: [PATCH 1/2] feat: requirements --- README.md | 35 +--- src/ALZ/ALZ.psd1 | 13 +- src/ALZ/Private/Tools/Test-Tooling.ps1 | 111 ++++++++++++ ...Environment.ps1 => Deploy-Accelerator.ps1} | 7 +- src/ALZ/Public/Edit-LineEnding.ps1 | 43 ----- src/ALZ/Public/Test-ALZRequirement.ps1 | 97 ---------- .../Public/Test-AcceleratorRequirement.ps1 | 20 +++ src/PSScriptAnalyzerSettings.psd1 | 5 - .../Private/Test-ALZRequirement.Tests.ps1 | 135 -------------- ...Tests.ps1 => Deploy-Accelerator.Tests.ps1} | 4 +- .../Unit/Public/Edit-LineEnding.Tests.ps1 | 166 ------------------ .../Unit/Public/Test-ALZRequirement.Tests.ps1 | 135 -------------- 12 files changed, 149 insertions(+), 622 deletions(-) create mode 100644 src/ALZ/Private/Tools/Test-Tooling.ps1 rename src/ALZ/Public/{New-ALZEnvironment.ps1 => Deploy-Accelerator.ps1} (98%) delete mode 100644 src/ALZ/Public/Edit-LineEnding.ps1 delete mode 100644 src/ALZ/Public/Test-ALZRequirement.ps1 create mode 100644 src/ALZ/Public/Test-AcceleratorRequirement.ps1 delete mode 100644 src/Tests/Unit/Private/Test-ALZRequirement.Tests.ps1 rename src/Tests/Unit/Public/{New-ALZEnvironment.Tests.ps1 => Deploy-Accelerator.Tests.ps1} (96%) delete mode 100644 src/Tests/Unit/Public/Edit-LineEnding.Tests.ps1 delete mode 100644 src/Tests/Unit/Public/Test-ALZRequirement.Tests.ps1 diff --git a/README.md b/README.md index 8f81dcd6..6d7557f3 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,11 @@ ## Introduction -TLDR: Head straight over to our [Quick Start](https://github.com/Azure/ALZ-PowerShell-Module/wiki/%5BUser-Guide%5D-Quick-Start) to get going now. - This repository contains the PowerShell module and documentation for the Azure landing zones Accelerators for Bicep and Terraform. The accelerators are an opinionated implementation of the Azure Landing Zones Terraform modules, with Azure DevOps or GitHub bootstrapping. It is designed to be used as a template to enable you to get started quickly deploying ALZ with Bicep or Terraform. -Please refer to our [Wiki](https://github.com/Azure/ALZ-PowerShell-Module/wiki) for detailed features and usage instructions. +Please refer to our [Docs](https://aka.ms/alz/acc) for detailed features and usage instructions. ## Quick Start @@ -24,35 +22,18 @@ To get going right now, run these PowerShell steps: ```pwsh Install-Module -Name ALZ -Deploy-Accelerator -``` - -## More Examples - -Here are more examples with different options: - -### Azure Landing Zone Environment with Bicep and GitHub Actions Workflows - -```powershell -Deploy-Accelerator -o -i "bicep" -b "alz_github" +Deploy-Accelerator -inputs "inputs.yaml" ``` -### Azure Landing Zone Environment with Bicep and Azure DevOps Pipelines +## Software Requirements -```powershell -Deploy-Accelerator -o -i "bicep" -b "alz_azuredevops" -``` - -### Azure Landing Zone Environment with Terraform and GitHub Pipelines - -```powershell -Deploy-Accelerator -o -i "terraform" -b "alz_github" -``` +You can see the software requirements for the ALZ Accelerators in the [Phase 1 Docs](https://aka.ms/alz/acc/phase1). -### Azure Landing Zone Environment with Terraform and Azure DevOps Pipelines +To check the requirements, run these commands: -```powershell -Deploy-Accelerator -o -i "terraform" -b "alz_azuredevops" +```pwsh +Install-Module -Name ALZ +Test-AcceleratorRequirements ``` ## Contributing diff --git a/src/ALZ/ALZ.psd1 b/src/ALZ/ALZ.psd1 index 6b611903..0f0f27b7 100644 --- a/src/ALZ/ALZ.psd1 +++ b/src/ALZ/ALZ.psd1 @@ -72,9 +72,8 @@ # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( - 'New-ALZEnvironment' - 'Test-ALZRequirement' - 'Edit-LineEnding' + 'Test-AcceleratorRequirement', + 'Deploy-Accelerator' ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. @@ -84,10 +83,7 @@ VariablesToExport = '*' # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @( - 'Edit-LineEndings' - 'Deploy-Accelerator' - ) + AliasesToExport = @() # DSC resources to export from this module # DscResourcesToExport = @() @@ -142,7 +138,4 @@ # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' - } - - diff --git a/src/ALZ/Private/Tools/Test-Tooling.ps1 b/src/ALZ/Private/Tools/Test-Tooling.ps1 new file mode 100644 index 00000000..3ddc4156 --- /dev/null +++ b/src/ALZ/Private/Tools/Test-Tooling.ps1 @@ -0,0 +1,111 @@ +function Test-Tooling { + $checkResults = @() + $hasFailure = $false + + # Check if PowerShell is the correct version + Write-Verbose "Checking PowerShell version" + $powerShellVersionTable = $PSVersionTable + $powerShellVersion = $powerShellVersionTable.PSVersion.ToString() + if ($powerShellVersionTable.PSVersion.Major -lt 7) { + $checkResults += @{ + 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" + result = "Failure" + } + $hasFailure = $true + } elseif ($powerShellVersionTable.PSVersion.Major -eq 7 -and $powerShellVersionTable.PSVersion.Minor -lt 4) { + $checkResults += @{ + 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" + result = "Failure" + } + $hasFailure = $true + } else { + $checkResults += @{ + message = "PowerShell version $powerShellVersion is supported." + result = "Success" + } + } + + # Check if Git is installed + Write-Verbose "Checking Git installation" + $gitPath = Get-Command git -ErrorAction SilentlyContinue + if ($gitPath) { + $checkResults += @{ + message = "Git is installed." + result = "Success" + } + } else { + $checkResults += @{ + message = "Git is not installed. Follow the instructions here: https://git-scm.com/downloads" + result = "Failure" + } + $hasFailure = $true + } + + # Check if Azure CLI is installed + Write-Verbose "Checking Azure CLI installation" + $azCliPath = Get-Command az -ErrorAction SilentlyContinue + if ($azCliPath) { + $checkResults += @{ + message = "Azure CLI is installed." + result = "Success" + } + } else { + $checkResults += @{ + message = "Azure CLI is not installed. Follow the instructions here: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli" + result = "Failure" + } + $hasFailure = $true + } + + # Check if Azure CLI is logged in + Write-Verbose "Checking Azure CLI login status" + $azCliAccount = $(az account show -o json) | ConvertFrom-Json + if ($azCliAccount) { + $checkResults += @{ + message = "Azure CLI is logged in. Tenant ID: $($azCliAccount.tenantId), Subscription: $($azCliAccount.name) ($($azCliAccount.id))" + result = "Success" + } + } else { + $checkResults += @{ + 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." + result = "Failure" + } + $hasFailure = $true + } + + # Check if latest ALZ module is installed + Write-Verbose "Checking ALZ module version" + $alzModuleCurrentVersion = Get-InstalledModule -Name ALZ + $alzModuleLatestVersion = Find-Module -Name ALZ + if ($alzModuleCurrentVersion.Version -lt $alzModuleLatestVersion.Version) { + $checkResults += @{ + 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'." + result = "Failure" + } + $hasFailure = $true + } else { + $checkResults += @{ + message = "ALZ module is the latest version ($($alzModuleCurrentVersion.Version))." + result = "Success" + } + } + + Write-Verbose "Showing check results" + $checkResults | ForEach-Object {[PSCustomObject]$_} | Format-Table -Property @{ + Label = "Check Result"; Expression = { + switch ($_.result) { + 'Success' { $color = "92"; break } + 'Failure' { $color = "91"; break } + default { $color = "0" } + } + $e = [char]27 + "$e[${color}m$($_.result)${e}[0m" + } + }, @{ Label = "Check Details"; Expression = {$_.message} } -AutoSize -Wrap + + if($hasFailure) { + Write-InformationColored "Accelerator software requirements have no been met, please review and install the missing software." -ForegroundColor Red -InformationAction Continue + Write-InformationColored "Cannot continue with Deployment..." -ForegroundColor Red -InformationAction Continue + throw "Accelerator software requirements have no been met, please review and install the missing software." + } +} diff --git a/src/ALZ/Public/New-ALZEnvironment.ps1 b/src/ALZ/Public/Deploy-Accelerator.ps1 similarity index 98% rename from src/ALZ/Public/New-ALZEnvironment.ps1 rename to src/ALZ/Public/Deploy-Accelerator.ps1 index f5269014..9265cd74 100644 --- a/src/ALZ/Public/New-ALZEnvironment.ps1 +++ b/src/ALZ/Public/Deploy-Accelerator.ps1 @@ -1,4 +1,4 @@ -function New-ALZEnvironment { +function Deploy-Accelerator { <# .SYNOPSIS Deploys an accelerator according to the supplied inputs. @@ -174,6 +174,9 @@ function New-ALZEnvironment { $ProgressPreference = "SilentlyContinue" + Write-InformationColored "Checking the software requirements for the Accelerator..." -ForegroundColor Green -InformationAction Continue + Test-Tooling + Write-InformationColored "Getting ready to deploy the accelerator with you..." -ForegroundColor Green -InformationAction Continue if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) { @@ -366,5 +369,3 @@ function New-ALZEnvironment { return } - -New-Alias -Name "Deploy-Accelerator" -Value "New-ALZEnvironment" diff --git a/src/ALZ/Public/Edit-LineEnding.ps1 b/src/ALZ/Public/Edit-LineEnding.ps1 deleted file mode 100644 index 3df7c6b2..00000000 --- a/src/ALZ/Public/Edit-LineEnding.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -enum LineEndingTypes { - Darwin - Unix - Win -} - -function Edit-LineEnding { - [CmdletBinding(SupportsShouldProcess = $true)] - [OutputType([String[]])] - param ( - [Parameter(ValueFromPipeline = $true)] - [String[]]$InputText, - [Parameter()][LineEndingTypes]$LineEnding = "Unix" - ) - - Begin { - - Switch ("$LineEnding".ToLower()) { - "darwin" { $eol = "`r" } - "unix" { $eol = "`n" } - "win" { $eol = "`r`n" } - } - - } - - Process { - - [String[]]$outputText += $InputText | - ForEach-Object { $_ -replace "`r`n", "`n" } | - ForEach-Object { $_ -replace "`r", "`n" } | - ForEach-Object { $_ -replace "`n", "$eol" } - - } - - End { - - return $outputText - - } - -} - -New-Alias -Name "Edit-LineEndings" -Value "Edit-LineEnding" \ No newline at end of file diff --git a/src/ALZ/Public/Test-ALZRequirement.ps1 b/src/ALZ/Public/Test-ALZRequirement.ps1 deleted file mode 100644 index c244b7f5..00000000 --- a/src/ALZ/Public/Test-ALZRequirement.ps1 +++ /dev/null @@ -1,97 +0,0 @@ -function Test-ALZRequirement { - <# - .SYNOPSIS - Test that the ALZ software requirements are met - .DESCRIPTION - This will check for the following software: - - PowerShell 7.1 or higher - - Git - - Azure PowerShell module - .EXAMPLE - C:\PS> Test-ALZRequirements - .EXAMPLE - C:\PS> Test-ALZRequirements -Verbose - .OUTPUTS - Boolean - True if all requirements are met, false if not. - .NOTES - This function is used by the ALZ build script to ensure that the software requirements are met before attempting to - build the ALZ environment. - .COMPONENT - ALZ - #> - [CmdletBinding()] - param ( - [Parameter(Mandatory = $false)] - [ValidateSet("bicep", "terraform")] - [Alias("Iac")] - [Alias("i")] - [string] $alzIacProvider = "bicep" - ) - - $result = $true - # Check if PowerShell is the corrrect version - if ((Get-PSVersion).PSVersion.Major -lt 7) { - Write-Error "PowerShell version $psMajorVersion.$psMinorVersion is not supported. Please upgrade to PowerShell 7.1 or higher." - $result = $false - } elseif ((Get-PSVersion).PSVersion.Major -eq 7 -and (Get-PSVersion).PSVersion.Minor -lt 1) { - Write-Error "PowerShell version $psMajorVersion.$psMinorVersion is not supported. Please upgrade to PowerShell 7.1 or higher." - $result = $false - } else { - Write-Verbose "PowerShell version $psMajorVersion.$psMinorVersion is supported." - } - - if ($alzIacProvider -eq "terraform") { - # Check if Azure CLI is installed - $azCliPath = Get-Command az -ErrorAction SilentlyContinue - if ($azCliPath) { - Write-Verbose "Azure CLI is installed." - } else { - Write-Error "Azure CLI is not installed. Please install Azure CLI." - $result = $false - } - } - - if ($alzIacProvider -eq "bicep") { - # Check if Git is installed - $gitPath = Get-Command git -ErrorAction SilentlyContinue - if ($gitPath) { - Write-Verbose "Git is installed." - } else { - Write-Error "Git is not installed. Please install Git." - $result = $false - } - - # Check if VS Code is installed - $vsCodePath = Get-Command code -ErrorAction SilentlyContinue - if ($vsCodePath) { - Write-Verbose "Visual Studio Code is installed." - } else { - Write-Error "Visual Studio Code is not installed. Please install Visual Studio Code." - $result = $false - } - # Check if Bicep is installed - $bicepPath = Get-Command bicep -ErrorAction SilentlyContinue - if ($bicepPath) { - Write-Verbose "Bicep is installed." - } else { - Write-Error "Bicep is not installed. Please install Bicep." - $result = $false - } - # Check if AZ PowerShell module is the correct version - $azModule = Get-AZVersion - if ($azModule.Version.Major -lt 10) { - Write-Error "Az module version $($azModule.Version) is not supported. Please Upgrade to AZ module version 10.0.0 or higher." - $result = $false - } else { - Write-Verbose "Az module version is supported." - } - } - if ($result) { - return "ALZ requirements are met." - } else { - return "ALZ requirements are not met." - } -} - - - diff --git a/src/ALZ/Public/Test-AcceleratorRequirement.ps1 b/src/ALZ/Public/Test-AcceleratorRequirement.ps1 new file mode 100644 index 00000000..24f12797 --- /dev/null +++ b/src/ALZ/Public/Test-AcceleratorRequirement.ps1 @@ -0,0 +1,20 @@ +function Test-AcceleratorRequirement { + <# + .SYNOPSIS + Test that the Accelerator software requirements are met + .DESCRIPTION + This will check for the pre-requisite software + .EXAMPLE + C:\PS> Test-AcceleratorRequirement + .EXAMPLE + C:\PS> Test-AcceleratorRequirement -Verbose + .OUTPUTS + Boolean - True if all requirements are met, false if not. + .NOTES + This function is used by the Deploy-Accelerator function to ensure that the software requirements are met before attempting run the Accelerator. + .COMPONENT + ALZ + #> + + Test-Tooling +} diff --git a/src/PSScriptAnalyzerSettings.psd1 b/src/PSScriptAnalyzerSettings.psd1 index cf51f490..90f2ac2b 100644 --- a/src/PSScriptAnalyzerSettings.psd1 +++ b/src/PSScriptAnalyzerSettings.psd1 @@ -58,9 +58,4 @@ # } #} #________________________________________ - 'Rules' = @{ - 'PSAvoidUsingCmdletAliases' = @{ - 'allowlist' = @('Edit-LineEndings','Deploy-Accelerator') - } - } } diff --git a/src/Tests/Unit/Private/Test-ALZRequirement.Tests.ps1 b/src/Tests/Unit/Private/Test-ALZRequirement.Tests.ps1 deleted file mode 100644 index 049ea97d..00000000 --- a/src/Tests/Unit/Private/Test-ALZRequirement.Tests.ps1 +++ /dev/null @@ -1,135 +0,0 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'ALZ' -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - -InModuleScope 'ALZ' { - Describe 'Test-ALZRequirement Public Function Tests' -Tag Unit { - BeforeAll { - $WarningPreference = 'SilentlyContinue' - $ErrorActionPreference = 'SilentlyContinue' - } - Context 'Incompatible Az module version lower than 10.0.0' { - BeforeEach { - Mock -CommandName Get-AZVersion -MockWith { - [PSCustomObject]@{ - Version = [PSCustomObject]@{ - Major = 9 - Minor = 7 - } - } - } - } - It 'should return the not met for non compatible az module versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Incompatible Powershell version lower than 7' { - BeforeEach { - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 6 - Minor = 2 - } - } - } - } - It 'should return the not met for non compatible pwsh versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Incompatible Powershell version 7.0' { - BeforeEach { - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 7 - Minor = 0 - } - } - } - } - It 'should return the not met for non compatible pwsh versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Git not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'git' } -MockWith { - $null - } - } - It 'should return the not met for no git installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Visual Studio Code not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'code' } -MockWith { - $null - } - } - It 'should return the not met for no Visual Studio Code installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Bicep not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'bicep' } -MockWith { - $null - } - } - It 'should return the not met for no bicep installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Success' { - BeforeEach { - Mock -CommandName Get-AZVersion -MockWith { - [PSCustomObject]@{ - Version = [PSCustomObject]@{ - Major = 10 - Minor = 0 - } - } - } - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 7 - Minor = 1 - } - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'git' } -MockWith { - [PSCustomObject]@{ - Name = 'git' - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'code' } -MockWith { - [PSCustomObject]@{ - Name = 'code' - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'bicep' } -MockWith { - [PSCustomObject]@{ - Name = 'bicep' - } - } - } - - It 'should return the expected results' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are met." - } - } - } -} diff --git a/src/Tests/Unit/Public/New-ALZEnvironment.Tests.ps1 b/src/Tests/Unit/Public/Deploy-Accelerator.Tests.ps1 similarity index 96% rename from src/Tests/Unit/Public/New-ALZEnvironment.Tests.ps1 rename to src/Tests/Unit/Public/Deploy-Accelerator.Tests.ps1 index 3e671d3d..3a8df374 100644 --- a/src/Tests/Unit/Public/New-ALZEnvironment.Tests.ps1 +++ b/src/Tests/Unit/Public/Deploy-Accelerator.Tests.ps1 @@ -12,7 +12,7 @@ Import-Module $PathToManifest -Force #------------------------------------------------------------------------- InModuleScope 'ALZ' { - Describe 'New-ALZEnvironment Public Function Tests' -Tag Unit { + Describe 'Deploy-Accelerator Public Function Tests' -Tag Unit { BeforeAll { $WarningPreference = 'SilentlyContinue' $ErrorActionPreference = 'SilentlyContinue' @@ -38,6 +38,8 @@ InModuleScope 'ALZ' { ) } + Mock -CommandName Test-Tooling + Mock -CommandName Edit-ALZConfigurationFilesInPlace Mock -CommandName Copy-Item -MockWith { } diff --git a/src/Tests/Unit/Public/Edit-LineEnding.Tests.ps1 b/src/Tests/Unit/Public/Edit-LineEnding.Tests.ps1 deleted file mode 100644 index eb9ee13f..00000000 --- a/src/Tests/Unit/Public/Edit-LineEnding.Tests.ps1 +++ /dev/null @@ -1,166 +0,0 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'ALZ' -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - -InModuleScope 'ALZ' { - Describe "Edit-LineEnding" { - BeforeAll { - $WarningPreference = 'SilentlyContinue' - $ErrorActionPreference = 'SilentlyContinue' - } - Context "When converting to Unix line endings" { - It "Converts Windows line endings to Unix" { - $inputText = "Hello`r`nWorld`r`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Unix" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - - It "Does not modify Unix line endings" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - } - - Context "When converting to Windows line endings" { - It "Converts Unix line endings to Windows" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Windows" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - - It "Does not modify Windows line endings" { - $inputText = "Hello`r`nWorld`r`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEnding -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - } - - Context "When converting to Darwin line endings" { - It "Converts Unix line endings to Darwin" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEnding -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Darwin" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEnding -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - - It "Does not modify Darwin line endings" { - $inputText = "Hello`rWorld`r" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEnding -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - } - - - } - - Describe "Edit-LineEndings (Alias)" { - BeforeAll { - $WarningPreference = 'SilentlyContinue' - $ErrorActionPreference = 'SilentlyContinue' - } - Context "When converting to Unix line endings (Alias)" { - It "Converts Windows line endings to Unix" { - $inputText = "Hello`r`nWorld`r`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Unix (Alias)" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - - It "Does not modify Unix line endings (Alias)" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`nWorld`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Unix - $result | Should -Be $expectedOutput - } - } - - Context "When converting to Windows line endings (Alias)" { - It "Converts Unix line endings to Windows" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Windows (Alias)" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - - It "Does not modify Windows line endings (Alias)" { - $inputText = "Hello`r`nWorld`r`n" - $expectedOutput = "Hello`r`nWorld`r`n" - $result = Edit-LineEndings -InputText $inputText -LineEnding Win - $result | Should -Be $expectedOutput - } - } - - Context "When converting to Darwin line endings (Alias)" { - It "Converts Unix line endings to Darwin" { - $inputText = "Hello`nWorld`n" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEndings -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - - It "Converts mixed line endings to Darwin (Alias)" { - $inputText = "Hello`rWorld`n" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEndings -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - - It "Does not modify Darwin line endings (Alias)" { - $inputText = "Hello`rWorld`r" - $expectedOutput = "Hello`rWorld`r" - $result = Edit-LineEndings -InputText $inputText -LineEnding Darwin - $result | Should -Be $expectedOutput - } - } - } -} \ No newline at end of file diff --git a/src/Tests/Unit/Public/Test-ALZRequirement.Tests.ps1 b/src/Tests/Unit/Public/Test-ALZRequirement.Tests.ps1 deleted file mode 100644 index 049ea97d..00000000 --- a/src/Tests/Unit/Public/Test-ALZRequirement.Tests.ps1 +++ /dev/null @@ -1,135 +0,0 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'ALZ' -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - -InModuleScope 'ALZ' { - Describe 'Test-ALZRequirement Public Function Tests' -Tag Unit { - BeforeAll { - $WarningPreference = 'SilentlyContinue' - $ErrorActionPreference = 'SilentlyContinue' - } - Context 'Incompatible Az module version lower than 10.0.0' { - BeforeEach { - Mock -CommandName Get-AZVersion -MockWith { - [PSCustomObject]@{ - Version = [PSCustomObject]@{ - Major = 9 - Minor = 7 - } - } - } - } - It 'should return the not met for non compatible az module versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Incompatible Powershell version lower than 7' { - BeforeEach { - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 6 - Minor = 2 - } - } - } - } - It 'should return the not met for non compatible pwsh versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Incompatible Powershell version 7.0' { - BeforeEach { - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 7 - Minor = 0 - } - } - } - } - It 'should return the not met for non compatible pwsh versions' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Git not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'git' } -MockWith { - $null - } - } - It 'should return the not met for no git installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Visual Studio Code not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'code' } -MockWith { - $null - } - } - It 'should return the not met for no Visual Studio Code installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Bicep not installed' { - BeforeEach { - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'bicep' } -MockWith { - $null - } - } - It 'should return the not met for no bicep installation' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are not met." - } - } - Context 'Success' { - BeforeEach { - Mock -CommandName Get-AZVersion -MockWith { - [PSCustomObject]@{ - Version = [PSCustomObject]@{ - Major = 10 - Minor = 0 - } - } - } - Mock -CommandName Get-PSVersion -MockWith { - [PSCustomObject]@{ - PSVersion = [PSCustomObject]@{ - Major = 7 - Minor = 1 - } - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'git' } -MockWith { - [PSCustomObject]@{ - Name = 'git' - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'code' } -MockWith { - [PSCustomObject]@{ - Name = 'code' - } - } - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'bicep' } -MockWith { - [PSCustomObject]@{ - Name = 'bicep' - } - } - } - - It 'should return the expected results' { - Test-ALZRequirement | Should -BeExactly "ALZ requirements are met." - } - } - } -} From b2ae500f6481efa55371d9bb7137de222c8d0eaa Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Tue, 21 Jan 2025 11:25:55 +0000 Subject: [PATCH 2/2] Add param to skip checks --- src/ALZ/Public/Deploy-Accelerator.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ALZ/Public/Deploy-Accelerator.ps1 b/src/ALZ/Public/Deploy-Accelerator.ps1 index 9265cd74..77a0ac4b 100644 --- a/src/ALZ/Public/Deploy-Accelerator.ps1 +++ b/src/ALZ/Public/Deploy-Accelerator.ps1 @@ -169,13 +169,25 @@ function Deploy-Accelerator { )] [Alias("tj")] [Alias("convertTfvarsToJson")] - [switch] $convert_tfvars_to_json + [switch] $convert_tfvars_to_json, + + [Parameter( + Mandatory = $false, + HelpMessage = "[OPTIONAL] Determines whether to skip the requirements check. This is not recommended." + )] + [Alias("sr")] + [Alias("skipRequirementsCheck")] + [switch] $skip_requirements_check ) $ProgressPreference = "SilentlyContinue" - Write-InformationColored "Checking the software requirements for the Accelerator..." -ForegroundColor Green -InformationAction Continue - Test-Tooling + if(-not $skip_requirements_check) { + Write-InformationColored "Checking the software requirements for the Accelerator..." -ForegroundColor Green -InformationAction Continue + Test-Tooling + } else { + Write-InformationColored "Skipping the software requirements check..." -ForegroundColor Yellow -InformationAction Continue + } Write-InformationColored "Getting ready to deploy the accelerator with you..." -ForegroundColor Green -InformationAction Continue