From 58f5e6eb61e14674f5647f181b2364e73ec75929 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:30:07 +0530 Subject: [PATCH 1/4] uri validation --- builders/build-node.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/builders/build-node.ps1 b/builders/build-node.ps1 index 05693c2..4e8c6de 100644 --- a/builders/build-node.ps1 +++ b/builders/build-node.ps1 @@ -56,6 +56,19 @@ function Get-NodeBuilder { $Platform = $Platform.ToLower() if ($Platform -match 'win32') { $builder = [WinNodeBuilder]::New($Version, $Platform, $Architecture) + # Get the URL of the binaries + $binariesUri = $builder.GetBinariesUri() + + # If the URL is $null, then skip the download and build process + if ($binariesUri -eq $null) { + Write-Host "The binary doesn't exist. Skipping download and build." + exit 0 + } else { + # Continue with the build + $builder.Build() + return $builder + } + } elseif (($Platform -match 'linux') -or ($Platform -match 'darwin')) { $builder = [NixNodeBuilder]::New($Version, $Platform, $Architecture) } else { -- 2.49.1 From fb203bee7927da8ea042441bdabff2bcf435d1c5 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:30:36 +0530 Subject: [PATCH 2/4] Update node-builder.psm1 --- builders/node-builder.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builders/node-builder.psm1 b/builders/node-builder.psm1 index f0eefa3..08b16c3 100644 --- a/builders/node-builder.psm1 +++ b/builders/node-builder.psm1 @@ -87,8 +87,12 @@ class NodeBuilder { #> Write-Host "Create WorkFolderLocation and ArtifactFolderLocation folders" - New-Item -Path $this.WorkFolderLocation -ItemType "directory" + if (-not (Test-Path -path $this.WorkFolderLocation)) { + New-Item -Path $this.WorkFolderLocation -ItemType "directory" + } + if (-not (Test-Path -path $this.ArtifactFolderLocation)) { New-Item -Path $this.ArtifactFolderLocation -ItemType "directory" + } Write-Host "Download Node.js $($this.Version) [$($this.Architecture)] executable..." $binariesArchivePath = $this.Download() -- 2.49.1 From 5c83b5281d18375b4466a53aacb92da703665a82 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:31:24 +0530 Subject: [PATCH 3/4] Update win-node-builder.psm1 --- builders/win-node-builder.psm1 | 41 +++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/builders/win-node-builder.psm1 b/builders/win-node-builder.psm1 index eefaa4a..ffdc060 100644 --- a/builders/win-node-builder.psm1 +++ b/builders/win-node-builder.psm1 @@ -30,22 +30,41 @@ class WinNodeBuilder : NodeBuilder { $this.OutputArtifactName = "node-$Version-$Platform-$Architecture.7z" } - [uri] GetBinariesUri() { - <# - .SYNOPSIS - Get base Node.js URI and return complete URI for Node.js installation executable. - #> - $base = $this.GetBaseUri() - return "${base}/v$($this.Version)/node-v$($this.Version)-win-$($this.Architecture).7z" + + + [uri] GetBinariesUri() { + <# + .SYNOPSIS + Get base Node.js URI and return complete URI for Node.js installation executable. + #> + + $base = $this.GetBaseUri() + $uri = "${base}/v$($this.Version)/node-v$($this.Version)-win-$($this.Architecture).7z" + + # Check if the package exists + try { + $response = Invoke-WebRequest -Uri $uri -Method Head -ErrorAction Stop + + # If the request was successful and the status code is 200, return the URI + if ($response.StatusCode -eq 200) { + return $uri + } else { + Write-Host "Skipping build as the binary does not exist." + return $null + } + } catch { + Write-Host "Skipping build as the binary does not exist." + return $null } - +} + [void] ExtractBinaries($archivePath) { $extractTargetDirectory = Join-Path $this.TempFolderLocation "tempExtract" Extract-SevenZipArchive -ArchivePath $archivePath -OutputDirectory $extractTargetDirectory $nodeOutputPath = Get-Item $extractTargetDirectory\* | Select-Object -First 1 -ExpandProperty Fullname - Move-Item -Path $nodeOutputPath\* -Destination $this.WorkFolderLocation - } + Move-Item -Path $nodeOutputPath\* -Destination $this.WorkFolderLocation -Force + } [void] CreateInstallationScript() { <# @@ -53,7 +72,7 @@ class WinNodeBuilder : NodeBuilder { Create Node.js artifact installation script based on specified template. #> - $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File + $installationScriptLocation = $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File -Force $installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName $installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw -- 2.49.1 From 6730960cfa5e64896888a8f10d27f545430fe036 Mon Sep 17 00:00:00 2001 From: aparnajyothi-y <147696841+aparnajyothi-y@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:34:18 +0530 Subject: [PATCH 4/4] Update win-node-builder.psm1 --- builders/win-node-builder.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builders/win-node-builder.psm1 b/builders/win-node-builder.psm1 index ffdc060..adc3b12 100644 --- a/builders/win-node-builder.psm1 +++ b/builders/win-node-builder.psm1 @@ -72,7 +72,7 @@ class WinNodeBuilder : NodeBuilder { Create Node.js artifact installation script based on specified template. #> - $installationScriptLocation = $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File -Force + $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File -Force $installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName $installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw -- 2.49.1