1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/brew/template.go
Lukas Malkmus f35534d9d7
feat: make generated brew formulas brew audit compatible (#1908) (#1911)
* feat: add license as first class config key to homebrew (#1908)

* feat: remove trailing whitespace from generated brew formula (#1908)
2020-11-26 10:06:47 -03:00

142 lines
3.1 KiB
Go

package brew
import "github.com/goreleaser/goreleaser/pkg/config"
type templateData struct {
Name string
Desc string
Homepage string
Version string
License string
Caveats []string
Plist string
DownloadStrategy string
Install []string
PostInstall string
Dependencies []config.HomebrewDependency
Conflicts []string
Tests []string
CustomRequire string
CustomBlock []string
MacOS downloadable
LinuxAmd64 downloadable
LinuxArm downloadable
LinuxArm64 downloadable
}
type downloadable struct {
DownloadURL string
SHA256 string
}
const formulaTemplate = `# This file was generated by GoReleaser. DO NOT EDIT.
{{ if .CustomRequire -}}
require_relative "{{ .CustomRequire }}"
{{ end -}}
class {{ .Name }} < Formula
desc "{{ .Desc }}"
homepage "{{ .Homepage }}"
version "{{ .Version }}"
{{ if .License -}}
license "{{ .License }}"
{{ end -}}
bottle :unneeded
{{- if and (not .MacOS.DownloadURL) (or .LinuxAmd64.DownloadURL .LinuxArm.DownloadURL .LinuxArm64.DownloadURL) }}
depends_on :linux
{{- end }}
{{- printf "\n" }}
{{- if .MacOS.DownloadURL }}
if OS.mac?
url "{{ .MacOS.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .MacOS.SHA256 }}"
end
{{- end }}
{{- if .LinuxAmd64.DownloadURL }}
if OS.linux? && Hardware::CPU.intel?
url "{{ .LinuxAmd64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxAmd64.SHA256 }}"
end
{{- end }}
{{- if .LinuxArm.DownloadURL }}
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "{{ .LinuxArm.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxArm.SHA256 }}"
end
{{- end }}
{{- if .LinuxArm64.DownloadURL }}
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "{{ .LinuxArm64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxArm64.SHA256 }}"
end
{{- end }}
{{- with .CustomBlock }}
{{ range $index, $element := . }}
{{ . }}
{{- end }}
{{- end }}
{{- with .Dependencies }}
{{ range $index, $element := . }}
depends_on "{{ .Name }}"
{{- if .Type }} => :{{ .Type }}{{- end }}
{{- end }}
{{- end -}}
{{- with .Conflicts }}
{{ range $index, $element := . }}
conflicts_with "{{ . }}"
{{- end }}
{{- end }}
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
{{- with .PostInstall }}
def post_install
{{ . }}
end
{{- end -}}
{{- with .Caveats }}
def caveats; <<~EOS
{{- range $index, $element := . }}
{{ . -}}
{{- end }}
EOS
end
{{- end -}}
{{- with .Plist }}
plist_options :startup => false
def plist; <<~EOS
{{ . }}
EOS
end
{{- end -}}
{{- if .Tests }}
test do
{{- range $index, $element := .Tests }}
{{ . -}}
{{- end }}
end
{{- end }}
end
`