Skip to content

Instantly share code, notes, and snippets.

@carlosgrillet
Created June 30, 2026 11:00
Show Gist options
  • Select an option

  • Save carlosgrillet/c60ef9c1f7a570c7d661d38cae3f327e to your computer and use it in GitHub Desktop.

Select an option

Save carlosgrillet/c60ef9c1f7a570c7d661d38cae3f327e to your computer and use it in GitHub Desktop.
Config GoReleaser in private github repositories
# Legend:
# <tool_name> the name of your binary, e.g. gotool
# <owner> the owner of the tool repository, e.g. privGo
# <repo> the tool repository
# <tap_owner> the owner of the homebrew tap repository
# <tap> the name of the homebrew tap
# <license> the license of your tool
# <project_description> description of your tool
#
# Example:
# https://github.com/privGo is a private organization
# https://github.com/privGo/internal-tap is the homebrew tap repository
# https://github.com/privGo/gotool is the tool repository
#
# privGo is the <owner> and <tap_owner>, internal-tap is the <tap>,
# gotool is the <repo> and potentially the <tool_name>
#
# There could be a case where your <repo> is named xy-gotool but
# you want your binary to be called and executed as gotool. In this
# case you would have xy-gotool as <repo> and gotool as <tool_name>.
#
# Considerations:
#
# - You must have a PAT on this repository that has read-write access to the
# <tap> repository, so goreleaser can write to it.
# - The machines where this tool will be installed must have the github cli
# installed (https://cli.github.com) and you should be logged in.
version: 2
project_name: <tool_name>
before:
hooks:
- go mod tidy
- go vet ./...
builds:
- binary: <tool_name>
main: .
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
archives:
- formats: ["tar.gz"]
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
checksum:
name_template: checksums.txt
snapshot:
version_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^ci:"
- "^chore:"
homebrew_casks:
- repository:
owner: <tap_owner>
name: <tap>
branch: main
token: "{{ .Env.HOMEBREW_TAP_TOKEN }}"
# Make sure to add a token to this repo
# That token should have Read and Write access to code
# so goreleaser on this repo can publish on the private tap
directory: Casks
homepage: https://github.com/<owner>/<repo>
description: <project_description>
license: <license>
hooks:
post:
install: |
if OS.mac?
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/<tool_name>"]
end
custom_block: |
module GitHubHelper
def self.token
github_token = ENV["HOMEBREW_GITHUB_API_TOKEN"]
if github_token.nil? || github_token.empty?
gh_bin = ["/opt/homebrew/bin/gh", "/usr/local/bin/gh", "/home/linuxbrew/.linuxbrew/bin/gh"].find { |p| File.executable?(p) }
github_token = `#{gh_bin} auth token 2>/dev/null`.strip if gh_bin
end
raise "No GitHub token available (install gh and run: gh auth login, or set HOMEBREW_GITHUB_API_TOKEN)" if github_token.nil? || github_token.empty?
github_token
end
def self.release_asset_url(tag, name)
require "json"
require "net/http"
require "uri"
resp = Net::HTTP.get(
URI.parse("https://api.github.com/repos/<owner>/<repo>/releases/tags/#{tag}"),
{
"Accept" => "application/vnd.github+json",
"Authorization" => "Bearer #{token}",
"X-GitHub-Api-Version" => "2022-11-28"
}
)
release = JSON.parse(resp)
release["assets"].find { |asset| asset["name"] == name }["url"]
end
end
url:
template: '#{GitHubHelper.release_asset_url("{{.Tag}}", "{{.ArtifactName}}")}'
headers:
- "Accept: application/octet-stream"
- "Authorization: Bearer #{GitHubHelper.token}"
- "X-GitHub-Api-Version: 2022-11-28"
release:
github:
owner: <owner>
name: <repo_name>
draft: false
prerelease: auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment