These snippets can be used to retrieve the latest GitHub release from Linux, macOS and Windows. Note that other approaches involve either:
- HTML scraping involving more dependencies or more complex code.
- Using GitHub API, which has rate limit, so it is not suitable for all applications.
Replace the repository org/name
with yours.
Assuming wget
is available:
tag=$(wget -qSO- --method=HEAD --max-redirect=0 https://github.com/smola/ci-tricks/releases/latest 2>&1 | grep Location: | sed -e 's/.*\///g')
Tested on Windows PowerShell and PowerShell Core on Linux.
# Fix SSL/TLS error on Windows PowerShell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$response = try {
Invoke-WebRequest "https://github.com/smola/ci-tricks/releases/latest" -UseBasicParsing -Method Head -MaximumRedirection 0 -ErrorAction 'Ignore'
} catch {
$_.Exception.Response
}
# Windows PowerShell and PowerShell Core seem to vary their behaviour
# here: $response.Headers.Location might be a String or a System.Uri.
$tag = $response.Headers.Location.ToString().Split("/")[-1]