Repository: goreleaser/goreleaser
Pull request #1010 (2019-04-17 19:09:13)

feat: add license to snapcraft

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1010?src=pr&el=h1) Report
> Merging [#1010](https://codecov.io/gh/goreleaser/goreleaser/pull/1010?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/b8f590126537beb8f269f424bb63f8326f469152?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master    #1010      +/-   ##
==========================================
+ Coverage   88.32%   88.32%   +<.01%     
==========================================
  Files          52       52              
  Lines        2560     2562       +2     
==========================================
+ Hits         2261     2263       +2     
  Misses        236      236              
  Partials       63       63
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1010?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1010/diff?src=pr&el=tree#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `100% <ø> (ø)` | :arrow_up: |
| [internal/pipe/snapcraft/snapcraft.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1010/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9zbmFwY3JhZnQvc25hcGNyYWZ0Lmdv) | `88.28% <100%> (+0.18%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1010?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/1010?src=pr&el=footer). Last update [b8f5901...77e8598](https://codecov.io/gh/goreleaser/goreleaser/pull/1010?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

caarlos0: Awesome, thanks @mgrachev !

Patch:
diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go
index 6ec3b2ca..70ff481f 100644
--- a/internal/pipe/snapcraft/snapcraft.go
+++ b/internal/pipe/snapcraft/snapcraft.go
@@ -35,6 +35,7 @@ type Metadata struct {
 	Version       string
 	Summary       string
 	Description   string
+	License       string `yaml:",omitempty"`
 	Grade         string `yaml:",omitempty"`
 	Confinement   string `yaml:",omitempty"`
 	Architectures []string
@@ -146,6 +147,10 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err
 		Apps:          map[string]AppMetadata{},
 	}
 
+	if ctx.Config.Snapcraft.License != "" {
+		metadata.License = ctx.Config.Snapcraft.License
+	}
+
 	metadata.Name = ctx.Config.ProjectName
 	if ctx.Config.Snapcraft.Name != "" {
 		metadata.Name = ctx.Config.Snapcraft.Name
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 232d9f40..facf83d9 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -227,6 +227,7 @@ type Snapcraft struct {
 	Name        string                          `yaml:",omitempty"`
 	Summary     string                          `yaml:",omitempty"`
 	Description string                          `yaml:",omitempty"`
+	License     string                          `yaml:",omitempty"`
 	Grade       string                          `yaml:",omitempty"`
 	Confinement string                          `yaml:",omitempty"`
 	Apps        map[string]SnapcraftAppMetadata `yaml:",omitempty"`
diff --git a/www/content/snapcraft.md b/www/content/snapcraft.md
index 6f970be5..9d766c66 100644
--- a/www/content/snapcraft.md
+++ b/www/content/snapcraft.md
@@ -69,6 +69,10 @@ snapcraft:
   # are explained later. More info about confinement here:
   # https://snapcraft.io/docs/reference/confinement
   confinement: strict
+  
+  # Your app's license, based on SPDX license expressions: https://spdx.org/licenses
+  # Default is empty.
+  license: MIT
 
   # Each binary built by GoReleaser is an app inside the snap. In this section
   # you can declare extra details for those binaries. It is optional.


Test patch:
diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go
index b9a44990..63962431 100644
--- a/internal/pipe/snapcraft/snapcraft_test.go
+++ b/internal/pipe/snapcraft/snapcraft_test.go
@@ -96,6 +96,7 @@ func TestRunPipeWithName(t *testing.T) {
 		Snapcraft: config.Snapcraft{
 			NameTemplate: "foo_{{.Arch}}",
 			Name:         "testsnapname",
+			License:      "MIT",
 			Summary:      "test summary",
 			Description:  "test description",
 		},
@@ -110,6 +111,7 @@ func TestRunPipeWithName(t *testing.T) {
 	err = yaml.Unmarshal(yamlFile, &metadata)
 	assert.NoError(t, err)
 	assert.Equal(t, "testsnapname", metadata.Name)
+	assert.Equal(t, "MIT", metadata.License)
 	assert.Equal(t, "mybin", metadata.Apps["mybin"].Command)
 	assert.Equal(t, "mybin", metadata.Apps["testsnapname"].Command)
 }
@@ -140,6 +142,7 @@ func TestRunPipeWithBinaryInDir(t *testing.T) {
 	err = yaml.Unmarshal(yamlFile, &metadata)
 	assert.NoError(t, err)
 	assert.Equal(t, "testsnapname", metadata.Name)
+	assert.Equal(t, "", metadata.License)
 	assert.Equal(t, "mybin", metadata.Apps["mybin"].Command)
 	assert.Equal(t, "mybin", metadata.Apps["testsnapname"].Command)
 }