Repository: goreleaser/goreleaser
Pull request #1554 (2020-05-23 20:10:05)

feat: add support brew dependency types
Resolve: #1524 

vercel-for-github[bot]: 
This pull request is being automatically deployed with Vercel ([learn more](https://zeit.ink/github-learn-more)).
To see the status of your deployment, click below or on the icon next to each commit.

  🔍 Inspect: https://vercel.com/goreleaser/goreleaser/l5sxzxdus
  ✅ Preview: https://goreleaser-git-feature-brew-dependencies.goreleaser.now.sh
  	
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=h1) Report
> Merging [#1554](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/a48ddc38288cd64837478af230516e51dabdb1f0&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1554/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1554   +/-   ##
=======================================
  Coverage   85.51%   85.51%           
=======================================
  Files          69       69           
  Lines        3819     3819           
=======================================
  Hits         3266     3266           
  Misses        458      458           
  Partials       95       95           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1554/diff?src=pr&el=tree#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `93.44% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=footer). Last update [a48ddc3...1eaa1d0](https://codecov.io/gh/goreleaser/goreleaser/pull/1554?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index c99c8123..7fb32ae9 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -90,7 +90,7 @@ brews:
     test: |
       system "#{bin}/goreleaser -v"
     dependencies:
-    - go
+    - name: go
 scoop:
   bucket:
     owner: goreleaser
diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go
index 409339f0..207a7f9c 100644
--- a/internal/pipe/brew/template.go
+++ b/internal/pipe/brew/template.go
@@ -1,5 +1,7 @@
 package brew
 
+import "github.com/goreleaser/goreleaser/pkg/config"
+
 type templateData struct {
 	Name             string
 	Desc             string
@@ -9,7 +11,7 @@ type templateData struct {
 	Plist            string
 	DownloadStrategy string
 	Install          []string
-	Dependencies     []string
+	Dependencies     []config.HomebrewDependency
 	Conflicts        []string
 	Tests            []string
 	CustomRequire    string
@@ -76,7 +78,8 @@ class {{ .Name }} < Formula
 
   {{- with .Dependencies }}
   {{ range $index, $element := . }}
-  depends_on "{{ . }}"
+  depends_on "{{ .Name }}"
+  {{- if .Type }} => :{{ .Type }}{{- end }}
   {{- end }}
   {{- end -}}
 
diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go
index dc2197e5..1202a01b 100644
--- a/internal/tmpl/tmpl.go
+++ b/internal/tmpl/tmpl.go
@@ -3,6 +3,7 @@ package tmpl
 
 import (
 	"bytes"
+	"fmt"
 	"path/filepath"
 	"strings"
 	"text/template"
@@ -25,6 +26,7 @@ const (
 	// general keys
 	projectName = "ProjectName"
 	version     = "Version"
+	rawVersion  = "RawVersion"
 	tag         = "Tag"
 	commit      = "Commit"
 	shortCommit = "ShortCommit"
@@ -33,6 +35,8 @@ const (
 	major       = "Major"
 	minor       = "Minor"
 	patch       = "Patch"
+	prerelease  = "Prerelease"
+	isSnapshot  = "IsSnapshot"
 	env         = "Env"
 	date        = "Date"
 	timestamp   = "Timestamp"
@@ -58,10 +62,14 @@ const (
 
 // New Template
 func New(ctx *context.Context) *Template {
+	sv := ctx.Semver
+	rawVersionV := fmt.Sprintf("%d.%d.%d", sv.Major, sv.Minor, sv.Patch)
+
 	return &Template{
 		fields: Fields{
 			projectName: ctx.Config.ProjectName,
 			version:     ctx.Version,
+			rawVersion:  rawVersionV,
 			tag:         ctx.Git.CurrentTag,
 			commit:      ctx.Git.Commit,
 			shortCommit: ctx.Git.ShortCommit,
@@ -73,7 +81,8 @@ func New(ctx *context.Context) *Template {
 			major:       ctx.Semver.Major,
 			minor:       ctx.Semver.Minor,
 			patch:       ctx.Semver.Patch,
-			// TODO: no reason not to add prerelease here too I guess
+			prerelease:  ctx.Semver.Prerelease,
+			isSnapshot:  ctx.Snapshot,
 		},
 	}
 }
diff --git a/pkg/config/config.go b/pkg/config/config.go
index e23b3cd8..b861044e 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -39,6 +39,12 @@ type Repo struct {
 	Name  string `yaml:",omitempty"`
 }
 
+// HomebrewDependency represents Homebrew dependency
+type HomebrewDependency struct {
+	Name string `yaml:",omitempty"`
+	Type string `yaml:",omitempty"`
+}
+
 // String of the repo, e.g. owner/name
 func (r Repo) String() string {
 	if r.Owner == "" && r.Name == "" {
@@ -49,26 +55,26 @@ func (r Repo) String() string {
 
 // Homebrew contains the brew section
 type Homebrew struct {
-	Name             string       `yaml:",omitempty"`
-	GitHub           Repo         `yaml:",omitempty"`
-	GitLab           Repo         `yaml:",omitempty"`
-	CommitAuthor     CommitAuthor `yaml:"commit_author,omitempty"`
-	Folder           string       `yaml:",omitempty"`
-	Caveats          string       `yaml:",omitempty"`
-	Plist            string       `yaml:",omitempty"`
-	Install          string       `yaml:",omitempty"`
-	Dependencies     []string     `yaml:",omitempty"`
-	Test             string       `yaml:",omitempty"`
-	Conflicts        []string     `yaml:",omitempty"`
-	Description      string       `yaml:",omitempty"`
-	Homepage         string       `yaml:",omitempty"`
-	SkipUpload       string       `yaml:"skip_upload,omitempty"`
-	DownloadStrategy string       `yaml:"download_strategy,omitempty"`
-	URLTemplate      string       `yaml:"url_template,omitempty"`
-	CustomRequire    string       `yaml:"custom_require,omitempty"`
-	CustomBlock      string       `yaml:"custom_block,omitempty"`
-	IDs              []string     `yaml:"ids,omitempty"`
-	Goarm            string       `yaml:"goarm,omitempty"`
+	Name             string               `yaml:",omitempty"`
+	GitHub           Repo                 `yaml:",omitempty"`
+	GitLab           Repo                 `yaml:",omitempty"`
+	CommitAuthor     CommitAuthor         `yaml:"commit_author,omitempty"`
+	Folder           string               `yaml:",omitempty"`
+	Caveats          string               `yaml:",omitempty"`
+	Plist            string               `yaml:",omitempty"`
+	Install          string               `yaml:",omitempty"`
+	Dependencies     []HomebrewDependency `yaml:",omitempty"`
+	Test             string               `yaml:",omitempty"`
+	Conflicts        []string             `yaml:",omitempty"`
+	Description      string               `yaml:",omitempty"`
+	Homepage         string               `yaml:",omitempty"`
+	SkipUpload       string               `yaml:"skip_upload,omitempty"`
+	DownloadStrategy string               `yaml:"download_strategy,omitempty"`
+	URLTemplate      string               `yaml:"url_template,omitempty"`
+	CustomRequire    string               `yaml:"custom_require,omitempty"`
+	CustomBlock      string               `yaml:"custom_block,omitempty"`
+	IDs              []string             `yaml:"ids,omitempty"`
+	Goarm            string               `yaml:"goarm,omitempty"`
 }
 
 // Scoop contains the scoop.sh section
diff --git a/pkg/context/context.go b/pkg/context/context.go
index 096f3f89..624366ee 100644
--- a/pkg/context/context.go
+++ b/pkg/context/context.go
@@ -90,6 +90,7 @@ type Semver struct {
 	Major      uint64
 	Minor      uint64
 	Patch      uint64
+	RawVersion string
 	Prerelease string
 }
 
diff --git a/www/docs/customization/homebrew.md b/www/docs/customization/homebrew.md
index ec3795b9..60552cc7 100644
--- a/www/docs/customization/homebrew.md
+++ b/www/docs/customization/homebrew.md
@@ -36,7 +36,6 @@ brews:
     # Default is 6 for all artifacts or each id if there a multiple versions.
     goarm: 6
 
-
     # NOTE: make sure the url_template, the token and given repo (github or gitlab) owner and name are from the
     # same kind. We will probably unify this in the next major version like it is done with scoop.
 
@@ -106,8 +105,9 @@ brews:
 
     # Packages your package depends on.
     dependencies:
-      - git
-      - zsh
+      - name: git
+      - name: zsh
+        type: optional
 
     # Packages that conflict with your package.
     conflicts:
@@ -165,7 +165,7 @@ class Program < Formula
   end
 
   depends_on "git"
-  depends_on "zsh"
+  depends_on "zsh" => :optional
 
   def install
     bin.install "program"
diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md
index ef0bddc3..ce520b19 100644
--- a/www/docs/customization/templates.md
+++ b/www/docs/customization/templates.md
@@ -10,21 +10,24 @@ templating is available.
 
 On fields that support templating, this fields are always available:
 
-|      Key       |                   Description                    |
-| :------------: | :----------------------------------------------: |
-| `.ProjectName` |                 the project name                 |
-|   `.Version`   | the version being released (`v` prefix stripped) |
-|     `.Tag`     |               the current git tag                |
-| `.ShortCommit` |            the git commit short hash             |
-| `.FullCommit`  |            the git commit full hash              |
-|   `.Commit`    |       the git commit hash (deprecated)           |
-|   `.GitURL`    |               the git remote url                 |
-|    `.Major`    |          the major part of the version           |
-|    `.Minor`    |          the minor part of the version           |
-|    `.Patch`    |          the patch part of the version           |
-|     `.Env`     |    a map with system's environment variables     |
-|    `.Date`     |        current UTC date in RFC3339 format        |
-|  `.Timestamp`  |         current UTC time in Unix format          |
+|       Key      |                                                          Description                                                         |
+|:--------------:|:----------------------------------------------------------------------------------------------------------------------------:|
+| `.ProjectName` |                                                       the project name                                                       |
+|   `.Version`   | the version being released (`v` prefix stripped),<br>or `{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}` in case of snapshot release |
+|     `.Tag`     |                                                      the current git tag                                                     |
+| `.ShortCommit` |                                                   the git commit short hash                                                  |
+|  `.FullCommit` |                                                   the git commit full hash                                                   |
+|    `.Commit`   |                                               the git commit hash (deprecated)                                               |
+|    `.GitURL`   |                                                      the git remote url                                                      |
+|    `.Major`    |                          the major part of the version (assuming `Tag` is a valid semver, else `0`)                          |
+|    `.Minor`    |                          the minor part of the version (assuming `Tag` is a valid semver, else `0`)                          |
+|    `.Patch`    |                          the patch part of the version (assuming `Tag` is a valid semver, else `0`)                          |
+|  `.Prerelease` |                      the prerelease part of the version, e.g. `beta` (assuming `Tag` is a valid semver)                      |
+|  `.RawVersion` |                              Major.Minor.Patch (assuming `Tag` is a valid semver, else `0.0.0`)                              |
+|  `.IsSnapshot` |                                   `true` if a snapshot is being released, `false` otherwise                                  |
+|     `.Env`     |                                           a map with system's environment variables                                          |
+|     `.Date`    |                                              current UTC date in RFC3339 format                                              |
+|  `.Timestamp`  |                                                current UTC time in Unix format                                               |
 
 On fields that are related to a single artifact (e.g., the binary name), you
 may have some extra fields:


Test patch:
diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go
index 92000072..f0b5d801 100644
--- a/internal/pipe/brew/brew_test.go
+++ b/internal/pipe/brew/brew_test.go
@@ -68,7 +68,7 @@ func assertDefaultTemplateData(t *testing.T, formulae string) {
 func TestFullFormulae(t *testing.T) {
 	data := defaultTemplateData
 	data.Caveats = []string{"Here are some caveats"}
-	data.Dependencies = []string{"gtk+"}
+	data.Dependencies = []config.HomebrewDependency{{Name: "gtk+"}}
 	data.Conflicts = []string{"svn"}
 	data.Plist = "it works"
 	data.CustomBlock = []string{"devel do", `  url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, `  sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"}
@@ -209,7 +209,7 @@ func TestRunPipe(t *testing.T) {
 							Caveats:      "don't do this {{ .ProjectName }}",
 							Test:         "system \"true\"\nsystem \"#{bin}/foo -h\"",
 							Plist:        `<xml>whatever</xml>`,
-							Dependencies: []string{"zsh", "bash"},
+							Dependencies: []config.HomebrewDependency{{Name: "zsh", Type: "optional"}, {Name: "bash"}},
 							Conflicts:    []string{"gtk+", "qt"},
 							Install:      `bin.install "{{ .ProjectName }}"`,
 						},
@@ -298,7 +298,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
 						Caveats:      "don't do this {{ .ProjectName }}",
 						Test:         "system \"true\"\nsystem \"#{bin}/foo -h\"",
 						Plist:        `<xml>whatever</xml>`,
-						Dependencies: []string{"zsh", "bash"},
+						Dependencies: []config.HomebrewDependency{{Name: "zsh"}, {Name: "bash", Type: "recommended"}},
 						Conflicts:    []string{"gtk+", "qt"},
 						Install:      `bin.install "{{ .ProjectName }}"`,
 						GitHub: config.Repo{
diff --git a/internal/pipe/brew/testdata/binary_overridden.rb.golden b/internal/pipe/brew/testdata/binary_overridden.rb.golden
index 2704b242..57fbdd10 100644
--- a/internal/pipe/brew/testdata/binary_overridden.rb.golden
+++ b/internal/pipe/brew/testdata/binary_overridden.rb.golden
@@ -9,7 +9,7 @@ class BinaryOverridden < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/custom_block.rb.golden b/internal/pipe/brew/testdata/custom_block.rb.golden
index 8cb4f908..70d9acb9 100644
--- a/internal/pipe/brew/testdata/custom_block.rb.golden
+++ b/internal/pipe/brew/testdata/custom_block.rb.golden
@@ -13,7 +13,7 @@ class CustomBlock < Formula
   
   head "https://github.com/caarlos0/test.git"
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
index 6b52afb5..800aaf20 100644
--- a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
+++ b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
@@ -11,7 +11,7 @@ class CustomDownloadStrategy < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/custom_require.rb.golden b/internal/pipe/brew/testdata/custom_require.rb.golden
index fa8bcc60..c6c398f9 100644
--- a/internal/pipe/brew/testdata/custom_require.rb.golden
+++ b/internal/pipe/brew/testdata/custom_require.rb.golden
@@ -12,7 +12,7 @@ class CustomRequire < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/default.rb.golden b/internal/pipe/brew/testdata/default.rb.golden
index 74f03a1e..946c1204 100644
--- a/internal/pipe/brew/testdata/default.rb.golden
+++ b/internal/pipe/brew/testdata/default.rb.golden
@@ -11,7 +11,7 @@ class Default < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/default_gitlab.rb.golden b/internal/pipe/brew/testdata/default_gitlab.rb.golden
index dc88ca02..9edceec6 100644
--- a/internal/pipe/brew/testdata/default_gitlab.rb.golden
+++ b/internal/pipe/brew/testdata/default_gitlab.rb.golden
@@ -11,7 +11,7 @@ class DefaultGitlab < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/github_enterprise_url.rb.golden b/internal/pipe/brew/testdata/github_enterprise_url.rb.golden
index 49069d67..656fb7fe 100644
--- a/internal/pipe/brew/testdata/github_enterprise_url.rb.golden
+++ b/internal/pipe/brew/testdata/github_enterprise_url.rb.golden
@@ -11,7 +11,7 @@ class GithubEnterpriseUrl < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/gitlab_enterprise_url.rb.golden b/internal/pipe/brew/testdata/gitlab_enterprise_url.rb.golden
index 1e550141..c02f5bc8 100644
--- a/internal/pipe/brew/testdata/gitlab_enterprise_url.rb.golden
+++ b/internal/pipe/brew/testdata/gitlab_enterprise_url.rb.golden
@@ -11,7 +11,7 @@ class GitlabEnterpriseUrl < Formula
   elsif OS.linux?
   end
   
-  depends_on "zsh"
+  depends_on "zsh" => :optional
   depends_on "bash"
   
   conflicts_with "gtk+"
diff --git a/internal/pipe/brew/testdata/multiple_armv5.rb.golden b/internal/pipe/brew/testdata/multiple_armv5.rb.golden
index 52fdc183..3301fed4 100644
--- a/internal/pipe/brew/testdata/multiple_armv5.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv5.rb.golden
@@ -21,7 +21,7 @@ class MultipleArmv5 < Formula
   end
   
   depends_on "zsh"
-  depends_on "bash"
+  depends_on "bash" => :recommended
   
   conflicts_with "gtk+"
   conflicts_with "qt"
diff --git a/internal/pipe/brew/testdata/multiple_armv6.rb.golden b/internal/pipe/brew/testdata/multiple_armv6.rb.golden
index 7d9906e9..96153b32 100644
--- a/internal/pipe/brew/testdata/multiple_armv6.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv6.rb.golden
@@ -21,7 +21,7 @@ class MultipleArmv6 < Formula
   end
   
   depends_on "zsh"
-  depends_on "bash"
+  depends_on "bash" => :recommended
   
   conflicts_with "gtk+"
   conflicts_with "qt"
diff --git a/internal/pipe/brew/testdata/multiple_armv7.rb.golden b/internal/pipe/brew/testdata/multiple_armv7.rb.golden
index 3c4fd401..4876d051 100644
--- a/internal/pipe/brew/testdata/multiple_armv7.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv7.rb.golden
@@ -21,7 +21,7 @@ class MultipleArmv7 < Formula
   end
   
   depends_on "zsh"
-  depends_on "bash"
+  depends_on "bash" => :recommended
   
   conflicts_with "gtk+"
   conflicts_with "qt"