Skip to content

Commit

Permalink
Add Powershell version of fetch configlet script
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Oct 9, 2020
1 parent d151c43 commit 7b14484
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bin/fetch-configlet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Function DownloadUrl ([string] $FileName, $Headers) {
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
$json = Invoke-RestMethod -Headers $Headers -Uri $latestUrl
$json.assets | Where-Object { $_.browser_download_url -match $FileName } | Select-Object -ExpandProperty browser_download_url
}

Function Headers {
If ($GITHUB_TOKEN) { @{ Authorization = "Bearer ${GITHUB_TOKEN}" } } Else { @{ } }
}

Function Arch {
If ([Environment]::Is64BitOperatingSystem) { "64bit" } Else { "32bit" }
}

$arch = Arch
$headers = Headers
$fileName = "configlet-windows-$arch.zip"
$outputDirectory = "bin"
$outputFile = Join-Path -Path $outputDirectory -ChildPath $fileName
$zipUrl = DownloadUrl -FileName $fileName -Headers $headers

Invoke-WebRequest -Headers $headers -Uri $zipUrl -OutFile $outputFile
Expand-Archive $outputFile -DestinationPath $outputDirectory -Force
Remove-Item -Path $outputFile

0 comments on commit 7b14484

Please sign in to comment.