Repository: goreleaser/goreleaser
Pull request #1011 (2019-04-18 19:46:10)

feat: add base key to snapcraft
Hi there!

I've added the base key to the snapcraft pipe.

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1011?src=pr&el=h1) Report
> Merging [#1011](https://codecov.io/gh/goreleaser/goreleaser/pull/1011?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/3da2b375c9f2c8e859f9546c6779dd024c032cda?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/1011/graphs/tree.svg?width=650&token=3bJvv6b7hN&height=150&src=pr)](https://codecov.io/gh/goreleaser/goreleaser/pull/1011?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1011      +/-   ##
==========================================
+ Coverage   88.32%   88.33%   +<.01%     
==========================================
  Files          52       52              
  Lines        2562     2564       +2     
==========================================
+ Hits         2263     2265       +2     
  Misses        236      236              
  Partials       63       63
```


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

------

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

caarlos0: awesome, thank you! :D

Patch:
diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go
index 70ff481f..28cf4309 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
+	Base          string `yaml:",omitempty"`
 	License       string `yaml:",omitempty"`
 	Grade         string `yaml:",omitempty"`
 	Confinement   string `yaml:",omitempty"`
@@ -147,6 +148,10 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err
 		Apps:          map[string]AppMetadata{},
 	}
 
+	if ctx.Config.Snapcraft.Base != "" {
+		metadata.Base = ctx.Config.Snapcraft.Base
+	}
+
 	if ctx.Config.Snapcraft.License != "" {
 		metadata.License = ctx.Config.Snapcraft.License
 	}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index facf83d9..6b164035 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"`
+	Base        string                          `yaml:",omitempty"`
 	License     string                          `yaml:",omitempty"`
 	Grade       string                          `yaml:",omitempty"`
 	Confinement string                          `yaml:",omitempty"`
diff --git a/www/content/snapcraft.md b/www/content/snapcraft.md
index 9d766c66..21c7977f 100644
--- a/www/content/snapcraft.md
+++ b/www/content/snapcraft.md
@@ -73,6 +73,14 @@ snapcraft:
   # Your app's license, based on SPDX license expressions: https://spdx.org/licenses
   # Default is empty.
   license: MIT
+  
+  # A snap of type base to be used as the execution environment for this snap.
+  # Valid values are:
+  # * bare - Empty base snap;
+  # * core - Ubuntu Core 16;
+  # * core18 - Ubuntu Core 18.
+  # Default is empty.
+  base: core18
 
   # 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 63962431..461364ba 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",
+			Base:         "core18",
 			License:      "MIT",
 			Summary:      "test summary",
 			Description:  "test description",
@@ -111,6 +112,7 @@ func TestRunPipeWithName(t *testing.T) {
 	err = yaml.Unmarshal(yamlFile, &metadata)
 	assert.NoError(t, err)
 	assert.Equal(t, "testsnapname", metadata.Name)
+	assert.Equal(t, "core18", metadata.Base)
 	assert.Equal(t, "MIT", metadata.License)
 	assert.Equal(t, "mybin", metadata.Apps["mybin"].Command)
 	assert.Equal(t, "mybin", metadata.Apps["testsnapname"].Command)
@@ -142,6 +144,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.Base)
 	assert.Equal(t, "", metadata.License)
 	assert.Equal(t, "mybin", metadata.Apps["mybin"].Command)
 	assert.Equal(t, "mybin", metadata.Apps["testsnapname"].Command)