1- Function RedirectLocationHeader ([string ]$url ) {
2- [Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
3-
4- $latest = " https://github.com/exercism/configlet/releases/latest"
5- $request = [System.Net.WebRequest ]::Create($latest )
6- $request.AllowAutoRedirect = $false
7- $response = $request.GetResponse ()
8-
9- $response.GetResponseHeader (" Location" )
1+ Function DownloadUrl ([string ] $FileName , $Headers ) {
2+ $latestUrl = " https://api.github.com/repos/exercism/configlet/releases/latest"
3+ $json = Invoke-RestMethod - Headers $Headers - Uri $latestUrl
4+ $json.assets | Where-Object { $_.browser_download_url -match $FileName } | Select-Object - ExpandProperty browser_download_url
105}
116
12- Function LatestVersion {
13- $location = RedirectLocationHeader(" https://github.com/exercism/configlet/releases/latest" )
14- $location.Substring ($location.LastIndexOf (" /" ) + 1 )
7+ Function Headers {
8+ If ($GITHUB_TOKEN ) { $headers = @ { Authorization = " Bearer ${GITHUB_TOKEN} " } } Else { $headers = @ { } }
159}
1610
1711Function Arch {
1812 If ([Environment ]::Is64BitOperatingSystem) { " 64bit" } Else { " 32bit" }
1913}
2014
2115$arch = Arch
22- $version = LatestVersion
16+ $headers = Headers
2317$fileName = " configlet-windows-$arch .zip"
24- $url = " https://github.com/exercism/configlet/releases/download/$version /$filename "
2518$outputDirectory = " bin"
2619$outputFile = Join-Path - Path $outputDirectory - ChildPath $fileName
20+ $zipUrl = DownloadUrl - FileName $fileName - Headers $headers
2721
28- Invoke-WebRequest - Uri $url - OutFile $outputFile
22+ Invoke-WebRequest - Headers $headers - Uri $zipUrl - OutFile $outputFile
2923Expand-Archive $outputFile - DestinationPath $outputDirectory - Force
3024Remove-Item - Path $outputFile
0 commit comments