mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Fix to correctly use fallback URL for tools on Windows
This commit is contained in:
parent
d9cb143213
commit
948917a97b
@ -101,7 +101,7 @@ Function Add-Tool() {
|
|||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
$url,
|
$urls,
|
||||||
[Parameter(Position = 1, Mandatory = $true)]
|
[Parameter(Position = 1, Mandatory = $true)]
|
||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
$tool,
|
$tool,
|
||||||
@ -112,23 +112,26 @@ Function Add-Tool() {
|
|||||||
if (Test-Path $bin_dir\$tool) {
|
if (Test-Path $bin_dir\$tool) {
|
||||||
Copy-Item $bin_dir\$tool -Destination $bin_dir\$tool.old -Force
|
Copy-Item $bin_dir\$tool -Destination $bin_dir\$tool.old -Force
|
||||||
}
|
}
|
||||||
if($url.Count -gt 1) {
|
|
||||||
$url = $url[0]
|
|
||||||
}
|
|
||||||
$tool_path = "$bin_dir\$tool"
|
$tool_path = "$bin_dir\$tool"
|
||||||
if (($url | Split-Path -Extension) -eq ".exe") {
|
foreach ($url in $urls){
|
||||||
$tool_path = "$tool_path.exe"
|
if (($url | Split-Path -Extension) -eq ".exe") {
|
||||||
}
|
$tool_path = "$tool_path.exe"
|
||||||
try {
|
}
|
||||||
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
try {
|
||||||
} catch {
|
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
|
||||||
if($url -match '.*github.com.*releases.*latest.*') {
|
} catch {
|
||||||
try {
|
if($url -match '.*github.com.*releases.*latest.*') {
|
||||||
$url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
|
try {
|
||||||
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
$url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
|
||||||
} catch { }
|
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($status_code -eq 200 -and (Test-Path $tool_path)) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
||||||
$bat_content = @()
|
$bat_content = @()
|
||||||
$bat_content += "@ECHO off"
|
$bat_content += "@ECHO off"
|
||||||
|
Loading…
Reference in New Issue
Block a user