Skip to content

Commit 9454a7d

Browse files
committed
Make the homebrew struct use the same names as in the spec
1 parent 28622fd commit 9454a7d

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

cmd/publishcmd/publish.go

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -182,32 +182,32 @@ func (p *Publisher) publishGitHubRelease(
182182
}
183183

184184
// HomebrewCaskSettings holds the custom settings for homebrew_cask publisher.
185+
// Field names match their Homebrew cask stanza counterparts.
185186
type HomebrewCaskSettings struct {
187+
Name string `mapstructure:"name"`
188+
Desc string `mapstructure:"desc"`
189+
Homepage string `mapstructure:"homepage"`
190+
Pkg string `mapstructure:"pkg"` // Override pkg filename
191+
Binary string `mapstructure:"binary"` // Full path to binary, e.g. /usr/local/bin/hugoreleaser
186192
BundleIdentifier string `mapstructure:"bundle_identifier"`
187193
TapRepository string `mapstructure:"tap_repository"`
188-
Name string `mapstructure:"name"`
189194
CaskPath string `mapstructure:"cask_path"`
190195
TemplateFilename string `mapstructure:"template_filename"`
191-
Description string `mapstructure:"description"`
192-
Homepage string `mapstructure:"homepage"`
193-
BinaryName string `mapstructure:"binary_name"`
194-
BinaryLocation string `mapstructure:"binary_location"`
195196
}
196197

197198
// HomebrewCaskContext holds data for the Homebrew cask template.
199+
// Field names match their Homebrew cask stanza counterparts.
198200
type HomebrewCaskContext struct {
199-
Name string
200-
DisplayName string
201+
Token string // Cask identifier, e.g. "hugoreleaser"
201202
Version string
202203
SHA256 string
203204
URL string
204-
Description string
205+
Name string // Display name for "name" stanza
206+
Desc string
205207
Homepage string
206-
PkgFilename string
208+
Pkg string
209+
Binary string
207210
BundleIdentifier string
208-
209-
// TODO(bep) check how goreleaser does this.
210-
BinaryPath string // Full path to binary, e.g. /usr/local/bin/hugoreleaser
211211
}
212212

213213
func (p *Publisher) updateHomebrewCask(
@@ -239,12 +239,6 @@ func (p *Publisher) updateHomebrewCask(
239239
if settings.CaskPath == "" {
240240
settings.CaskPath = fmt.Sprintf("Casks/%s.rb", settings.Name)
241241
}
242-
if settings.BinaryName == "" {
243-
settings.BinaryName = p.core.Config.BuildSettings.Binary
244-
}
245-
if settings.BinaryLocation == "" {
246-
settings.BinaryLocation = "/usr/local/bin"
247-
}
248242

249243
// Find the first .pkg archive matching the archive paths pattern.
250244
pkgInfo, err := p.findPkgArchive(release, pub.ArchivePathsCompiled)
@@ -254,6 +248,12 @@ func (p *Publisher) updateHomebrewCask(
254248

255249
logCtx.WithField("pkg", pkgInfo.Name).Log(logg.String("Found pkg archive"))
256250

251+
// Use pkg filename from settings if provided, otherwise from archive.
252+
pkgFilename := settings.Pkg
253+
if pkgFilename == "" {
254+
pkgFilename = pkgInfo.Name
255+
}
256+
257257
// Build download URL.
258258
downloadURL := fmt.Sprintf(
259259
"https://github.com/%s/%s/releases/download/%s/%s",
@@ -263,24 +263,18 @@ func (p *Publisher) updateHomebrewCask(
263263
pkgInfo.Name,
264264
)
265265

266-
// Build binary path if binary_name is configured.
267-
var binaryPath string
268-
if settings.BinaryName != "" {
269-
binaryPath = filepath.Join(settings.BinaryLocation, settings.BinaryName)
270-
}
271-
272266
// Build cask context.
273267
caskCtx := HomebrewCaskContext{
274-
Name: settings.Name,
275-
DisplayName: p.core.Config.Project,
268+
Token: settings.Name,
269+
Name: p.core.Config.Project,
276270
Version: version,
277271
SHA256: pkgInfo.SHA256,
278272
URL: downloadURL,
279-
Description: settings.Description,
273+
Desc: settings.Desc,
280274
Homepage: settings.Homepage,
281-
PkgFilename: pkgInfo.Name,
275+
Pkg: pkgFilename,
276+
Binary: settings.Binary,
282277
BundleIdentifier: settings.BundleIdentifier,
283-
BinaryPath: binaryPath,
284278
}
285279

286280
// Render cask template.

hugoreleaser.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Next release
2-
HUGORELEASER_TAG=v0.61.1
2+
HUGORELEASER_TAG=v0.61.2
33
HUGORELEASER_COMMITISH=main

staticfiles/templates/homebrew-cask.rb.gotmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
cask "{{ .Name }}" do
1+
cask "{{ .Token }}" do
22
version "{{ .Version }}"
33
sha256 "{{ .SHA256 }}"
44

55
url "{{ .URL }}"
6-
name "{{ .DisplayName }}"
7-
desc "{{ .Description }}"
6+
name "{{ .Name }}"
7+
desc "{{ .Desc }}"
88
homepage "{{ .Homepage }}"
99

10-
pkg "{{ .PkgFilename }}"
11-
{{- if .BinaryPath }}
10+
pkg "{{ .Pkg }}"
11+
{{- if .Binary }}
1212

13-
binary "{{ .BinaryPath }}"
13+
binary "{{ .Binary }}"
1414
{{- end }}
1515

1616
uninstall pkgutil: "{{ .BundleIdentifier }}"

0 commit comments

Comments
 (0)