/
template.go
207 lines (180 loc) · 4.53 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
PostInstall []string
Dependencies []config.HomebrewDependency
Conflicts []string
Tests []string
CustomRequire string
CustomBlock []string
LinuxPackages []releasePackage
MacOSPackages []releasePackage
Service []string
HasOnlyAmd64MacOsPkg bool
}
type releasePackage struct {
DownloadURL string
SHA256 string
OS string
Arch string
DownloadStrategy string
Install []string
}
const formulaTemplate = `# typed: false
# frozen_string_literal: true
# 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 }}
{{- with .Dependencies }}
{{ range $index, $element := . }}
depends_on "{{ .Name }}"
{{- if .Type }} => :{{ .Type }}{{- else if .Version }} => "{{ .Version }}"{{- end }}
{{- end }}
{{- end -}}
{{- if and (not .LinuxPackages) .MacOSPackages }}
depends_on :macos
{{- end }}
{{- if and (not .MacOSPackages) .LinuxPackages }}
depends_on :linux
{{- end }}
{{- printf "\n" }}
{{- if .MacOSPackages }}
on_macos do
{{- range $element := .MacOSPackages }}
{{- if eq $element.Arch "all" }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
{{- else if $.HasOnlyAmd64MacOsPkg }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
if Hardware::CPU.arm?
def caveats
<<~EOS
The darwin_arm64 architecture is not supported for the {{ $.Name }}
formula at this time. The darwin_amd64 binary may work in compatibility
mode, but it might not be fully supported.
EOS
end
end
{{- else }}
{{- if eq $element.Arch "amd64" }}
if Hardware::CPU.intel?
{{- end }}
{{- if eq $element.Arch "arm64" }}
if Hardware::CPU.arm?
{{- end}}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
end
{{- end }}
{{- end }}
end
{{- end }}
{{- if and .MacOSPackages .LinuxPackages }}{{ printf "\n" }}{{ end }}
{{- if .LinuxPackages }}
on_linux do
{{- range $element := .LinuxPackages }}
{{- if eq $element.Arch "amd64" }}
if Hardware::CPU.intel?
{{- end }}
{{- if eq $element.Arch "arm" }}
if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
{{- end }}
{{- if eq $element.Arch "arm64" }}
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
{{- end }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
{{- range $index, $element := .Install }}
{{ . -}}
{{- end }}
end
end
{{- end }}
end
{{- end }}
{{- with .Conflicts }}
{{ range $index, $element := . }}
conflicts_with "{{ . }}"
{{- end }}
{{- end }}
{{- with .CustomBlock }}
{{ range $index, $element := . }}
{{ . }}
{{- end }}
{{- end }}
{{- with .PostInstall }}
def post_install
{{- range . }}
{{ . }}
{{- end }}
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 -}}
{{- with .Service }}
service do
{{- range . }}
{{ . }}
{{- end }}
end
{{- end -}}
{{- if .Tests }}
test do
{{- range $index, $element := .Tests }}
{{ . -}}
{{- end }}
end
{{- end }}
end
`