1+ param (
2+ [switch ] $Update = $false
3+ )
4+
5+ function Get-Architecture {
6+ $architecture = [System.Runtime.InteropServices.RuntimeInformation ]::OSArchitecture
7+
8+ $arch = switch ($architecture ) {
9+ " X64" { " amd64" }
10+ " Arm64" { " arm64" }
11+ Default { " " }
12+ }
13+
14+ if ($arch -eq " " ) {
15+ throw " Unsupported architecture: ${architecture} "
16+ }
17+
18+ return $arch
19+ }
20+
21+ function Get-Version {
22+ param ([Parameter (Mandatory = $true )][bool ] $Update )
23+
24+ if ($Update ) {
25+ return " latest"
26+ }
27+
28+ return git describe -- tags -- exact- match 2> $null || " latest"
29+ }
30+
31+ function New-TemporaryDirectory {
32+ $tmp = [System.IO.Path ]::GetTempPath()
33+ $name = (New-Guid ).ToString(" N" )
34+ $dir = New-Item - ItemType Directory - Path (Join-Path $tmp $name )
35+ return $dir.FullName
36+ }
37+
38+ function Get-Url {
39+ param ([Parameter (Mandatory = $true )][string ] $Version , [Parameter (Mandatory = $true )][string ] $Architecture )
40+
41+ if ($Version -eq " latest" ) {
42+ return " https://github.com/databus23/helm-diff/releases/latest/download/helm-diff-windows-${Architecture} .tgz"
43+ }
44+ return " https://github.com/databus23/helm-diff/releases/download/${Version} /helm-diff-windows-${Architecture} .tgz"
45+ }
46+
47+ function Download-Plugin {
48+ param ([Parameter (Mandatory = $true )][string ] $Url , [Parameter (Mandatory = $true )][string ] $Output )
49+
50+ Invoke-WebRequest - OutFile $Output $Url
51+ }
52+
53+ function Install-Plugin {
54+ param ([Parameter (Mandatory = $true )][string ] $ArchiveDirectory , [Parameter (Mandatory = $true )][string ] $ArchiveName , [Parameter (Mandatory = $true )][string ] $Destination )
55+
56+ tar - xzf (Join-Path $ArchiveDirectory $ArchiveName ) - C $ArchiveDirectory
57+
58+ New-Item - ItemType Directory - Path $Destination - Force
59+ Copy-Item - Path (Join-Path $ArchiveDirectory " diff" " bin" " diff.exe" ) - Destination $Destination - Force
60+ }
61+
62+ $ErrorActionPreference = " Stop"
63+
64+ $archiveName = " helm-diff.tgz"
65+ $arch = Get-Architecture
66+ $version = Get-Version - Update $Update
67+ $tmpDir = New-TemporaryDirectory
68+
69+ trap { Remove-Item - path $tmpDir - Recurse - Force }
70+
71+ $url = Get-Url - Version $version - Architecture $arch
72+ $output = Join-Path $tmpDir $archiveName
73+
74+ Download- Plugin - Url $url - Output $output
75+ Install-Plugin - ArchiveDirectory $tmpDir - ArchiveName $archiveName - Destination (Join-Path $env: HELM_PLUGIN_DIR " bin" )
0 commit comments