Bash: Determining latest github release tag and version

It is not uncommon to find an installation page where you are asked to download a packaged release from the github site.  But even if you are using the “latest” alias to grab the most recent, you may still need to know the exact release tag for unzipping, configuration management, etc.

Luckily, a simple query to the github api can provide that information using the syntax below:

https://api.github.com/<owner>/<repo>/releases/<version>

Here is an example of finding the “latest” release tag for the govc vmware CLI and the yq yaml parser.

# latest tag for govc vmware CLI
$ curl -sL https://api.github.com/repos/vmware/govmomi/releases/latest | jq -r ".tag_name"

v0.24.0

# latest tag for yq yaml parser
$ curl -sL https://api.github.com/repos/mikefarah/yq/releases/latest | jq -r ".tag_name"

v4.5.1

In an Ansible playbook, this looks like:

# instead of using a shell to curl, use built-in uri
- name: get latest k9s release
  uri:
    url: https://api.github.com/repos/derailed/k9s/releases/latest
    body_format: json
    return_content: yes
  register: k9sversion

- debug:
  msg: "latest version of k9s: {{k9sversion.json.tag_name}}"

 

REFERENCES

stackoverflow, get latest release tag

NOTES

finding download URL for yq which has multiple assets

latest_yq_linux=$(curl -sL https://api.github.com/repos/mikefarah/yq/releases/latest | jq -r ".assets[].browser_download_url" | grep linux_amd64.tar.gz)
wget $latest_yq_linux
tar xvfz yq_linux_amd64.tar.gz
sudo cp yq_linux_amd64 /usr/local/bin/yq

latest zip for rboxfpsunlocker

curl -sL https://api.github.com/repos/axstin/rbxfpsunlocker/releases/latest | jq -r ".zipball_url"

latest zip for terraform

TERRA_VERSION=$(curl -sL https://api.github.com/repos/hashicorp/terraform/releases/latest | jq -r ".tag_name" | cut -c2-)
wget https://releases.hashicorp.com/terraform/${TERRA_VERSION}/terraform_${TERRA_VERSION}_linux_amd64.zip

latest k9s

latest_k9s=$(curl -s https://api.github.com/repos/derailed/k9s/releases/latest | jq -r ".tag_name")

# grab archive
wget https://github.com/derailed/k9s/releases/download/$latest_k9s/k9s_Linux_amd64.tar.gz

# put into executable dir
tar xvfz k9s_Linux_amd64.tar.gz
sudo cp k9s /usr/local/bin/.