Skip to content

Fix brew update notifications #11024

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 3 commits into from
May 27, 2025
Merged

Conversation

BagToad
Copy link
Member

@BagToad BagToad commented May 26, 2025

Fixes #10242

Description

This attempts to follow the suggestion in #10242 (comment) to add a build tag for controlling the updaterEnabled value instead of a statically linked build property. I'm proposing this build tag be passed in via an environment variable, which means Brew's build would be edited to look something like this:

    with_env(
      "GH_VERSION" => gh_version,
      "GO_LDFLAGS" => "-s -w",
      "GO_BUILDTAGS" => "updateable",
    ) do
      system "make", "bin/gh", "manpages"
    end

I decided to put it in the same ghcmd package so the var can remain un-exported. I needed to create two files so that we get one value when the build tag is set and another when it is not set; without the two files for the two cases, we get a compile error, as you'd expect.

Testing

Note

This testing was performed on a Mac.

After checking out this branch...

# Delete the update cache
rm ~/.local/state/gh/state.yml

# Cleanup just in case
make clean 

# Build it with an "old" version and the correct build tag
GH_VERSION="0.0.1" GO_BUILDTAGS="updateable" make

# Run a somewhat long running command:
./bin/gh pr list

Demo

❯ ./bin/gh pr list              

Showing 30 of 42 open pull requests in cli/cli

ID      TITLE                                 BRANCH                               CREATED AT            
<truncated for brevity>


A new release of gh is available: 0.0.1 → 2.73.0
https://github.com/cli/cli/releases/tag/v2.73.0

@BagToad BagToad temporarily deployed to cli-automation May 26, 2025 15:45 — with GitHub Actions Inactive
@BagToad BagToad marked this pull request as ready for review May 26, 2025 15:54
@Copilot Copilot AI review requested due to automatic review settings May 26, 2025 15:54
@BagToad BagToad requested a review from a team as a code owner May 26, 2025 15:54
@BagToad BagToad requested a review from andyfeller May 26, 2025 15:54
@BagToad BagToad temporarily deployed to cli-automation May 26, 2025 15:54 — with GitHub Actions Inactive
Comment on lines 5 to 10
// updaterEnabled is a statically linked build property set in gh formula within homebrew/homebrew-core
// used to control whether users are notified of newer GitHub CLI releases.
// This needs to be set to 'cli/cli' as it affects where update.CheckForUpdate() checks for releases.
// It is unclear whether this means that only homebrew builds will check for updates or not.
// Development builds leave this empty as impossible to determine if newer or not.
// For more information, <https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/gh.rb>.
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: update this comment after implementation feedback.

Copy link
Member

Choose a reason for hiding this comment

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

I'd definitely like to reconsider whether this has to be a string cli/cli rather than a bool. I cannot for the life of me figure out why this specific string is required. I also don't believe the comment (that I know is a copy paste), since the only real check is that it is non empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm yeah good point. I don't know why it's a string 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah it gets passed in as a repo arg:

return update.CheckForUpdate(ctx, httpClient, stateFilePath, updaterEnabled, currentVersion)

func CheckForUpdate(ctx context.Context, client *http.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {

Which is eventually used in a request here:

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repo), nil)

Copy link
Member

Choose a reason for hiding this comment

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

It was originally a boolean and it later changed to the repo in this commit: ba0a441

Unfortunately, it doesn't link to any issue explaining why this is desirable. I don't feel strongly if we want to leave it as-is, but I think a comment linking to these historical commits with an explanation would be valuable.

Also FWIW, here is the issue which disabled this functionality for our own packaged builds: 2097899 (PR: #6977)

Copy link
Member

@williammartin williammartin May 27, 2025

Choose a reason for hiding this comment

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

I'm uncertain whether RPM and Debian packages have a way to detect updated packages on https://cli.github.com/ versus the logic around brew bumps, avoiding new releases having people jump on updates but nothing is there yet

I don't understand what you're trying to express here, with regards specifying the repo as the value of updaterEnabled.

My only strong opinion is we treat this as a Chesterton's Fence exercise, avoiding changing this until we have a better understanding of the need and the problem it creates for us.

I don't mind this, as long as the fact we don't know and people should make their own decision in future is documented beside the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll definitely be updating the comments with details about what has been found here :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm uncertain whether RPM and Debian packages have a way to detect updated packages on https://cli.github.com/ versus the logic around brew bumps, avoiding new releases having people jump on updates but nothing is there yet

I don't understand what you're trying to express here, with regards specifying the repo as the value of updaterEnabled.

Sorry, I was contemplating why only Homebrew builds enable gh release checking while our RPM and Debian packages disable that, not whether the variable should be a string vs boolean. My preference would be for any gh user to be notified about new releases.

Expand for digging into origins of gh update behavior

I think the following comments on #166 are the closest to explaining the original thought:

  • Add an easier upgrade command #166 (comment)

    This issue just describes a potential idea for gh, but we haven't fleshed out how this should work and therefore we haven't begun development.

    Many people already install GitHub CLI via their package manager, such as Homebrew on macOS/Linux, scoop/Chocolatey on Windows, and various package managers on *nix platforms. For people who have installed gh via their package manager, should gh provide an upgrade command, and if so, what should that command do? How do we detect these cases?

    Personally, I think it would be risky to try to side-step the package manager by providing an upgrade command, since a part of the reason why people use package managers is having a degree of control and security over their system.

    Keeping all this in mind, for which populations should we then provide a gh upgrade command and what should that command do when executed?

  • Add an easier upgrade command #166 (comment)

    Thanks @mislav! I agree with everything you said. My inclination is that the upgrading should be handled at the package manager level, and it seems (though I don't have data on this) that the vast majority of people using gh so far are installing it via a package manager, and therefore upgrading is handled there. I'm curious what I might be missing though.

  • Add an easier upgrade command #166 (comment)

    This is my inclination as well, but I'm wondering whether others (including our users) have a different idea of what their upgrade experience should feel like and should it be handled by the gh executable itself.

    For example: right now, manually downloading .deb/.rpm packages from the Releases page and installing them directly on every update is not a great upgrade experience (in my view) and we could potentially solve it by maintaining our own package repository. However, that approach still relies on 3rd-party package managers and doesn't require us to make any additions to gh command functionality.

    Also, worth noting is that the preferred upgrade method via Homebrew is now brew upgrade gh and not brew upgrade gh --fetch-HEAD as it was in the time when we were still prototyping. This should make it easier for Homebrew users to upgrade, unless they want to keep building the latest version from master.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was contemplating why only Homebrew builds enable gh release checking while our RPM and Debian packages disable that, not whether the variable should be a string vs boolean

Ack.

#6977 for further reading as to why it was turned off, when it was initially turned on.

Copy link
Member

@andyfeller andyfeller May 27, 2025

Choose a reason for hiding this comment

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

#6977 for further reading as to why it was turned off, when it was initially turned on.

Thank you!!!

Truthfully, I don't know how readily other package managers actually notify users when new packages are available. I don't see dropping the notice as that detracting or problematic that we disable it all together.

@BagToad BagToad requested a review from williammartin May 26, 2025 15:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a build‐tag driven mechanism for toggling updaterEnabled instead of using a fixed build property, allowing Homebrew to pass a tag to enable update notifications.

  • Pass a custom GO_BUILDTAGS env var into go build as -tags in script/build.go
  • Provide two build‐tag files (update_enabled.go / update_disabled.go) that set updaterEnabled appropriately
  • Remove the old hardcoded updaterEnabled var in cmd.go

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
script/build.go Reads GO_BUILDTAGS and injects it as a -tags flag to go build
internal/ghcmd/update_enabled.go Defines updaterEnabled = "cli/cli" under the updateable build tag
internal/ghcmd/update_disabled.go Defines updaterEnabled = "" when updateable tag is not set
internal/ghcmd/cmd.go Removes the previous default updaterEnabled declaration
Comments suppressed due to low confidence (2)

script/build.go:56

  • [nitpick] Consider renaming the environment variable to GH_BUILDTAGS to avoid conflict with standard Go environment variables (e.g., GOOS, GOARCH).
buildTags, _ := os.LookupEnv("GO_BUILDTAGS")

internal/ghcmd/update_enabled.go:1

  • [nitpick] The build tag updateable is unconventional; consider using the standard spelling updatable for clarity and consistency.
//go:build updateable

Copy link
Member

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

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

Thanks, @BagToad, I can't wait for update notices to be restored! Hopefully we hear back about any situations where forks depend on this and we instruct them appropriately. Should basically be a new linker flag in the build process, not the end of the world.

@BagToad BagToad merged commit 98b844a into trunk May 27, 2025
16 checks passed
@BagToad BagToad deleted the kw/cli-10242-fix-updater-notifications branch May 27, 2025 20:33
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jun 13, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.73.0` -> `v2.74.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.74.1`](https://github.com/cli/cli/releases/tag/v2.74.1): GitHub CLI 2.74.1

[Compare Source](cli/cli@v2.74.0...v2.74.1)

#### What's Changed

-   Document support for `@copilot` in `gh [pr|issue] edit --add-assignee` and `--remove-assignee` by [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#11056
-   Fix pr edit when URL is provided by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11057
-   Fix const in MR finder tests by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11091

**Full Changelog**: cli/cli@v2.74.0...v2.74.1

### [`v2.74.0`](https://github.com/cli/cli/releases/tag/v2.74.0): GitHub CLI 2.74.0

[Compare Source](cli/cli@v2.73.0...v2.74.0)

#### Security

A security vulnerability has been identified in a core `gh` dependency, `go-gh`, where an attacker-controlled GitHub Enterprise Server could result in executing arbitrary commands on a user's machine by replacing HTTP URLs provided by GitHub with local file paths for browsing.

This issue is addressed in this `gh` release by updating `go-gh` to a fixed version.

For more information, see GHSA-g9f5-x53j-h563

#### What's changed

##### ✨ Features

-   Add `preview prompter` command by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10745
-   \[gh run watch] Support `--compact` flag by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10629
-   Fix brew update notifications by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11024

##### 🐛 Fixes

-   Revert "\[gh config] Escape pipe symbol in Long desc for website manual" by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11004
-   Fix formatting in allowed values for `gh config --help` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11003
-   fix: `gh gist edit` panic when no file in a gist by [@&#8203;phanen](https://github.com/phanen) in cli/cli#10627
-   Add retry logic when fetching TUF content in `gh attestation` commands by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10943

##### 📚 Docs & Chores

-   Update README.md by [@&#8203;irhdab](https://github.com/irhdab) in cli/cli#11022
-   Add tests for `RenderJobs` and `RenderJobsCompact` by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11013
-   Add example usage of `--head` option to `pr list` docs by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10979
-   Mention `pr create` will print the created MR's URL by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10980
-   Add Digest to ReleaseAsset struct by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#11030

##### :dependabot: Dependencies

-   Bump `go-gh` to v2.12.1 by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11043
-   chore(deps): bump github.com/gabriel-vasile/mimetype from 1.4.8 to 1.4.9 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10825
-   Update sigstore-go dependency to v1.0.0 by [@&#8203;malancas](https://github.com/malancas) in cli/cli#11028
-   chore(deps): bump github.com/sigstore/protobuf-specs from 0.4.1 to 0.4.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10999
-   chore(deps): bump github.com/yuin/goldmark from 1.7.8 to 1.7.12 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11032

#### New Contributors

-   [@&#8203;irhdab](https://github.com/irhdab) made their first contribution in cli/cli#11022
-   [@&#8203;phanen](https://github.com/phanen) made their first contribution in cli/cli#10627

**Full Changelog**: cli/cli@v2.73.0...v2.74.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC41MC4wIiwidXBkYXRlZEluVmVyIjoiNDAuNTAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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.

Core GitHub CLI update checker disabled due to relocation of package build variable
3 participants