Skip to content

feat: add check updates command #577

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

Merged
merged 14 commits into from
Mar 13, 2025

Conversation

alexng353
Copy link
Contributor

@alexng353 alexng353 commented Dec 2, 2024

This PR adds automatic (daily) checks for new updates for the CLI, only in interactive mode. Alternatively, a user may manually check for updates using the railway check-updates command.

Automatic daily checks run in interactive mode, in the background, for any command called. If a new version is detected, the CLI will push a message to the user (similar to NPM) that requests they update their CLI.

Manual checks can be run as follows:

railway check-updates

This is what the check-updates command looks like when the version has changed:
image

This is what the check-updates command looks like when the version has not changed:
image

This is what the automatic check looks like when the check detects that the version has changed:
image

The data is grabbed (rather slowly) via the GitHub API (endpoint https://api.github.com/repos/railwayapp/cli/releases/latest), which takes around 700ms to process. This is why we run the check in the background, and even then, we only run it daily.

First run:
image
Second run:
image

@brody192 brody192 changed the title feat: add check updates command feat: add check updates command [WIP] Dec 2, 2024
@alexng353 alexng353 changed the title feat: add check updates command [WIP] feat: add check updates command Dec 4, 2024
@coffee-cup coffee-cup added the release/minor Author minor release label Dec 9, 2024
Copy link
Contributor

@coffee-cup coffee-cup left a comment

Choose a reason for hiding this comment

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

Looking good and just a few comments.

Can you also please add descriptions to any PRs so it makes it easier to review. This should include things like

  • Added commands (screenshots of the output is very useful)
  • Changes to behaviour.

Copy link
Contributor

@coffee-cup coffee-cup left a comment

Choose a reason for hiding this comment

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

Would love to get this merged soon! Just a small merge conflict and a few linting rules but then I think it would be good to go

@alexng353
Copy link
Contributor Author

alexng353 commented Feb 13, 2025

Would love to get this merged soon! Just a small merge conflict and a few linting rules but then I think it would be good to go

Merge conflict rectified via rebase.
Lint fixed with cargo fmt.

Apologies for the initial poor quality of this PR; most of it was discussed over Discord, and I didn't put the effort into reflecting the information here.

Copy link
Collaborator

@Milo123459 Milo123459 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!

feat: check for updates in background and print on next run

remove updates check from init, link and run

move functions around in main.rs
Copy link
Collaborator

@Milo123459 Milo123459 left a comment

Choose a reason for hiding this comment

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

lgtm. well done!

Copy link
Contributor

@coffee-cup coffee-cup 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. Just wondering about that comment in main, but this can be merged after

src/main.rs Outdated
Comment on lines 127 to 146
// Trace from where Args::parse() bubbles an error to where it gets caught
// and handled.
//
// https://github.com/clap-rs/clap/blob/cb2352f84a7663f32a89e70f01ad24446d5fa1e2/clap_builder/src/derive.rs#L30-L42
// https://github.com/clap-rs/clap/blob/cb2352f84a7663f32a89e70f01ad24446d5fa1e2/clap_builder/src/error/mod.rs#L233-L237
//
// This code tells us what exit code to use:
// https://github.com/clap-rs/clap/blob/cb2352f84a7663f32a89e70f01ad24446d5fa1e2/clap_builder/src/error/mod.rs#L221-L227
//
// https://github.com/clap-rs/clap/blob/cb2352f84a7663f32a89e70f01ad24446d5fa1e2/clap_builder/src/error/mod.rs#L206-L208
//
// This code tells us what stream to print the error to:
// https://github.com/clap-rs/clap/blob/cb2352f84a7663f32a89e70f01ad24446d5fa1e2/clap_builder/src/error/mod.rs#L210-L215
//
// pub(crate) fn stream(&self) -> Stream {
// match self.kind() {
// ErrorKind::DisplayHelp | ErrorKind::DisplayVersion => Stream::Stdout,
// _ => Stream::Stderr,
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be removed? What is it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove it, but it's helpful for future devs if they want to look into the reasoning behind the main file's error handling

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its okay to leave a comment with a link, but this big block is unnecessary IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove 👍

@coffee-cup coffee-cup merged commit ec13e9b into railwayapp:master Mar 13, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/minor Author minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants