Skip to content

Commit 8a7ad70

Browse files
committed
Used Write-Output
1 parent 2de557e commit 8a7ad70

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

scripts/upload-resources-to-github-windows.ps1

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ param(
55
[switch]$K8sAssetsOnly
66
)
77

8-
$ErrorActionPreference = "Stop"
8+
#$ErrorActionPreference = "Stop"
99

10-
# Function to handle errors and cleanup any partially uploaded assets
11-
function HandleErrorsAndCleanup {
12-
param (
13-
[int]$ExitCode
14-
)
15-
if ($ExitCode -eq 0) {
16-
exit 0
17-
}
18-
if ($global:AssetIdsUploaded.Count -ne 0) {
19-
Write-Host "`nCleaning up assets uploaded in the current execution of the script"
20-
foreach ($assetId in $global:AssetIdsUploaded) {
21-
Write-Host "Deleting asset $assetId"
22-
Invoke-RestMethod -Method Delete -Uri "https://api.github.com/repos/LikithaVemulapalli/aws-node-termination-handler/releases/assets/$assetId" -Headers @{Authorization = "token $env:GITHUB_TOKEN"}
23-
}
24-
exit $ExitCode
25-
}
26-
}
10+
# # Function to handle errors and cleanup any partially uploaded assets
11+
# function HandleErrorsAndCleanup {
12+
# param (
13+
# [int]$ExitCode
14+
# )
15+
# if ($ExitCode -eq 0) {
16+
# exit 0
17+
# }
18+
# if ($global:AssetIdsUploaded.Count -ne 0) {
19+
# Write-Output "`nCleaning up assets uploaded in the current execution of the script"
20+
# foreach ($assetId in $global:AssetIdsUploaded) {
21+
# Write-Output "Deleting asset $assetId"
22+
# Invoke-RestMethod -Method Delete -Uri "https://api.github.com/repos/LikithaVemulapalli/aws-node-termination-handler/releases/assets/$assetId" -Headers @{Authorization = "token $env:GITHUB_TOKEN"}
23+
# }
24+
# exit $ExitCode
25+
# }
26+
# }
2727

2828
# Function to upload an asset to GitHub
2929
function UploadAsset {
@@ -39,31 +39,31 @@ function UploadAsset {
3939

4040
try {
4141
$Response = Invoke-RestMethod -Method Post -Uri $Uri -Headers $Headers -InFile $AssetPath -ErrorAction Stop
42-
if ($Response.id -ne $null) {
43-
$global:AssetIdsUploaded += $Response.id
44-
Write-Host "Created asset ID $($Response.id) successfully"
42+
if ($Response -and $Response.id) {
43+
#$global:AssetIdsUploaded += $Response.id
44+
Write-Output "Created asset ID $($Response.id) successfully"
4545
} else {
46-
Write-Host "❌ Upload failed with response message: $($Response | ConvertTo-Json)"
46+
Write-Output "❌ Upload failed with response message: $($Response | ConvertTo-Json)"
4747
exit 1
4848
}
4949
} catch {
50-
Write-Host "❌ Upload failed: $_"
50+
Write-Output "❌ Upload failed: $_"
5151
exit 1
5252
}
5353
}
5454

5555
# Initialize global variables
56-
$global:AssetIdsUploaded = @()
57-
trap { HandleErrorsAndCleanup -ExitCode $global:LASTEXITCODE }
56+
# $global:AssetIdsUploaded = @()
57+
# trap { HandleErrorsAndCleanup -ExitCode $global:LASTEXITCODE }
5858

5959
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
60-
$Version = & "$ScriptPath/../Makefile" version -s
60+
$Version = (& "$ScriptPath/../Makefile" version -s)
6161
$BuildDir = "$ScriptPath/../build/k8s-resources/$Version"
6262
$BinaryDir = "$ScriptPath/../build/bin"
6363
$ReleaseId = (Invoke-RestMethod -Uri "https://api.github.com/repos/LikithaVemulapalli/aws-node-termination-handler/releases" -Headers @{Authorization = "token $env:GITHUB_TOKEN"} | ConvertFrom-Json | Where-Object { $_.tag_name -eq $Version }).id
6464

6565
if (-not $ReleaseId) {
66-
Write-Host "❌ Failed to find release ID for version $Version"
66+
Write-Output "❌ Failed to find release ID for version $Version"
6767
exit 1
6868
}
6969

@@ -75,14 +75,14 @@ if (-not $BinariesOnly) {
7575
$Assets += Get-ChildItem -Path $BinaryDir | ForEach-Object { $_.FullName }
7676

7777
# Log gathered assets
78-
Write-Host "Assets to upload:"
78+
Write-Output "Assets to upload:"
7979
foreach ($Asset in $Assets) {
80-
Write-Host $Asset
80+
Write-Output $Asset
8181
}
8282

8383
# Upload each asset
8484
Write-Host "`nUploading release assets for release id '$ReleaseId' to Github"
8585
foreach ($Asset in $Assets) {
86-
Write-Host "`n Uploading $($Asset | Split-Path -Leaf)"
86+
Write-Output "`n Uploading $($Asset | Split-Path -Leaf)"
8787
UploadAsset -AssetPath $Asset
8888
}

0 commit comments

Comments
 (0)