/
template.go
141 lines (121 loc) · 3.08 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
`