From b3a12ce01eb47332182f3a6e8835500c3e647a57 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 19 Dec 2022 07:19:21 +0530 Subject: [PATCH] Add fallback in PHP build cache in Windows --- src/scripts/win32.ps1 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index fbb58985..cbbcb1ac 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -218,10 +218,22 @@ Function Add-PhpConfig { # Function to get PHP from GitHub releases cache Function Set-PhpCache { try { - $release = Invoke-RestMethod https://api.github.com/repos/shivammathur/php-builder-windows/releases/tags/php$version - $asset = $release.assets | ForEach-Object { - if($_.name -match "php-$version.[0-9]+$env:PHPTS-Win32-.*-$arch.zip") { - return $_.name + try { + $release = Invoke-RestMethod https://api.github.com/repos/shivammathur/php-builder-windows/releases/tags/php$version + $asset = $release.assets | ForEach-Object { + if($_.name -match "php-$version.[0-9]+$env:PHPTS-Win32-.*-$arch.zip") { + return $_.name + } + } + if($null -eq $asset) { + throw "Asset not found" + } + } catch { + $release = Invoke-WebRequest $php_builder/releases/expanded_assets/php$version + $asset = $release.links.href | ForEach-Object { + if($_ -match "php-$version.[0-9]+$env:PHPTS-Win32-.*-$arch.zip") { + return $_.split('/')[-1] + } } } Invoke-WebRequest -UseBasicParsing -Uri $php_builder/releases/download/php$version/$asset -OutFile $php_dir\$asset