Skip to content

Commit 5ed6c88

Browse files
committed
Testing windows release
1 parent a542b9e commit 5ed6c88

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
- name: Check out code into the Go module directory
4747
uses: actions/checkout@v2
4848

49-
- name: Set up WSL
50-
uses: Vampire/setup-wsl@v3
49+
# - name: Set up WSL
50+
# uses: Vampire/setup-wsl@v3
5151

5252
- name: Release Windows Assets
5353
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ upload-resources-to-github:
130130
${MAKEFILE_PATH}/scripts/upload-resources-to-github -k -s ${K8S_1_25_ASSET_SUFFIX}
131131

132132
upload-resources-to-github-windows:
133-
wsl-bash ${MAKEFILE_PATH}/scripts/upload-resources-to-github -b
133+
powershell -File ${MAKEFILE_PATH}/scripts/upload-resources-to-github-windows -BinariesOnly
134134

135135
generate-k8s-yaml:
136136
${MAKEFILE_PATH}/scripts/generate-k8s-yaml
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# upload-resources-to-github.ps1
2+
3+
param(
4+
[switch]$BinariesOnly
5+
)
6+
7+
$ErrorActionPreference = "Stop"
8+
9+
function HandleErrorsAndCleanup {
10+
param (
11+
[int]$ExitCode
12+
)
13+
if ($ExitCode -eq 0) {
14+
exit 0
15+
}
16+
if ($global:AssetIdsUploaded.Count -ne 0) {
17+
Write-Host "`nCleaning up assets uploaded in the current execution of the script"
18+
foreach ($assetId in $global:AssetIdsUploaded) {
19+
Write-Host "Deleting asset $assetId"
20+
Invoke-RestMethod -Method Delete -Uri "https://api.github.com/repos/aws/aws-node-termination-handler/releases/assets/$assetId" -Headers @{Authorization = "token $env:GITHUB_TOKEN"}
21+
}
22+
exit $ExitCode
23+
}
24+
}
25+
26+
function UploadAsset {
27+
param (
28+
[string]$AssetPath
29+
)
30+
$resp = Invoke-RestMethod -Method Post -Uri "https://uploads.github.com/repos/aws/aws-node-termination-handler/releases/$ReleaseId/assets?name=$(Split-Path -Leaf $AssetPath)" -Headers @{
31+
Authorization = "token $env:GITHUB_TOKEN"
32+
'Content-Type' = (Get-Content -Path $AssetPath -Raw | Measure-Object -Line).Count -gt 1 ? 'application/zip' : 'application/octet-stream'
33+
} -InFile $AssetPath -ErrorAction Stop
34+
35+
if ($resp.id -ne $null) {
36+
$global:AssetIdsUploaded += $resp.id
37+
Write-Host "Created asset ID $($resp.id) successfully"
38+
} else {
39+
Write-Host "❌ Upload failed with response message: $($resp | ConvertTo-Json)"
40+
exit 1
41+
}
42+
}
43+
44+
$global:AssetIdsUploaded = @()
45+
trap { HandleErrorsAndCleanup -ExitCode $global:LASTEXITCODE }
46+
47+
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
48+
$Version = & "$ScriptPath\..\Makefile" version -s
49+
$BuildDir = "$ScriptPath\..\build\k8s-resources\$Version"
50+
$BinaryDir = "$ScriptPath\..\build\bin"
51+
$ReleaseId = (Invoke-RestMethod -Uri "https://api.github.com/repos/aws/aws-node-termination-handler/releases" -Headers @{Authorization = "token $env:GITHUB_TOKEN"} | ConvertFrom-Json | Where-Object { $_.tag_name -eq $Version }).id
52+
53+
$Assets = @()
54+
if (-not $BinariesOnly) {
55+
$Assets += "$BuildDir\individual-resources.tar", "$BuildDir\all-resources.yaml", "$BuildDir\individual-resources-queue-processor.tar", "$BuildDir\all-resources-queue-processor.yaml"
56+
}
57+
if ($BinariesOnly) {
58+
$Assets += Get-ChildItem -Path $BinaryDir
59+
}
60+
61+
Write-Host "`nUploading release assets for release id '$ReleaseId' to Github"
62+
for ($i = 0; $i -lt $Assets.Count; $i++) {
63+
Write-Host "`n $($i + 1). $($Assets[$i] | Split-Path -Leaf)"
64+
UploadAsset -AssetPath $Assets[$i]
65+
}

0 commit comments

Comments
 (0)