-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUpdate-GitModule.ps1
75 lines (55 loc) · 2.51 KB
/
Update-GitModule.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function Update-GitModule {
[CmdletBinding(HelpUri='https://github.com/iricigor/InstallModuleFromGit/blob/master/Docs/Update-GitModule.md')]
param (
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0,ParameterSetName='ByUri')]
[string[]]$ProjectUri,
# https://github.com/dfinke/InstallModuleFromGitHub
# https://github.com/iricigor/FIFA2018
[Parameter(Mandatory,ParameterSetName='ByName')]
[string[]]$Name,
[string]$Branch = "master",
[string]$DestinationPath = (Get-InstallPath),
[switch]$Force
)
BEGIN {
$FunctionName = $MyInvocation.MyCommand.Name
Write-Verbose -Message "$(Get-Date -f G) $FunctionName starting"
if (!(Test-Prerequisites)) {
throw "$FunctionName prerequisites not met"
# TODO: Add more details
}
if ($env:AGENT_TEMPDIRECTORY) {
$tmpRoot = $env:AGENT_TEMPDIRECTORY
} else {
$tmpRoot = [System.IO.Path]::GetTempPath()
}
if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name}
}
PROCESS {
foreach ($P1 in $ProjectUri) {
Write-Verbose -Message "$(Get-Date -f T) processing $P1"
$RemoteModuleInfo = Get-GitModule -ProjectUri $P1 -KeepTempCopy
if (!$RemoteModuleInfo -or ($RemoteModuleInfo.Count -gt 1)) {continue} # we have the error in get-gitmodule
$ModuleName = $RemoteModuleInfo.Name
# TODO: continue only after cleanup!
# Check version, and if higher install it
$AllModules = @(
(Get-Module -Name $ModuleName -ListAvailable),
(Get-InstalledModule -Name $ModuleName -ErrorAction SilentlyContinue)
) | Select Name, Version
$LocalModuleInfo = $AllModules | Sort-Object Version -Descending | Select -First 1
if (!$LocalModuleInfo) {
Write-Error "$FunctionName cannot find local module '$ModuleName'"
continue
}
if ($LocalModuleInfo.Version -ge $RemoteModuleInfo.Version) {
Write-Verbose "$(Get-Date -f T) not updating module '$ModuleName', local version $($LocalModuleInfo.Version), remote version $($RemoteModuleInfo.Version)"
} else {
Install-ModuleInfo -ModuleInfo $RemoteModuleInfo -DestinationPath $DestinationPath -Force:$Force
}
}
}
END {
Write-Verbose -Message "$(Get-Date -f G) $FunctionName completed"
}
}