Repository: goreleaser/goreleaser
Pull request #1837 (2020-10-06 01:08:44)

feat: snap restart-condition
refs #1664

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/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/1j9i5vc70](https://vercel.com/goreleaser/goreleaser/1j9i5vc70)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1837?src=pr&el=h1) Report
> Merging [#1837](https://codecov.io/gh/goreleaser/goreleaser/pull/1837?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/a6a4f293743e37b497d85b7f8c4cc451aa015ed8?el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

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

```diff
@@           Coverage Diff           @@
##           master    #1837   +/-   ##
=======================================
  Coverage   81.28%   81.29%           
=======================================
  Files          72       72           
  Lines        3698     3699    +1     
=======================================
+ Hits         3006     3007    +1     
  Misses        570      570           
  Partials      122      122           
```


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

------

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


Patch:
diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go
index a89c7b64..561cd101 100644
--- a/internal/pipe/snapcraft/snapcraft.go
+++ b/internal/pipe/snapcraft/snapcraft.go
@@ -49,10 +49,11 @@ type Metadata struct {
 
 // AppMetadata for the binaries that will be in the snap package.
 type AppMetadata struct {
-	Command   string
-	Plugs     []string `yaml:",omitempty"`
-	Daemon    string   `yaml:",omitempty"`
-	Completer string   `yaml:",omitempty"`
+	Command          string
+	Plugs            []string `yaml:",omitempty"`
+	Daemon           string   `yaml:",omitempty"`
+	Completer        string   `yaml:",omitempty"`
+	RestartCondition string   `yaml:"restart-condition,omitempty"`
 }
 
 const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
@@ -255,8 +256,9 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
 				command,
 				config.Args,
 			}, " ")),
-			Plugs:  config.Plugs,
-			Daemon: config.Daemon,
+			Plugs:            config.Plugs,
+			Daemon:           config.Daemon,
+			RestartCondition: config.RestartCondition,
 		}
 
 		if config.Completer != "" {
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 8ff3fff8..83d58f26 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -353,11 +353,12 @@ type Sign struct {
 
 // SnapcraftAppMetadata for the binaries that will be in the snap package.
 type SnapcraftAppMetadata struct {
-	Plugs     []string
-	Daemon    string
-	Args      string
-	Completer string `yaml:",omitempty"`
-	Command   string `yaml:"command"`
+	Plugs            []string
+	Daemon           string
+	Args             string
+	Completer        string `yaml:",omitempty"`
+	Command          string `yaml:"command"`
+	RestartCondition string `yaml:"restart_condition,omitempty"`
 }
 
 // Snapcraft config.
diff --git a/www/docs/customization/snapcraft.md b/www/docs/customization/snapcraft.md
index 690dd9a6..0c241ca6 100644
--- a/www/docs/customization/snapcraft.md
+++ b/www/docs/customization/snapcraft.md
@@ -128,6 +128,11 @@ snapcrafts:
         # Defaults is the app name.
         command: bin/drumroll.wrapper
 
+        # Restart condition of the snap.
+        # Defaults to empty.
+        # https://snapcraft.io/docs/snapcraft-yaml-reference
+        restart_condition: "always"
+
     # Allows plugs to be configured. Plugs like system-files and personal-files
     # require this.
     # Default is empty.


Test patch:
diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go
index b1d968c5..eac791e5 100644
--- a/internal/pipe/snapcraft/snapcraft_test.go
+++ b/internal/pipe/snapcraft/snapcraft_test.go
@@ -202,9 +202,10 @@ func TestRunPipeMetadata(t *testing.T) {
 				Description:  "test description",
 				Apps: map[string]config.SnapcraftAppMetadata{
 					"mybin": {
-						Plugs:  []string{"home", "network", "personal-files"},
-						Daemon: "simple",
-						Args:   "--foo --bar",
+						Plugs:            []string{"home", "network", "personal-files"},
+						Daemon:           "simple",
+						Args:             "--foo --bar",
+						RestartCondition: "always",
 					},
 				},
 				Plugs: map[string]interface{}{
@@ -231,7 +232,8 @@ func TestRunPipeMetadata(t *testing.T) {
 	require.Equal(t, []string{"home", "network", "personal-files"}, metadata.Apps["mybin"].Plugs)
 	require.Equal(t, "simple", metadata.Apps["mybin"].Daemon)
 	require.Equal(t, "mybin --foo --bar", metadata.Apps["mybin"].Command)
-	require.Equal(t, map[interface{}]interface{}(map[interface{}]interface{}{"read": []interface{}{"$HOME/test"}}), metadata.Plugs["personal-files"])
+	require.Equal(t, map[interface{}]interface{}{"read": []interface{}{"$HOME/test"}}, metadata.Plugs["personal-files"])
+	require.Equal(t, "always", metadata.Apps["mybin"].RestartCondition)
 }
 
 func TestNoSnapcraftInPath(t *testing.T) {