SHA256 mismatch when brewing custom Go Project

257 views Asked by At

I created a cli using Go, and I'm trying to release it to Homebrew using GoReleaser. I followed the steps in the docs. I created a tag and pushed it to Github so that Goreleaser could use it. On the main branch of my project, I see the rb file for Homebrew to use. The issue is that when I try to brew tap and then brew install, I get a mismatch in sha256 error.

Here are my steps to generate a release:

  1. git tag -a v1.0.27 -m "release"
  2. git push origin v1.0.27
  3. gorelease release --clean

This successfully creates a release on GitHub and generates a new formula.

Here is my .goreleaser.yml file

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

This is what (part of) the generated formula looks like:

# 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
.....

When I run brew tap username/cli https://github.com/username/cli and then brew install username/cli/teamcli, I get back

==> 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.

Yes, I've tried removing the file and downloading again but the issue keeps occurring with the mismatch in SHA256.

1

There are 1 answers

1
Hezy Ziv On

try to verify the SHA256, Download the release asset manually from GitHub. calculate its SHA256 checksum using the shasum command:

shasum -a 256 downloaded_file_name

Compare this checksum with the one in the formula. If they don't match, it means the asset was modified after the formula was generated.