Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Install-Dependencies much faster by only installing missing requirements #894

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions build/Install-Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,40 @@ param(

[ValidateScript({ Test-Path $_ })]
[string]
$ModuleSettingsPath
$ModuleSettingsPath,

# Force installation of required modules, even if they are already installed.
[switch]
$Force
)

. "$psscriptroot/common-functions.ps1"

$settingPath = "$PSScriptRoot/../module/$ModuleName/config/ModuleSettings.json"
if ($ModuleSettingsPath) { $settingPath = $ModuleSettingsPath }
$content = Get-Content -Path $settingPath | ConvertFrom-Json
Write-Verbose("Installing Module $($content.sourceModule)")
Install-Module $content.sourceModule -scope currentuser -Force -AllowClobber

foreach ($moduleName in $content.destinationModuleName){
Write-Verbose("Installing Module $($moduleName)")
Install-Module $moduleName -scope currentuser -RequiredVersion $content.destinationModuleVersion -Force -AllowClobber
}
if ($Force) {
Write-Verbose 'Skipping the check for installed prerequisites.'
} else {
Write-Verbose 'Checking installed modules for required dependencies.'
$InstalledModules = Get-Module -ListAvailable -Verbose:$false | Group-Object -Property Name
}

$SourceModule = $content.sourceModule
if (($InstalledModules.Name -contains $SourceModule) -and -not $Force) {
Write-Verbose "The $SourceModule module is already installed."
} else {
Write-Verbose("Installing Module: $sourceModule")
Install-Module $sourceModule -Scope CurrentUser -Force -AllowClobber
}

foreach ($moduleName in $content.destinationModuleName) {
$InstalledModuleReference = $InstalledModules.Where({ $_.Name -eq $moduleName }).Group
if (($InstalledModuleReference.Version -ge $content.destinationModuleVersion) -and -not $Force) {
Write-Verbose "The $moduleName module is already installed."
} else {
Write-Verbose "Installing Module: $moduleName"
Install-Module $moduleName -Scope CurrentUser -RequiredVersion $content.destinationModuleVersion -Force -AllowClobber
}
}