-
-
Save MarkTiedemann/c0adc1701f3f5c215fc2c2d5b1d5efd3 to your computer and use it in GitHub Desktop.
| # Download latest dotnet/codeformatter release from github | |
| $repo = "dotnet/codeformatter" | |
| $file = "CodeFormatter.zip" | |
| $releases = "https://api.github.com/repos/$repo/releases" | |
| Write-Host Determining latest release | |
| $tag = (Invoke-WebRequest $releases | ConvertFrom-Json)[0].tag_name | |
| $download = "https://github.com/$repo/releases/download/$tag/$file" | |
| $name = $file.Split(".")[0] | |
| $zip = "$name-$tag.zip" | |
| $dir = "$name-$tag" | |
| Write-Host Dowloading latest release | |
| Invoke-WebRequest $download -Out $zip | |
| Write-Host Extracting release files | |
| Expand-Archive $zip -Force | |
| # Cleaning up target dir | |
| Remove-Item $name -Recurse -Force -ErrorAction SilentlyContinue | |
| # Moving from temp dir to target dir | |
| Move-Item $dir\$name -Destination $name -Force | |
| # Removing temp files | |
| Remove-Item $zip -Force | |
| Remove-Item $dir -Recurse -Force |
@andyneff You are right. curl.exe -LO https://github.com/%repo%/releases/latest/download/%file% should be the preferred way for downloading the latest release these days (curl is available by default on Windows and it's faster than PowerShell's Invoke-WebRequest, so I'd recommend using it instead).
@andyneff You are right.
curl.exe -LO https://github.com/%repo%/releases/latest/download/%file%should be the preferred way for downloading the latest release these days (curlis available by default on Windows and it's faster than PowerShell'sInvoke-WebRequest, so I'd recommend using it instead).
Invoke-WebRequest is fine to be used with PowerShell Core. In older versions you have to use it with $progressPreference = 'silentlyContinue' , otherwise it will be very slow.
It was just brought to my attention that this works:
https://github.com/$repo/releases/latest/download/$filewhich is apparently here (although, I'd never find that without knowing the answer first ;)