Skip to content

Instantly share code, notes, and snippets.

@smola
Last active May 14, 2018 11:27
Show Gist options
  • Save smola/388b05b2602fd91c33975744ba653975 to your computer and use it in GitHub Desktop.
Save smola/388b05b2602fd91c33975744ba653975 to your computer and use it in GitHub Desktop.
Get latest GitHub release from the command line (Linux, macOS, Windows)

Get latest GitHub release

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.

Bash

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')

PowerShell

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment