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

add version check command #14880

Merged
merged 6 commits into from
Jan 23, 2025
Merged

add version check command #14880

merged 6 commits into from
Jan 23, 2025

Conversation

fdncred
Copy link
Collaborator

@fdncred fdncred commented Jan 21, 2025

Description

This PR supersedes #14813 by making it a built-in command instead of checking for the latest version at some interval when nushell starts.

This is what it looks like.
image

This example shows the output when the running version was 0.101.1-nightly.10
image

Description from old PR.
One key functionality that I thought was interesting with this and that I worked with @hustcer on was to try and make sure it works with nightlies. So, it should tell you when there's a new nightly version that is available to download. This way, you can know about it without checking.

What's key from a nightly perspective is (1) the tags are now semver compliant and (2) hustcer now updates the Cargo.toml package.version version number prior to compilation so you can know you're running a nightly version, and this PR uses that information to know whether to check the nightly repo or the nushell repo for updates.

This uses the update-informer crate. NOTE that this informs you of updates but does not automatically update. I kind of see this as the first step to eventually having an auto updater.

There was caching of the version in the old PR since it ran on every nushell startup. Since this PR makes it a command and therefore always runs on-demand, I've removed the caching so that it always checks when you run it.

User-Facing Changes

Tests + Formatting

After Submitting

@fdncred fdncred mentioned this pull request Jan 21, 2025
@fdncred
Copy link
Collaborator Author

fdncred commented Jan 21, 2025

@cptpiepmatz Any idea what these wasm failures are all about?

Copy link
Contributor

@132ikl 132ikl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe it could return something like:

╭────────────┬─────────╮
│ latest     │ 0.101.0 │
│ up_to_date │ false   │
│ channel    │ stable  │
╰────────────┴─────────╯

Cargo.toml Outdated
@@ -136,7 +136,7 @@ quickcheck = "1.0"
quickcheck_macros = "1.0"
quote = "1.0"
rand = "0.8"
getrandom = "0.2" # pick same version that rand requires
getrandom = "0.2" # pick same version that rand requires
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..what happened here? 🤣

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, that's weird. I guess dependi extension tries to format it. i'll save without formatting and see what happens.

@@ -264,6 +264,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
Term,
TermSize,
TermQuery,
VersionCheck,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be gated behind the network feature rather than the os feature

@132ikl
Copy link
Contributor

132ikl commented Jan 21, 2025

@cptpiepmatz Any idea what these wasm failures are all about?

looks like the update-informer crate just needs to be gated behind a feature flag. this seems to work for me:

diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml
index 6eb92d2d4..667353f85 100644
--- a/crates/nu-command/Cargo.toml
+++ b/crates/nu-command/Cargo.toml
@@ -91,7 +91,7 @@ tabled = { workspace = true, features = ["ansi"], default-features = false }
 titlecase = { workspace = true }
 toml = { workspace = true, features = ["preserve_order"] }
 unicode-segmentation = { workspace = true }
-update-informer = { workspace = true }
+update-informer = { workspace = true, optional = true }
 ureq = { workspace = true, default-features = false, features = ["charset", "gzip", "json"] }
 url = { workspace = true }
 uu_cp = { workspace = true, optional = true }
@@ -177,6 +177,7 @@ js = [
 network = [
        "multipart-rs",
        "native-tls",
+       "update-informer",
        "ureq/native-tls",
        "uuid",
 ]

@fdncred
Copy link
Collaborator Author

fdncred commented Jan 21, 2025

Thanks for the feedback @132ikl. I think followed all of your advice.

@cptpiepmatz
Copy link
Contributor

That seems to be the right way to do it 👍🏻

@fdncred fdncred marked this pull request as draft January 21, 2025 17:05
@fdncred
Copy link
Collaborator Author

fdncred commented Jan 21, 2025

@mgrachev would you mind taking a look at this please? I can't seem to get the nightly check working.

The cargo pkg version seems right but it's saying .10 is current/latest version even though there is tag with 0.101.1-nightly.12 in the nightly repo

│ CARGO_PKG_VERSION                    │ 0.101.1-nightly.10

Note: I've changed every instance of version "0.101.1" to "0.101.1-nightly.10" including the root cargo.toml package.version as well and rebuilt. I've done this to simulate a nightly build and checking with an old version. However, when I run the command, I get this output.

❯ version check
Current version: 0.101.1-nightly.10 <-- this is a debug statement that's output from "let current_version = env!("CARGO_PKG_VERSION").to_string();"
╭─────────┬────────────────────╮
│ channel │ nightly            │
│ current │ true               │
│ latest  │ 0.101.1-nightly.10 │
╰─────────┴────────────────────╯

channel is right, current should be false, latest should be 0.101.1-nightly.12. I'm sure it's something stupid I'm doing somewhere.

@mgrachev
Copy link

mgrachev commented Jan 22, 2025

It doesn't work because ureq doesn't work out of the box with the native-tls feature flag:
https://github.com/algesten/ureq/tree/2.12.1?tab=readme-ov-file#features

native-tls enables an adapter so you can pass a native_tls::TlsConnector instance to AgentBuilder::tls_connector. Due to the risk of diamond dependencies accidentally switching on an unwanted TLS implementation, native-tls is never picked up as a default or used by the crate level convenience calls (ureq::get etc) – it must be configured on the agent. The native-certs feature does nothing for native-tls.

A workaround:

  1. nushell/Cargo.toml:
ureq = { version = "2.12", default-features = false, features = ["native-tls"] }
  1. nushell/crates/nu-command/Cargo.toml:
network = [
    "update-informer/native-tls",
]
  1. nushell/crates/nu-command/src/network/version_check.rs:
struct NativeTlsHttpClient;

impl HttpClient for NativeTlsHttpClient {
    fn get<T: serde::de::DeserializeOwned>(
        url: &str,
        timeout: std::time::Duration,
        headers: update_informer::http_client::HeaderMap,
    ) -> update_informer::Result<T> {
        let agent = ureq::AgentBuilder::new()
            .tls_connector(std::sync::Arc::new(native_tls::TlsConnector::new()?))
            .build();

        let mut req = agent.get(url).timeout(timeout);

        for (header, value) in headers {
            req = req.set(header, value);
        }

        let json = req.call()?.into_json()?;

        Ok(json)
    }
}

pub fn check_for_latest_nushell_version() -> Value {
        // skipped
        let informer =
            update_informer::new(NuShellNightly, nightly_pkg_name, current_version.clone())
                .http_client(NativeTlsHttpClient)
                .interval(std::time::Duration::ZERO);
        // skipped
}

In the future, I will try to fix this issue in the new version of update-informer.

@fdncred
Copy link
Collaborator Author

fdncred commented Jan 22, 2025

That did it! Thanks so much @mgrachev. You've been a wonderful help during the process of integrating your crate. Sincerely appreciate all your help and your cool crate.

@fdncred
Copy link
Collaborator Author

fdncred commented Jan 22, 2025

ugh, wasm build/clippy again.

@cptpiepmatz
Copy link
Contributor

cptpiepmatz commented Jan 22, 2025

ureq is also a network crate

@fdncred fdncred marked this pull request as ready for review January 23, 2025 13:15
Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, let's try it how it plays with the nightly

@sholderbach sholderbach merged commit cdbb3ee into nushell:main Jan 23, 2025
16 checks passed
@fdncred fdncred deleted the check_version branch January 23, 2025 14:23
@github-actions github-actions bot added this to the v0.102.0 milestone Jan 23, 2025
@fdncred
Copy link
Collaborator Author

fdncred commented Jan 23, 2025

To be clear, for anyone testing this. It will probably only work on nightlies >= 0.101.1-nightly.14. @hustcer made some changes on how the nightlies are compiled related to versioning which are required for version check to operate. It should work fine with regular releases but those only happen every 6wks now.

@fdncred fdncred added networking All about our `http` and `url` commands and everything going accross the network. new-command pr:commands This PR changes our commands in some way labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
networking All about our `http` and `url` commands and everything going accross the network. new-command pr:commands This PR changes our commands in some way
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants