Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Updates] Create automatic update behavior #567

Open
charlespierce opened this issue Oct 11, 2019 · 1 comment
Open

[Updates] Create automatic update behavior #567

charlespierce opened this issue Oct 11, 2019 · 1 comment

Comments

@charlespierce
Copy link
Contributor

With all of the groundwork taken care of, we can actually create automatic updates. This will involve:

  • Checking the latest version available from the public repository (https://volta.sh/latest-version) and comparing with the currently running version
  • If there is a newer version available, downloading and unpacking the binaries into their expected locations

After the new binaries are available, the migration behavior will take care of any necessary changes the next time volta or a shim is executed. There are a couple considerations for the implementation:

  • It shouldn't have a significant effect on the hot path of running a shim, we don't want users to be waiting for an update when all they did was run ember --version.
  • We shouldn't be propagating any errors to the user's terminal, since they shouldn't have to think about the fact that the update is running.
  • We don't want to check every time the user runs a tool, we should limit it to ~once per day, at most.
  • We need a way of detecting managed environments, so that we can skip checking for updates when the version is being handled by an internal IT team.
@mgrachev
Copy link

To check for updates you can use the update-informer crate.
It has the ability to implement your own registry to check updates. For example:

use update_informer::{registry, Check, Package, Registry, Result};

let pkg_name = env!("CARGO_PKG_NAME");
let current_version = env!("CARGO_PKG_VERSION");

struct Volta;

impl Registry for Volta {
    const NAME: &'static str = "volta";

    fn get_latest_version(_pkg: &Package, _timeout: Duration) -> Result<Option<String>> {
        let result = reqwest::blocking::get("https://volta.sh/latest-version")?.text()?;
        let version = result.trim().to_string();

        Ok(Some(version))
    }
}

let informer = update_informer::new(Volta, pkg_name, current_version);

if let Ok(Some(version)) = informer.check_version() {
    let msg = format!(
        "A new release of {pkg_name} is available: v{current_version} -> {new_version}",
        pkg_name = pkg_name,
        current_version = current_version,
        new_version = version.to_string()
    );

    let release_url = format!(
        "https://github.com/{pkg_name}/{pkg_name}/releases/tag/{version}",
        pkg_name = pkg_name,
        version = version
    );

    println!("\n{msg}\n{url}", msg = msg, url = release_url);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants