Skip to content

Add Environment Variable to Skip Latest Extension Version Check #9925

Closed

Description

@LangLangBart

Describe the feature or problem you’d like to solve

In version 2.62.0, the ability to check the extension for the latest version was added.

Using a modified local version of an extension shows updates on every run, which I consider false positives since I don't want to upgrade. Also, a small delay of about one second has been added, which is unwanted after exiting an extension.

Proposed solution

Ability to skip checking for the latest extension version.

Extend GH_NO_UPDATE_NOTIFIER to silence extension update messages, or introduce a new variable specifically for extensions.

Additional context

This request is related to issue #743, where an environment variable was added to silence update messages.

%[1]sGH_NO_UPDATE_NOTIFIER%[1]s: set to any value to disable update notifications. By default, gh
checks for new releases once every 24 hours and displays an upgrade notice on standard
error if a newer version was found.

More Context

I am using this extension:

However, my local version is not using the 'main' branch but a pull request I created.

When I run the extension, I see the following message, which I don't want to see:

gh notify -an 1

A new release of notify is available: b39386a96a4e105dc3e5f34a447bdc011c9e8098 → 556df2eecdc0f838244a012759da0b76bcfeb2e7
To upgrade, run: gh extension upgrade notify
[email protected]:meiji163/gh-notify.git

Activity

  1. andyfeller commented on Nov 16, 2024

    @andyfeller
    Contributor

    Thank you for sharing feedback on the new extension update checking feature and sharing suggestions on how to improve it, @LangLangBart! 🙇 Extending the GH_NO_UPDATE_NOTIFIER and dropping the 1 second timeout make sense. 👍

    Whether we should have a separate environment variable for extensions or not is a good question. 🤔 The cmd.go logic involved has a little bit of complexity especially with the updaterEnabled which looks like it would be statically set during compilation but I can't find anything that is changing its value:

    cli/internal/ghcmd/cmd.go

    Lines 219 to 238 in 9decf1b

    func shouldCheckForUpdate() bool {
    if os.Getenv("GH_NO_UPDATE_NOTIFIER") != "" {
    return false
    }
    if os.Getenv("CODESPACES") != "" {
    return false
    }
    return updaterEnabled != "" && !isCI() && isTerminal(os.Stdout) && isTerminal(os.Stderr)
    }
    func isTerminal(f *os.File) bool {
    return isatty.IsTerminal(f.Fd()) || isatty.IsCygwinTerminal(f.Fd())
    }
    // based on https://github.com/watson/ci-info/blob/HEAD/index.js
    func isCI() bool {
    return os.Getenv("CI") != "" || // GitHub Actions, Travis CI, CircleCI, Cirrus CI, GitLab CI, AppVeyor, CodeShip, dsari
    os.Getenv("BUILD_NUMBER") != "" || // Jenkins, TeamCity
    os.Getenv("RUN_ID") != "" // TaskCluster, dsari
    }

    All of that aside, I'll admit I struggled a bit with some of the complexity of the different extension types and whether to duplicate or completely refactor the update logic to cache information about the latest release found:

    // ReleaseInfo stores information about a release
    type ReleaseInfo struct {
    Version string `json:"tag_name"`
    URL string `json:"html_url"`
    PublishedAt time.Time `json:"published_at"`
    }
    type StateEntry struct {
    CheckedForUpdateAt time.Time `yaml:"checked_for_update_at"`
    LatestRelease ReleaseInfo `yaml:"latest_release"`
    }
    // CheckForUpdate checks whether this software has had a newer release on GitHub
    func CheckForUpdate(ctx context.Context, client *http.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {
    stateEntry, _ := getStateEntry(stateFilePath)
    if stateEntry != nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
    return nil, nil
    }
    releaseInfo, err := getLatestReleaseInfo(ctx, client, repo)
    if err != nil {
    return nil, err
    }
    err = setStateEntry(stateFilePath, time.Now(), *releaseInfo)
    if err != nil {
    return nil, err
    }
    if versionGreaterThan(releaseInfo.Version, currentVersion) {
    return releaseInfo, nil
    }
    return nil, nil
    }

    From #6977, it appears this updaterEnabled is being set via Homebrew in https://github.com/Homebrew/homebrew-core/blob/5269b1788711898ab5732f74bf781b1e9f6ba7e4/Formula/g/gh.rb#L27-L43

      def install
        gh_version = if build.stable?
          version.to_s
        else
          Utils.safe_popen_read("git", "describe", "--tags", "--dirty").chomp
        end
    
        with_env(
          "GH_VERSION" => gh_version,
          "GO_LDFLAGS" => "-s -w -X main.updaterEnabled=cli/cli",
        ) do
          system "make", "bin/gh", "manpages"
        end
        bin.install "bin/gh"
        man1.install Dir["share/man/man1/gh*.1"]
        generate_completions_from_executable(bin/"gh", "completion", "-s")
      end
  2. Roxyfundz1 commented on Nov 25, 2024

    @Roxyfundz1
  3. added
    coreThis issue is not accepting PRs from outside contributors
    and removed on Nov 28, 2024
  4. andyfeller commented on Jan 30, 2025

    @andyfeller
    Contributor

    Circling back to this issue now that v2.66.0 has been released, the team decided to use the new GH_NO_EXTENSION_UPDATE_NOTIFIER environment variable for opting out of extension update notices. This will give users greater control over awareness of new features, bug fixes, or security without making it all or nothing.

    Otherwise, extension update notices are now on par with core gh notices.

    For more information, see gh help environment docs

  5. added a commit that references this issue on Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-extensionrelating to the gh extension command

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions