@@ -12,20 +12,31 @@ $requestOpts = @{
1212 RetryIntervalSec = 1
1313}
1414
15- $arch = If ([Environment ]::Is64BitOperatingSystem) { " x86-64" } Else { " i386" }
16- $fileName = " configlet_.+_windows_$arch .zip"
17-
1815Function Get-DownloadUrl {
16+ $arch = If ([Environment ]::Is64BitOperatingSystem) { " x86-64" } Else { " i386" }
1917 $latestUrl = " https://api.github.com/repos/exercism/configlet/releases/latest"
20- Invoke-RestMethod - Uri $latestUrl - PreserveAuthorizationOnRedirect @requestOpts
21- | Select-Object - ExpandProperty assets
22- | Where-Object { $_.browser_download_url -match $FileName }
23- | Select-Object - ExpandProperty browser_download_url
18+ Invoke-RestMethod - Uri $latestUrl - PreserveAuthorizationOnRedirect @requestOpts `
19+ | Select-Object - ExpandProperty assets `
20+ | Where-Object { $_.name -match " ^configlet_.+_windows_ ${arch} .zip$ " } `
21+ | Select-Object - ExpandProperty browser_download_url - First 1
2422}
2523
26- $downloadUrl = Get-DownloadUrl
2724$outputDirectory = " bin"
28- $outputFile = Join-Path - Path $outputDirectory - ChildPath $fileName
29- Invoke-WebRequest - Uri $downloadUrl - OutFile $outputFile @requestOpts
30- Expand-Archive $outputFile - DestinationPath $outputDirectory - Force
31- Remove-Item - Path $outputFile
25+ if (! (Test-Path - Path $outputDirectory )) {
26+ Write-Output " Error: no ./bin directory found. This script should be ran from a repo root."
27+ exit 1
28+ }
29+
30+ Write-Output " Fetching configlet..."
31+ $downloadUrl = Get-DownloadUrl
32+ $outputFileName = " configlet.zip"
33+ $outputPath = Join-Path - Path $outputDirectory - ChildPath $outputFileName
34+ Invoke-WebRequest - Uri $downloadUrl - OutFile $outputPath @requestOpts
35+
36+ $configletPath = Join-Path - Path $outputDirectory - ChildPath " configlet.exe"
37+ if (Test-Path - Path $configletPath ) { Remove-Item - Path $configletPath }
38+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($outputPath , $outputDirectory )
39+ Remove-Item - Path $outputPath
40+
41+ $configletVersion = (Select-String - Pattern " /releases/download/(.+?)/" - InputObject $downloadUrl - AllMatches).Matches.Groups[1 ].Value
42+ Write-Output " Downloaded configlet ${configletVersion} to ${configletPath} "
0 commit comments