Skip to content

Commit 757018e

Browse files
authored
refactor(plugin.yaml): enhance platform support and update commands (#712)
* refactor(plugin.yaml): enhance platform support and update commands Signed-off-by: yxxhero <[email protected]>
1 parent cf4917b commit 757018e

File tree

3 files changed

+106
-12
lines changed

3 files changed

+106
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
os: [ubuntu-latest, macos-latest, windows-latest]
4444
shell: [ default ]
4545
experimental: [ false ]
46-
helm-version: [ v3.18.6, v3.17.4 ]
46+
helm-version: [ v3.18.6, v3.19.0-rc.1 ]
4747
include:
4848
- os: windows-latest
4949
shell: wsl
@@ -61,16 +61,16 @@ jobs:
6161
- os: windows-latest
6262
shell: wsl
6363
experimental: false
64-
helm-version: v3.17.4
64+
helm-version: v3.19.0-rc.1
6565
- os: windows-latest
6666
shell: cygwin
6767
experimental: false
68-
helm-version: v3.17.4
68+
helm-version: v3.19.0-rc.1
6969
- os: ubuntu-latest
7070
container: alpine
7171
shell: sh
7272
experimental: false
73-
helm-version: v3.17.4
73+
helm-version: v3.19.0-rc.1
7474

7575
steps:
7676
- name: Disable autocrlf
@@ -93,8 +93,6 @@ jobs:
9393
- name: Setup Cygwin
9494
if: "contains(matrix.shell, 'cygwin')"
9595
uses: egor-tensin/setup-cygwin@v4
96-
with:
97-
platform: x64
9896

9997
- name: helm plugin install
10098
run: helm plugin install .
@@ -111,7 +109,7 @@ jobs:
111109
# That's why we cover only 2 Helm minor versions in this matrix.
112110
# See https://github.com/helmfile/helmfile/pull/286#issuecomment-1250161182 for more context.
113111
- helm-version: v3.18.6
114-
- helm-version: v3.17.4
112+
- helm-version: v3.19.0-rc.1
115113
steps:
116114
- uses: engineerd/[email protected]
117115
with:

install-binary.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
Push-Location $ArchiveDirectory
57+
tar -xzf $ArchiveName -C .
58+
Pop-Location
59+
60+
New-Item -ItemType Directory -Path $Destination -Force
61+
Copy-Item -Path (Join-Path $ArchiveDirectory "diff" "bin" "diff.exe") -Destination $Destination -Force
62+
}
63+
64+
$ErrorActionPreference = "Stop"
65+
66+
$archiveName = "helm-diff.tgz"
67+
$arch = Get-Architecture
68+
$version = Get-Version -Update $Update
69+
$tmpDir = New-TemporaryDirectory
70+
71+
trap { Remove-Item -path $tmpDir -Recurse -Force }
72+
73+
$url = Get-Url -Version $version -Architecture $arch
74+
$output = Join-Path $tmpDir $archiveName
75+
76+
Download-Plugin -Url $url -Output $output
77+
Install-Plugin -ArchiveDirectory $tmpDir -ArchiveName $archiveName -Destination (Join-Path $env:HELM_PLUGIN_DIR "bin")

plugin.yaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
name: "diff"
1+
name: diff
22
# Version is the version of Helm plus the number of official builds for this
33
# plugin
44
version: "3.12.5"
55
usage: "Preview helm upgrade changes as a diff"
66
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+
13+
platformHooks:
14+
install:
15+
- command: ${HELM_PLUGIN_DIR}/install-binary.sh
16+
- os: windows
17+
command: pwsh
18+
args:
19+
- -c
20+
- ${HELM_PLUGIN_DIR}/install-binary.ps1
21+
update:
22+
- command: ${HELM_PLUGIN_DIR}/install-binary.sh
23+
args:
24+
- -u
25+
- os: windows
26+
command: pwsh
27+
args:
28+
- -c
29+
- ${HELM_PLUGIN_DIR}/install-binary.ps1
30+
- -Update

0 commit comments

Comments
 (0)