@@ -12,20 +12,31 @@ $requestOpts = @{
12
12
RetryIntervalSec = 1
13
13
}
14
14
15
- $arch = If ([Environment ]::Is64BitOperatingSystem) { " x86-64" } Else { " i386" }
16
- $fileName = " configlet_.+_windows_$arch .zip"
17
-
18
15
Function Get-DownloadUrl {
16
+ $arch = If ([Environment ]::Is64BitOperatingSystem) { " x86-64" } Else { " i386" }
19
17
$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
24
22
}
25
23
26
- $downloadUrl = Get-DownloadUrl
27
24
$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