1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

142 lines
3.1 KiB
Go
Raw Normal View History

2017-07-16 15:06:32 -03:00
package brew
import "github.com/goreleaser/goreleaser/pkg/config"
2017-07-16 15:06:32 -03:00
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
2017-07-16 15:06:32 -03:00
}
const formulaTemplate = `# This file was generated by GoReleaser. DO NOT EDIT.
{{ if .CustomRequire -}}
require_relative "{{ .CustomRequire }}"
{{ end -}}
class {{ .Name }} < Formula
2017-07-16 15:06:32 -03:00
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 }}
2018-04-03 21:13:17 -03:00
{{- with .Dependencies }}
{{ range $index, $element := . }}
depends_on "{{ .Name }}"
{{- if .Type }} => :{{ .Type }}{{- end }}
{{- end }}
{{- end -}}
2017-07-16 15:06:32 -03:00
{{- with .Conflicts }}
{{ range $index, $element := . }}
2017-07-16 15:06:32 -03:00
conflicts_with "{{ . }}"
{{- end }}
{{- end }}
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
{{- with .PostInstall }}
def post_install
{{ . }}
end
{{- end -}}
{{- with .Caveats }}
2017-07-16 15:06:32 -03:00
def caveats; <<~EOS
{{- range $index, $element := . }}
{{ . -}}
{{- end }}
EOS
2017-07-16 15:06:32 -03:00
end
{{- end -}}
{{- with .Plist }}
2017-07-16 15:06:32 -03:00
plist_options :startup => false
def plist; <<~EOS
{{ . }}
EOS
2017-07-16 15:06:32 -03:00
end
{{- end -}}
{{- if .Tests }}
test do
{{- range $index, $element := .Tests }}
{{ . -}}
{{- end }}
end
{{- end }}
end
`