balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
457 stars 143 forks source link

Generate download link to latest CLI release ("balena update") #1716

Open pdcastro opened 4 years ago

pdcastro commented 4 years ago

Independently of having an autoupdate feature (#1669), there are use cases of dynamically generating a download link to the latest CLI executable installer or zip package, for use in web pages or scripts (curl / wget command lines), including users' CI scripts.

For example, the getting started guide / reference docs include several links to the CLI installation instructions or the releases page:

The recommended way to deploy code is to install the balena CLI. The easiest way to do this is to use the installer for your OS available on the releases page. Choose the latest release of the installer for your OS, and follow the installation instructions.
Note: You may also install the balena CLI via npm on a system running NodeJS, as explained in NPM Installation.

There are 4 links to the CLI documentation/releases above. Considering the document is a getting started guide for first-time users, it would be desirable to replace the 4 links with 1 or 2 links, one of them being a direct link to an .exe or .pkg file for Windows / macOS respectively. Something like:

Click here to download and install the CLI for Windows Note: Additional platforms and installation options are available, including the ability to choose specific CLI versions to install -- read more about the installation options.

(More about this in issue #1711.)

For this to be possible, the docs / getting started guide would need to dynamically generate the download link to the latest available CLI release, for the required platform.

So we need a couple of things on the CLI side:

This may be doable via some GitHub or npm registry HTTP API (hopefully public, non authenticated) that fetches available releases, otherwise we might need to publish/store CLI release information somewhere (like the balenaCloud API, but consider also users of openBalena and even standalone balenaOS images, which are configurable using the CLI, who are in principle not required to have a balenaCloud user account).

Regarding the balena update command, it was discussed before in CLI check-ins (Shaun). The command's purpose is to manually initiate a CLI update, not generate download URLs. However, it may be reasonable (?) to introduce the URL generation functionality first. For example:

$ balena update print-url --platform windows --type executable
https://github.com/balena-io/balena-cli/releases/download/v11.30.17/balena-cli-v11.30.17-windows-x64-installer.exe

$ balena update print-url --platform macos --type executable --version 11.30.10
https://github.com/balena-io/balena-cli/releases/download/v11.30.10/balena-cli-v11.30.10-macOS-x64-installer.pkg

$ balena update print-url --platform linux --type standalone
https://github.com/balena-io/balena-cli/releases/download/v11.30.17/balena-cli-v11.30.17-linux-x64-standalone.zip

$ balena update print-url --type source-zip
https://github.com/balena-io/balena-cli/archive/v11.30.17.zip

$ balena update
→ Causes `balena help update` to be printed, including an explanation like:

The `balena update` command is intended to check for available CLI releases and
initiate an update installation. At the moment, only the `print-url` subcommand
is implemented. It can be used to print URLs to CLI installers for use in your
own scripts. 

The description of the balena update print-url subcommand above is just an idea I've had. It would be good to discuss it a bit more widely (Scott, Shaun, Cameron, Thodoris, Page...) before starting the implementation.

pdcastro commented 4 years ago

Connects-to:

pdcastro commented 4 years ago

Some reference Javascript code

I.e., a Javascript version of this trick:

One Liner to Download the Latest Release from Github Repo https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8

pdcastro commented 3 years ago

Connects-to: balena-io/docs/pull/2064