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

Only warn about version upgrade once a day #12660

Merged
merged 2 commits into from Jun 14, 2023
Merged

Only warn about version upgrade once a day #12660

merged 2 commits into from Jun 14, 2023

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Apr 12, 2023

Description

Fixes #12659.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@Frassle Frassle requested a review from dixler April 12, 2023 15:27
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Apr 12, 2023

Changelog

[uncommitted] (2023-06-13)

Features

  • [cli] Don't warn about the CLI version being out of date on every run. The CLI will now only warn once a day, when it queries for the latest version.
    #12660

Copy link
Contributor

@dixler dixler 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. have a nit around branching.

Comment on lines 396 to 406
var skipUpdateCheck bool
latestVer, oldestAllowedVer, err := getCachedVersionInfo()
if err == nil {
// If we have cached version information then don't bother warning, we would have warned when we last
// updated the cache. But we will still log this to the internal logging system that by default users
// don't see.
skipUpdateCheck = true
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This could be an early exit and simplify the branching here and in the remainder of the function which is dependent on mutable state.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to early return here.
Long-term, it appears that with this change the cache file is useless as a source of information, and is just a marker. We can (here or in a future change) stop storing the JSON-encoded blob in it, and instead just use its last modified time to determine whether we've already informed the user.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 to early return here.

Can't early return because I still wanted to do the version check and write to the logging log.

Long-term, it appears that with this change the cache file is useless as a source of information, and is just a marker.

Yes, I did consider changing that all with this change but wasn't sure if anything else might use this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's a nit so no need to block on this.

Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Could we add a small test for this?

Comment on lines 396 to 406
var skipUpdateCheck bool
latestVer, oldestAllowedVer, err := getCachedVersionInfo()
if err == nil {
// If we have cached version information then don't bother warning, we would have warned when we last
// updated the cache. But we will still log this to the internal logging system that by default users
// don't see.
skipUpdateCheck = true
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to early return here.
Long-term, it appears that with this change the cache file is useless as a source of information, and is just a marker. We can (here or in a future change) stop storing the JSON-encoded blob in it, and instead just use its last modified time to determine whether we've already informed the user.

pkg/cmd/pulumi/pulumi.go Outdated Show resolved Hide resolved
@Frassle
Copy link
Member Author

Frassle commented Apr 12, 2023

Could we add a small test for this?

Ugh maybe, but this code is not built for testing 😆

@abhinav
Copy link
Contributor

abhinav commented Apr 12, 2023

Ugh maybe, but this code is not built for testing 😆

Yeah, I think without refactoring it, it's possible with a little t.Setenv and maybe os.Stdout/os.Stderr hijacking (example).

Comment on lines 396 to 406
var skipUpdateCheck bool
latestVer, oldestAllowedVer, err := getCachedVersionInfo()
if err == nil {
// If we have cached version information then don't bother warning, we would have warned when we last
// updated the cache. But we will still log this to the internal logging system that by default users
// don't see.
skipUpdateCheck = true
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a nit so no need to block on this.

Frassle and others added 2 commits June 13, 2023 12:41
Changes the new CLI version check
to warn about new versions at most once a day.

Fixes #12659
Adds a test to verify that checkForUpdate does not warn
more than once in the same 24 hour period.
@abhinav
Copy link
Contributor

abhinav commented Jun 13, 2023

@Frassle @dixler I rebased this and added a test to verify this new behavior. The test fails without this change:

=== RUN   TestCheckForUpdate
=== RUN   TestCheckForUpdate/cached
    pulumi_test.go:99:
                Error Trace:    /Users/abg/src/pulumi/pulumi/pkg/cmd/pulumi/pulumi_test.go:99
                Error:          Expected nil, but got: &diag.Diag{URN:"", ID:0, Message:"A new version of Pulumi is available. To upgrade from version '1.0.0' to '1.2.3', visit https://pulumi.com/docs/install/ for manual instructions and release notes.", Raw:true, StreamID:0}
                Test:           TestCheckForUpdate/cached
=== RUN   TestCheckForUpdate/cache_expired
--- FAIL: TestCheckForUpdate (0.06s)
    --- FAIL: TestCheckForUpdate/cached (0.01s)
    --- PASS: TestCheckForUpdate/cache_expired (0.02s)

@abhinav
Copy link
Contributor

abhinav commented Jun 14, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 14, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

  • bors-ok

@bors bors bot merged commit 5d7785e into master Jun 14, 2023
42 checks passed
@bors bors bot deleted the fraser/versionWarning branch June 14, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make pulumi warning check display only once a day
4 participants