You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GoReleaser发布Go项目到Homebrew时出现SHA256不匹配

Homebrew安装GoReleaser发布的CLI工具时SHA256不匹配问题

我用Go开发了一个CLI工具,尝试通过GoReleaser发布到Homebrew。按步骤创建标签并推送到GitHub,执行goreleaser生成发布版本和Homebrew公式文件,但执行brew tap username/cli https://github.com/username/cli和brew install username/cli/teamcli时,出现SHA256不匹配错误。

发布流程

我执行的发布步骤如下:

  • git tag -a v1.0.27 -m "release"
  • git push origin v1.0.27
  • goreleaser release --clean

这个流程成功在GitHub创建了发布,也生成了新的formula文件。

.goreleaser.yml配置

builds:
  - env:
      - CGO_ENABLED=0
    goos:
      - linux
      - windows
      - darwin # macos
    goarch:
      - amd64
      - arm64

checksum:
  name_template: "checksums.txt"
snapshot:
  name_template: "{{ incpatch .Version }}-next"
changelog:
  sort: asc
  filters:
    exclude:
      - "^docs:"
      - "^test:"

# Same repo deployment
brews:
  - name: teamcli
    homepage: https://github.com/username/cli
    description: Secretive.
    repository:
      owner: username
      name: cli

生成的Formula部分内容

# typed: false
# frozen_string_literal: true

# This file was generated by GoReleaser. DO NOT EDIT.
class Msicli < Formula
  desc "The one stop shop for all things msi."
  homepage "https://github.com/username/cli"
  version "1.0.27"

  on_macos do
    if Hardware::CPU.arm?
      url "https://github.com/username/cli/releases/download/v1.0.27/cli_Darwin_arm64.tar.gz"
      sha256 "cad93dbeac1273d227ff7a08c14e18d5456058e186069bcddaeff0bd82dba23d"

      def install
        bin.install "cli"
      end
    end
    if Hardware::CPU.intel?
      url "https://github.com/username/cli/releases/download/v1.0.27/cli_Darwin_x86_64.tar.gz"
      sha256 "50a214e9ddefc27c76c83aa4db6d3f0256c36c6845a108d555d72ac9d45b7b52"

      def install
        bin.install "cli"
      end
.....

安装时的错误信息

==> Fetching username/cli/teamcli
==> Downloading https://github.com/username/cli/releases/download/v1.0.27/cli
==> Downloading from https://github.com/enterprises/....
##O=#    #                                                                                                             
Error: teamcli: SHA256 mismatch
Expected: 50a214e9ddefc27c76c83aa4db6d3f0256c36c6845a108d555d72ac9d45b7b52
  Actual: d887ab0beac687324520384f8c3c3b21ab9bb2888fc2e98b9174f3df77c9f36a
    File: /Users/Homebrew/downloads/d3a77523f3adc5b18143bf40fecc0eb4ac75faf66dd3c1de7f0126b50d7057f0--sso
To retry an incomplete download, remove the file above.

我已经尝试删除下载文件后重新下载,但SHA256不匹配的问题仍然存在。


解决办法

  1. 验证GitHub发布文件的SHA256
    手动计算GitHub上对应二进制包的SHA256值,和Formula里的预期值对比:

    curl -L https://github.com/username/cli/releases/download/v1.0.27/cli_Darwin_x86_64.tar.gz | shasum -a 256
    

    如果结果和Formula里的不一致,说明GoReleaser生成的包和上传的文件不匹配,重新运行goreleaser release --clean重新发布,确保过程无中断。

  2. 检查Formula文件是否正确更新
    去username/cli仓库的Formula目录下,查看teamcli.rb里的SHA256值是否和实际文件一致。如果不一致,要么手动修正,要么重新运行GoReleaser自动推送正确的Formula。

  3. 清理Homebrew缓存
    除了删除单个下载文件,清理Homebrew的缓存目录:

    brew cleanup -s
    rm -rf $(brew --cache)/username/cli/teamcli
    

    之后重新执行安装命令。

  4. 检查命名一致性
    注意到生成的Formula类名是Msicli,但安装的是teamcli,确认.goreleaser.yml里的name: teamcli配置正确,生成的Formula文件名是teamcli.rb,避免命名混乱导致拉取错误文件。

内容的提问来源于stack exchange,提问作者Frantz Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 15:46:26