github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/brew/template.go (about)

     1  package brew
     2  
     3  import "github.com/goreleaser/goreleaser/pkg/config"
     4  
     5  type templateData struct {
     6  	Name              string
     7  	Desc              string
     8  	Homepage          string
     9  	Version           string
    10  	License           string
    11  	Caveats           []string
    12  	Plist             string
    13  	DownloadStrategy  string
    14  	Install           []string
    15  	PostInstall       string
    16  	Dependencies      []config.HomebrewDependency
    17  	Conflicts         []string
    18  	Tests             []string
    19  	CustomRequire     string
    20  	CustomBlock       []string
    21  	MacOSAmd64        downloadable
    22  	MacOSArm64        downloadable
    23  	LinuxAmd64        downloadable
    24  	LinuxArm          downloadable
    25  	LinuxArm64        downloadable
    26  	HasMacOSDownloads bool
    27  	HasLinuxDownloads bool
    28  }
    29  
    30  type downloadable struct {
    31  	DownloadURL string
    32  	SHA256      string
    33  }
    34  
    35  const formulaTemplate = `# typed: false
    36  # frozen_string_literal: true
    37  
    38  # This file was generated by GoReleaser. DO NOT EDIT.
    39  {{ if .CustomRequire -}}
    40  require_relative "{{ .CustomRequire }}"
    41  {{ end -}}
    42  class {{ .Name }} < Formula
    43    desc "{{ .Desc }}"
    44    homepage "{{ .Homepage }}"
    45    version "{{ .Version }}"
    46    {{ if .License -}}
    47    license "{{ .License }}"
    48    {{ end -}}
    49    bottle :unneeded
    50    {{- if and (not .HasLinuxDownloads) .HasMacOSDownloads }}
    51    depends_on :macos
    52    {{- end }}
    53    {{- if and (not .HasMacOSDownloads) .HasLinuxDownloads }}
    54    depends_on :linux
    55    {{- end }}
    56    {{- printf "\n" }}
    57  
    58    {{- if .HasMacOSDownloads }}
    59    on_macos do
    60      {{- if .MacOSAmd64.DownloadURL }}
    61      if Hardware::CPU.intel?
    62        url "{{ .MacOSAmd64.DownloadURL }}"
    63        {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
    64        sha256 "{{ .MacOSAmd64.SHA256 }}"
    65      end
    66      {{- end }}
    67      {{- if .MacOSArm64.DownloadURL }}
    68      if Hardware::CPU.arm?
    69        url "{{ .MacOSArm64.DownloadURL }}"
    70        {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
    71        sha256 "{{ .MacOSArm64.SHA256 }}"
    72      end
    73      {{- end }}
    74    end
    75    {{- end }}
    76  
    77    {{- if and .HasMacOSDownloads .HasLinuxDownloads }}{{ printf "\n" }}{{ end }}
    78  
    79    {{- if .HasLinuxDownloads }}
    80    on_linux do
    81      {{- if .LinuxAmd64.DownloadURL }}
    82      if Hardware::CPU.intel?
    83        url "{{ .LinuxAmd64.DownloadURL }}"
    84        {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
    85        sha256 "{{ .LinuxAmd64.SHA256 }}"
    86      end
    87      {{- end }}
    88      {{- if .LinuxArm.DownloadURL }}
    89      if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
    90        url "{{ .LinuxArm.DownloadURL }}"
    91        {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
    92        sha256 "{{ .LinuxArm.SHA256 }}"
    93      end
    94      {{- end }}
    95      {{- if .LinuxArm64.DownloadURL }}
    96      if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
    97        url "{{ .LinuxArm64.DownloadURL }}"
    98        {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
    99        sha256 "{{ .LinuxArm64.SHA256 }}"
   100      end
   101      {{- end }}
   102    end
   103    {{- end }}
   104  
   105    {{- with .CustomBlock }}
   106    {{ range $index, $element := . }}
   107    {{ . }}
   108    {{- end }}
   109    {{- end }}
   110  
   111    {{- with .Dependencies }}
   112    {{ range $index, $element := . }}
   113    depends_on "{{ .Name }}"
   114    {{- if .Type }} => :{{ .Type }}{{- end }}
   115    {{- end }}
   116    {{- end -}}
   117  
   118    {{- with .Conflicts }}
   119    {{ range $index, $element := . }}
   120    conflicts_with "{{ . }}"
   121    {{- end }}
   122    {{- end }}
   123  
   124    def install
   125      {{- range $index, $element := .Install }}
   126      {{ . -}}
   127      {{- end }}
   128    end
   129  
   130    {{- with .PostInstall }}
   131  
   132    def post_install
   133      {{ . }}
   134    end
   135    {{- end -}}
   136  
   137    {{- with .Caveats }}
   138  
   139    def caveats; <<~EOS
   140      {{- range $index, $element := . }}
   141      {{ . -}}
   142      {{- end }}
   143    EOS
   144    end
   145    {{- end -}}
   146  
   147    {{- with .Plist }}
   148  
   149    plist_options :startup => false
   150  
   151    def plist; <<~EOS
   152      {{ . }}
   153    EOS
   154    end
   155    {{- end -}}
   156  
   157    {{- if .Tests }}
   158  
   159    test do
   160      {{- range $index, $element := .Tests }}
   161      {{ . -}}
   162      {{- end }}
   163    end
   164    {{- end }}
   165  end
   166  `