-
-
Save gjonespf/2b84a2fb354b7ce8bc10c23474851d2f to your computer and use it in GitHub Desktop.
Download latest GitHub release via Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Download latest dotnet/codeformatter release from github | |
| $repo = "jgm/pandoc" | |
| $filenamePattern = "*x86_64.zip" | |
| $pathExtract = "C:\Tools\pandoc" | |
| $innerDirectory = $true | |
| $preRelease = $false | |
| if ($preRelease) { | |
| $releasesUri = "https://api.github.com/repos/$repo/releases" | |
| $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri)[0].assets | Where-Object name -like $filenamePattern ).browser_download_url | |
| } | |
| else { | |
| $releasesUri = "https://api.github.com/repos/$repo/releases/latest" | |
| $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url | |
| } | |
| $pathZip = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $(Split-Path -Path $downloadUri -Leaf) | |
| Invoke-WebRequest -Uri $downloadUri -Out $pathZip | |
| Remove-Item -Path $pathExtract -Recurse -Force -ErrorAction SilentlyContinue | |
| if ($innerDirectory) { | |
| $tempExtract = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $((New-Guid).Guid) | |
| Expand-Archive -Path $pathZip -DestinationPath $tempExtract -Force | |
| Move-Item -Path "$tempExtract\*" -Destination $pathExtract -Force | |
| Remove-Item -Path $tempExtract -Force -Recurse -ErrorAction SilentlyContinue | |
| } | |
| else { | |
| Expand-Archive -Path $pathZip -DestinationPath $pathExtract -Force | |
| } | |
| Remove-Item $pathZip -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment