Sync fetch-configlet.ps1 script (#113)
This commit is contained in:
@@ -12,20 +12,31 @@ $requestOpts = @{
|
|||||||
RetryIntervalSec = 1
|
RetryIntervalSec = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$arch = If ([Environment]::Is64BitOperatingSystem) { "64bit" } Else { "32bit" }
|
|
||||||
$fileName = "configlet-windows-$arch.zip"
|
|
||||||
|
|
||||||
Function Get-DownloadUrl {
|
Function Get-DownloadUrl {
|
||||||
|
$arch = If ([Environment]::Is64BitOperatingSystem) { "x86-64" } Else { "i386" }
|
||||||
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
|
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
|
||||||
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts
|
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts `
|
||||||
| Select-Object -ExpandProperty assets
|
| Select-Object -ExpandProperty assets `
|
||||||
| Where-Object { $_.browser_download_url -match $FileName }
|
| Where-Object { $_.name -match "^configlet_.+_windows_${arch}.zip$" } `
|
||||||
| Select-Object -ExpandProperty browser_download_url
|
| Select-Object -ExpandProperty browser_download_url -First 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$downloadUrl = Get-DownloadUrl
|
|
||||||
$outputDirectory = "bin"
|
$outputDirectory = "bin"
|
||||||
$outputFile = Join-Path -Path $outputDirectory -ChildPath $fileName
|
if (!(Test-Path -Path $outputDirectory)) {
|
||||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
|
Write-Output "Error: no ./bin directory found. This script should be ran from a repo root."
|
||||||
Expand-Archive $outputFile -DestinationPath $outputDirectory -Force
|
exit 1
|
||||||
Remove-Item -Path $outputFile
|
}
|
||||||
|
|
||||||
|
Write-Output "Fetching configlet..."
|
||||||
|
$downloadUrl = Get-DownloadUrl
|
||||||
|
$outputFileName = "configlet.zip"
|
||||||
|
$outputPath = Join-Path -Path $outputDirectory -ChildPath $outputFileName
|
||||||
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath @requestOpts
|
||||||
|
|
||||||
|
$configletPath = Join-Path -Path $outputDirectory -ChildPath "configlet.exe"
|
||||||
|
if (Test-Path -Path $configletPath) { Remove-Item -Path $configletPath }
|
||||||
|
[System.IO.Compression.ZipFile]::ExtractToDirectory($outputPath, $outputDirectory)
|
||||||
|
Remove-Item -Path $outputPath
|
||||||
|
|
||||||
|
$configletVersion = (Select-String -Pattern "/releases/download/(.+?)/" -InputObject $downloadUrl -AllMatches).Matches.Groups[1].Value
|
||||||
|
Write-Output "Downloaded configlet ${configletVersion} to ${configletPath}"
|
||||||
|
|||||||
Reference in New Issue
Block a user