Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Retrieve latest CLI version in the background#2189

Merged
gonzaloriestra merged 5 commits intomainfrom
check-for-new-version-in-background
Apr 20, 2022
Merged

Retrieve latest CLI version in the background#2189
gonzaloriestra merged 5 commits intomainfrom
check-for-new-version-in-background

Conversation

@amcaplan
Copy link
Copy Markdown
Contributor

@amcaplan amcaplan commented Mar 29, 2022

WHY are these changes introduced?

Inspired by #2052

Currently we check for a new version as a blocking process. This isn't a good experience for CLI users, for whom the command hangs once daily until we check for a new version.

WHAT is this pull request doing?

This approach will fork the process and check in the background, saving the result and warning the user the next time they run a command.

Note this isn't ideal for CLI environments which might run 1 command per CLI run and never show the warning. We might choose to mitigate by checking inline on non-TTY terminals.

How to test your changes?

  1. Enable these lines in your dev environment (need to play with the if/elsif or just copy the lines to after the conditional)
  2. Change the version to something older
  3. Change the checking interval to 1 second so it'll check each time you run the command
  4. Run bin/shopify version a few times and you'll start to see the new version warning (hopefully on round 2)

Screen Shot 2022-03-29 at 13 04 50

Update checklist

  • I've added a CHANGELOG entry for this PR (if the change is public-facing)
  • I've considered possible cross-platform impacts (Mac, Linux, Windows).
  • I've left the version number as is (we'll handle incrementing this when releasing).

@amcaplan amcaplan requested review from a team, hannachen and molly-yu and removed request for a team March 29, 2022 10:05
@amcaplan amcaplan force-pushed the check-for-new-version-in-background branch from 28c7079 to 301527a Compare March 29, 2022 11:35
Currently we check for a new version as a blocking process. This isn't a
good experience for CLI users, for whom the command hangs once daily
until we check for a new version.

This approach will fork the process and check in the background, saving
the result and warning the user the next time they run a command.

Note this isn't ideal for CLI environments which might run 1 command per
CLI run and never show the warning. We might choose to mitigate by
checking inline on non-TTY terminals.
@amcaplan amcaplan force-pushed the check-for-new-version-in-background branch from ab5140c to 6c9df66 Compare March 30, 2022 08:02
def with_stubbed_context(&block)
@old_config = ShopifyCLI::Config
without_warnings do
ShopifyCLI.const_set(:Config, Class.new do
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

const_set here and below displays a warning, since the constant has already been set. So I disable warnings here to avoid unhelpful output in tests.

rescue
nil
ensure
ShopifyCLI::Config.set(VERSION_CHECK_SECTION, LAST_CHECKED_AT_FIELD, Time.now.to_i)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still wait until tomorrow to try if something went wrong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something is wrong. This doesn't work as intended. Version check repeats on every command. See #2382

Copy link
Copy Markdown
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

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

The code LGTM and it works as expected! 👏

@AnwarElbo
Copy link
Copy Markdown

Fork isn't supported on Windows 11, have been trying to figure out what was wrong. See my stacktrace after running shopify version.

/gems/shopify-cli-2.16.0/lib/shopify_cli/context.rb:624:in `fork': fork() function is unimplemented on this machine (NotImplementedError)

@gonzaloriestra
Copy link
Copy Markdown
Contributor

@AnwarElbo oh, we didn't realize about that, thanks for the notice. I'll prepare a bugfix as soon as possible.

@gonzaloriestra
Copy link
Copy Markdown
Contributor

@AnwarElbo it should be fixed in v2.16.1, sorry for the inconvenience!

end
end
latest_version = ShopifyCLI::Config.get(VERSION_CHECK_SECTION, LATEST_VERSION_FIELD, default: ShopifyCLI::VERSION)
latest_version unless latest_version == ShopifyCLI::VERSION
Copy link
Copy Markdown
Contributor

@ADTC ADTC Jul 12, 2022

Choose a reason for hiding this comment

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

This will always return the latest_version even when (time_of_last_check + VERSION_CHECK_INTERVAL) < (now = Time.now.to_i) is false.

Fixed in PR #2453

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants