Skip to content

Commit 41db619

Browse files
committed
refactor(plugin.yaml): enhance platform support and update commands
Signed-off-by: yxxhero <[email protected]>
1 parent 1d12d90 commit 41db619

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

install-binary.ps1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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")

plugin.yaml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
name: "diff"
1+
name: diff
22
# Version is the version of Helm plus the number of official builds for this
33
# plugin
4-
version: "3.9.13"
5-
usage: "Preview helm upgrade changes as a diff"
6-
description: "Preview helm upgrade changes as a diff"
4+
version: 3.9.13
5+
usage: Preview helm upgrade changes as a diff
6+
description: Preview helm upgrade changes as a diff
77
useTunnel: true
8-
command: "$HELM_PLUGIN_DIR/bin/diff"
9-
hooks:
10-
install: "$HELM_PLUGIN_DIR/install-binary.sh"
11-
update: "$HELM_PLUGIN_DIR/install-binary.sh -u"
8+
platformCommand:
9+
- command: ${HELM_PLUGIN_DIR}/bin/diff
10+
- os: windows
11+
command: ${HELM_PLUGIN_DIR}\bin\diff.exe
12+
platformHooks:
13+
install:
14+
- command: ${HELM_PLUGIN_DIR}/install-binary.sh
15+
- os: windows
16+
command: pwsh
17+
args:
18+
- -c
19+
- ${HELM_PLUGIN_DIR}/install-binary.ps1
20+
update:
21+
- command: ${HELM_PLUGIN_DIR}/install-binary.sh
22+
args:
23+
- -u
24+
- os: windows
25+
command: pwsh
26+
args:
27+
- -c
28+
- ${HELM_PLUGIN_DIR}/install-binary.ps1
29+
- -Update

0 commit comments

Comments
 (0)