55 [switch ]$K8sAssetsOnly
66)
77
8- # $ErrorActionPreference = "Stop"
9-
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- # }
8+ $ErrorActionPreference = " Stop"
9+
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 " `n Cleaning 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
2929function UploadAsset {
@@ -40,7 +40,7 @@ function UploadAsset {
4040 try {
4141 $Response = Invoke-RestMethod - Method Post - Uri $Uri - Headers $Headers - InFile $AssetPath - ErrorAction Stop
4242 if ($Response -and $Response.id ) {
43- # $global:AssetIdsUploaded += $Response.id
43+ $global :AssetIdsUploaded += $Response.id
4444 Write-Output " Created asset ID $ ( $Response.id ) successfully"
4545 } else {
4646 Write-Output " ❌ Upload failed with response message: $ ( $Response | ConvertTo-Json ) ❌"
@@ -53,14 +53,16 @@ function UploadAsset {
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 = v1.109.0
60+ $Version = " v1.110.0 "
6161$BuildDir = " $ScriptPath /../build/k8s-resources/$Version "
6262$BinaryDir = " $ScriptPath /../build/bin"
6363
64+ [Net.ServicePointManager ]::SecurityProtocol = [Net. ::SecurityProtocolType ]::Tls12
65+
6466try {
6567 $Response = (Invoke-RestMethod - Uri " https://api.github.com/repos/LikithaVemulapalli/aws-node-termination-handler/releases" - Headers @ {Authorization = " token $env: GITHUB_TOKEN " })
6668} catch {
@@ -72,12 +74,9 @@ Write-Output "API Response:"
7274Write-Output $Response | ForEach-Object { Write-Output $_.tag_name }
7375
7476
75- $release = $Response | Where-Object {
76- Write-Output " Checking release: $ ( $_.tag_name ) "
77- $_.tag_name -eq $Version
78- }
77+ $release = $Response | Where-Object { $_.tag_name -eq $Version }
7978
80- Write-Output " Filtered Release"
79+ Write-Output " Filtered Release - latest release "
8180Write-Output $release
8281
8382$ReleaseId = $release.id
@@ -92,10 +91,12 @@ if (-not $ReleaseId) {
9291
9392# Gather assets to upload based on the -BinariesOnly flag
9493$Assets = @ ()
94+ if ($BinariesOnly ) {
95+ $Assets += Get-ChildItem - Path $BinaryDir | ForEach-Object { $_.FullName }
96+ }
9597if (-not $BinariesOnly ) {
9698 $Assets += " $BuildDir \individual-resources.tar" , " $BuildDir \all-resources.yaml" , " $BuildDir \individual-resources-queue-processor.tar" , " $BuildDir \all-resources-queue-processor.yaml"
9799}
98- $Assets += Get-ChildItem - Path $BinaryDir | ForEach-Object { $_.FullName }
99100
100101# Log gathered assets
101102Write-Output " Assets to upload:"
0 commit comments