@@ -72,16 +72,38 @@ $HASH_FUNCTIONS_STR = $HASH_FUNCTIONS -join '|' # SHA1|SHA256|SHA384|SHA512|MD5
7272$NERDCTL_CHECKSUM_FILE_PATTERN = " (?<hashfunction>(?:^({0})))" -f ($HASH_FUNCTIONS -join ' |' )
7373$NERDCTL_FILTER_SCRIPTBLOCK_STR = { ((" {0}" -match " $NERDCTL_CHECKSUM_FILE_PATTERN " ) -and " {0}" -notmatch " .*.asc$" ) }.ToString()
7474
75- function Get-LatestToolVersion ($repository ) {
75+
76+ Set-Variable - Option AllScope - scope Global - Visibility Public - Name " CONTAINERD_REPO" - Value " containerd/containerd" - Force
77+ Set-Variable - Option AllScope - scope Global - Visibility Public - Name " BUILDKIT_REPO" - Value " moby/buildkit" - Force
78+ Set-Variable - Option AllScope - scope Global - Visibility Public - Name " NERDCTL_REPO" - Value " containerd/nerdctl" - Force
79+ Set-Variable - Option AllScope - scope Global - Visibility Public - Name " WINCNI_PLUGIN_REPO" - Value " microsoft/windows-container-networking" - Force
80+ Set-Variable - Option AllScope - scope Global - Visibility Public - Name " CLOUDNATIVE_CNI_REPO" - Value " containernetworking/plugins" - Force
81+
82+
83+ function Get-LatestToolVersion ($tool ) {
84+ # Get the repository based on the tool
85+ $repository = switch ($tool.ToLower ()) {
86+ " containerd" { $CONTAINERD_REPO }
87+ " buildkit" { $BUILDKIT_REPO }
88+ " nerdctl" { $NERDCTL_REPO }
89+ " wincniplugin" { $WINCNI_PLUGIN_REPO }
90+ " cloudnativecni" { $CLOUDNATIVE_CNI_REPO }
91+ Default { Throw " Couldn't get latest $tool version. Invalid tool name: '$tool '." }
92+ }
93+
94+ # Get the latest release version URL string
95+ $uri = " https://api.github.com/repos/$repository /releases/latest"
96+
97+ Write-Debug " Getting the latest $tool version from $uri "
98+
99+ # Get the latest release version
76100 try {
77- $uri = " https://api.github.com/repos/$repository /releases/latest"
78101 $response = Invoke-WebRequest - Uri $uri - UseBasicParsing
79102 $version = ($response.content | ConvertFrom-Json ).tag_name
80103 return $version.TrimStart (" v" )
81104 }
82105 catch {
83- $tool = ($repository -split " /" )[1 ]
84- Throw " Could not get $tool latest version. $ ( $_.Exception.Message ) "
106+ Throw " Couldn't get $tool latest version from $uri . $ ( $_.Exception.Message ) "
85107 }
86108}
87109
@@ -889,7 +911,7 @@ function Invoke-ExecutableCommand {
889911 return $p
890912}
891913
892-
914+ Export-ModuleMember - Variable CONTAINERD_REPO , BUILDKIT_REPO , NERDCTL_REPO , WINCNI_PLUGIN_REPO , CLOUDNATIVE_CNI_REPO
893915Export-ModuleMember - Function Get-LatestToolVersion
894916Export-ModuleMember - Function Get-DefaultInstallPath
895917Export-ModuleMember - Function Test-EmptyDirectory
0 commit comments