-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixing and refactoring for e2e tests (#107)
# Pull Request ## Description This PR is part of the major refactoring work to de-couple the bootstrap and support bicep automation. The fixes and refactoring in this branch were designed to make the e2e tests pass successfully. You can see the successful test run for this branch here: - PR: Azure/accelerator-bootstrap-modules#1 - Test Run: https://github.com/Azure/accelerator-bootstrap-modules/actions/runs/8288999772/job/22684596007?pr=1 ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
- Loading branch information
1 parent
e6d3bf0
commit a2e0390
Showing
36 changed files
with
301 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Bootstrap dependencies | ||
|
||
# https://docs.microsoft.com/powershell/module/packagemanagement/get-packageprovider | ||
Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null | ||
|
||
# https://docs.microsoft.com/powershell/module/powershellget/set-psrepository | ||
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | ||
|
||
# List of PowerShell Modules required for the build | ||
$modulesToInstall = [System.Collections.ArrayList]::new() | ||
# https://github.com/nightroman/Invoke-Build | ||
$null = $modulesToInstall.Add(([PSCustomObject]@{ | ||
ModuleName = 'InvokeBuild' | ||
ModuleVersion = '5.10.2' | ||
})) | ||
|
||
'Installing PowerShell Modules' | ||
foreach ($module in $modulesToInstall) { | ||
$installSplat = @{ | ||
Name = $module.ModuleName | ||
RequiredVersion = $module.ModuleVersion | ||
Repository = 'PSGallery' | ||
SkipPublisherCheck = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
try { | ||
Install-Module @installSplat | ||
Import-Module -Name $module.ModuleName -ErrorAction Stop | ||
' - Successfully installed {0}' -f $module.ModuleName | ||
} catch { | ||
$message = 'Failed to install {0}' -f $module.ModuleName | ||
" - $message" | ||
throw | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions
84
src/ALZ/Private/Deploy-Accelerator-Helpers/Get-BootstrapAndStarterConfig.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
function Get-BootstrapAndStarterConfig { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $false)] | ||
[string]$iac, | ||
[Parameter(Mandatory = $false)] | ||
[string]$bootstrap, | ||
[Parameter(Mandatory = $false)] | ||
[string]$bootstrapPath, | ||
[Parameter(Mandatory = $false)] | ||
[string]$bootstrapConfigPath, | ||
[Parameter(Mandatory = $false)] | ||
[PSCustomObject]$userInputOverrides | ||
) | ||
|
||
if ($PSCmdlet.ShouldProcess("Get Configuration for Bootstrap and Starter", "modify")) { | ||
$hasStarterModule = $false | ||
$starterModuleUrl = "" | ||
$starterModuleSourceFolder = "" | ||
$starterReleaseTag = "" | ||
$starterPipelineFolder = "" | ||
|
||
$bootstrapDetails = $null | ||
$validationConfig = $null | ||
$inputConfig = $null | ||
|
||
# Get the bootstap configuration | ||
$bootstrapConfigFullPath = Join-Path $bootstrapPath $bootstrapConfigPath | ||
Write-Verbose "Bootstrap config path $bootstrapConfigFullPath" | ||
$bootstrapConfig = Get-ALZConfig -configFilePath $bootstrapConfigFullPath | ||
$validationConfig = $bootstrapConfig.validators | ||
|
||
# Get the available bootstrap modules | ||
$bootstrapModules = $bootstrapConfig.bootstrap_modules | ||
|
||
# Request the bootstrap type if not already specified | ||
if($bootstrap -eq "") { | ||
$bootstrap = Request-SpecialInput -type "bootstrap" -bootstrapModules $bootstrapModules -userInputOverrides $userInputOverrides | ||
} | ||
|
||
# Get the bootstrap details and validate it exists (use alias for legacy values) | ||
$bootstrapDetails = $bootstrapModules.PsObject.Properties | Where-Object { $_.Name -eq $bootstrap -or $bootstrap -in $_.Value.aliases } | ||
if($null -eq $bootstrapDetails) { | ||
Write-InformationColored "The bootstrap type '$bootstrap' that you have selected does not exist. Please try again with a valid bootstrap type..." -ForegroundColor Red -InformationAction Continue | ||
throw | ||
} | ||
|
||
# Get the starter modules for the selected bootstrap if it has any | ||
$bootstrapStarterModule = $bootstrapDetails.Value.PSObject.Properties | Where-Object { $_.Name -eq "starter_modules" } | ||
|
||
if($null -ne $bootstrapStarterModule) { | ||
# If the bootstrap has starter modules, get the details and url | ||
$hasStarterModule = $true | ||
$starterModules = $bootstrapConfig.PSObject.Properties | Where-Object { $_.Name -eq "starter_modules" } | ||
$starterModuleType = $bootstrapStarterModule.Value | ||
$starterModuleDetails = $starterModules.Value.PSObject.Properties | Where-Object { $_.Name -eq $starterModuleType } | ||
if($null -eq $starterModuleDetails) { | ||
Write-InformationColored "The starter modules '$($starterModuleType)' for the bootstrap type '$bootstrap' that you have selected does not exist. This could be an issue with your custom configuration, please check and try again..." -ForegroundColor Red -InformationAction Continue | ||
throw | ||
} | ||
|
||
$starterModuleUrl = $starterModuleDetails.Value.$iac.url | ||
$starterModuleSourceFolder = $starterModuleDetails.Value.$iac.module_path | ||
$starterPipelineFolder = $starterModuleDetails.Value.$iac.pipeline_folder | ||
} | ||
|
||
# Get the bootstrap interface user input config | ||
$inputConfigFilePath = Join-Path -Path $bootstrapPath -ChildPath $bootstrapDetails.Value.interface_config_file | ||
Write-Verbose "Interface config path $inputConfigFilePath" | ||
$inputConfig = Get-ALZConfig -configFilePath $inputConfigFilePath | ||
|
||
return @{ | ||
bootstrapDetails = $bootstrapDetails | ||
hasStarterModule = $hasStarterModule | ||
starterModuleUrl = $starterModuleUrl | ||
starterModuleSourceFolder = $starterModuleSourceFolder | ||
starterReleaseTag = $starterReleaseTag | ||
starterPipelineFolder = $starterPipelineFolder | ||
validationConfig = $validationConfig | ||
inputConfig = $inputConfig | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/ALZ/Private/Deploy-Accelerator-Helpers/New-ModuleSetup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
function New-ModuleSetup { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $false)] | ||
[string]$targetDirectory, | ||
[Parameter(Mandatory = $false)] | ||
[string]$targetFolder, | ||
[Parameter(Mandatory = $false)] | ||
[string]$sourceFolder, | ||
[Parameter(Mandatory = $false)] | ||
[string]$url, | ||
[Parameter(Mandatory = $false)] | ||
[string]$release, | ||
[Parameter(Mandatory = $false)] | ||
[string]$moduleOverrideFolderPath, | ||
[Parameter(Mandatory = $false)] | ||
[bool]$skipInternetChecks | ||
) | ||
|
||
if ($PSCmdlet.ShouldProcess("Check and get module", "modify")) { | ||
$versionAndPath = $null | ||
|
||
if($skipInternetChecks) { | ||
$versionAndPath = Get-ExistingLocalRelease -targetDirectory $targetDirectory -targetFolder $targetFolder | ||
} else { | ||
$versionAndPath = New-FolderStructure ` | ||
-targetDirectory $targetDirectory ` | ||
-url $url ` | ||
-release $release ` | ||
-targetFolder $targetFolder ` | ||
-sourceFolder $sourceFolder ` | ||
-overrideSourceDirectoryPath $moduleOverrideFolderPath | ||
} | ||
return $versionAndPath | ||
} | ||
} |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function Test-ALZGitRepository { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[Alias("Output")] | ||
[Alias("OutputDirectory")] | ||
[Alias("O")] | ||
[string] $alzEnvironmentDestination, | ||
[Parameter(Mandatory = $false)] | ||
[switch] $autoApprove | ||
) | ||
$gitDirectory = Join-Path $alzEnvironmentDestination ".git" | ||
if (Test-Path $gitDirectory) { | ||
Write-Verbose "The directory $alzEnvironmentDestination is already a git repository." | ||
return $true | ||
} | ||
|
||
$runGitInit = $true | ||
$gitBranch = "main" | ||
|
||
if(!$autoApprove) { | ||
$gitInit = Read-Host "Initialize the directory $alzEnvironmentDestination as a git repository? (y/n)" | ||
if ($gitInit -ieq "y") { | ||
$runGitInit = $true | ||
$gitBranch = Read-Host "Enter the default branch name. (Hit enter to skip and use 'main')" | ||
if ($gitBranch -eq "") { | ||
$gitBranch = "main" | ||
} | ||
} | ||
} | ||
|
||
if($runGitInit -and $PSCmdlet.ShouldProcess("gitrepository", "initialize")) { | ||
git init -b $gitBranch $alzEnvironmentDestination | ||
} | ||
|
||
return $runGitInit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.