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

208 lines
4.5 KiB
Go
Raw Normal View History

2017-07-16 20:06:32 +02:00
package brew
import "github.com/goreleaser/goreleaser/pkg/config"
2017-07-16 20:06:32 +02:00
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
2017-07-16 20:06:32 +02:00
}
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
2017-07-16 20:06:32 +02:00
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 := . }}
{{ . }}
2017-07-16 20:06:32 +02:00
{{- end }}
{{- end }}
{{- with .PostInstall }}
def post_install
{{- range . }}
{{ . }}
{{- end }}
end
{{- end -}}
{{- with .Caveats }}
2017-07-16 20:06:32 +02:00
def caveats
<<~EOS
{{- range $index, $element := . }}
{{ . -}}
{{- end }}
EOS
2017-07-16 20:06:32 +02:00
end
{{- end -}}
{{- with .Plist }}
2017-07-16 20:06:32 +02:00
plist_options startup: false
2017-07-16 20:06:32 +02:00
def plist
<<~EOS
{{ . }}
EOS
2017-07-16 20:06:32 +02:00
end
{{- end -}}
{{- with .Service }}
service do
{{- range . }}
{{ . }}
{{- end }}
end
{{- end -}}
2017-07-16 20:06:32 +02:00
{{- if .Tests }}
test do
{{- range $index, $element := .Tests }}
{{ . -}}
{{- end }}
end
{{- end }}
end
`