Repository: goreleaser/nfpm
Pull request #696 (2023-08-10 16:09:23)

feat: add minimal support for Debian pre-dependencies
Basic support for adding 'Pre-Depends:' to Debian packages added.

jeremy-gill: @caarlos0, I've moved the 'predepends' tag from the platform-independent area to a Debian-specific location.  I've also tweaked `deb/deb_test.go` to provide some minimal testing of the new tag.  Finally, I updated the `www/docs/configuration.md` to explain the use of the new tag.  Is this the change you were looking for?
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/goreleaser/nfpm/pull/696?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#696](https://app.codecov.io/gh/goreleaser/nfpm/pull/696?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (94b5690) into [main](https://app.codecov.io/gh/goreleaser/nfpm/commit/24a43c5ad7cfc549e8a4ec930521a97a30f26cc8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (24a43c5) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main     #696      +/-   ##
==========================================
+ Coverage   75.02%   75.03%   +0.01%     
==========================================
  Files          10       10              
  Lines        2406     2407       +1     
==========================================
+ Hits         1805     1806       +1     
  Misses        425      425              
  Partials      176      176              
```


| [Files Changed](https://app.codecov.io/gh/goreleaser/nfpm/pull/696?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [deb/deb.go](https://app.codecov.io/gh/goreleaser/nfpm/pull/696?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-ZGViL2RlYi5nbw==) | `72.42% <ø> (ø)` | |
| [nfpm.go](https://app.codecov.io/gh/goreleaser/nfpm/pull/696?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-bmZwbS5nbw==) | `85.06% <100.00%> (+0.06%)` | :arrow_up: |


caarlos0: thank you, I'll add an integration test too.

Patch:
diff --git a/deb/deb.go b/deb/deb.go
index 625ad9f..92938de 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -720,6 +720,9 @@ Replaces: {{join .}}
 {{- with nonEmpty .Info.Provides}}
 Provides: {{join .}}
 {{- end }}
+{{- with .Info.Deb.Predepends}}
+Pre-Depends: {{join .}}
+{{- end }}
 {{- with .Info.Depends}}
 Depends: {{join .}}
 {{- end }}
diff --git a/nfpm.go b/nfpm.go
index f99c6c9..67bbe7b 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -235,6 +235,7 @@ func (c *Config) expandEnvVars() {
 	for k, v := range c.Info.Deb.Fields {
 		c.Info.Deb.Fields[k] = os.Expand(v, c.envMappingFunc)
 	}
+	c.Info.Deb.Predepends = c.expandEnvVarsStringSlice(c.Info.Deb.Predepends)
 }
 
 // Info contains information about a single package.
@@ -390,6 +391,7 @@ type Deb struct {
 	Signature   DebSignature      `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=signature"`
 	Compression string            `yaml:"compression,omitempty" json:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=xz,enum=none,default=gzip"`
 	Fields      map[string]string `yaml:"fields,omitempty" json:"fields,omitempty" jsonschema:"title=fields"`
+	Predepends  []string          `yaml:"predepends,omitempty" json:"predepends,omitempty" jsonschema:"title=predepends directive,example=nfpm"`
 }
 
 type DebSignature struct {
diff --git a/www/docs/configuration.md b/www/docs/configuration.md
index 12f4818..de56332 100644
--- a/www/docs/configuration.md
+++ b/www/docs/configuration.md
@@ -408,6 +408,12 @@ deb:
   fields:
     Bugs: https://github.com/goreleaser/nfpm/issues
 
+  # The Debian-specific "predepends" field can be used to ensure the complete installation of a list of
+  # packages (including unpacking, pre- and post installation scripts) prior to the installation of the
+  # built package.
+  predepends:
+    - baz (>= 1.2.3-0)
+
 apk:
   # apk specific architecture name that overrides "arch" without performing any replacements.
   apk_arch: armhf


Test patch:
diff --git a/deb/deb_test.go b/deb/deb_test.go
index 6769deb..83ad3b8 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -88,6 +88,9 @@ func exampleInfo() *nfpm.Info {
 					Type:        files.TypeDir,
 				},
 			},
+			Deb: nfpm.Deb{
+				Predepends: []string{"less"},
+			},
 		},
 	})
 }
diff --git a/deb/testdata/bad_provides.golden b/deb/testdata/bad_provides.golden
index 0de8682..05c7f16 100644
--- a/deb/testdata/bad_provides.golden
+++ b/deb/testdata/bad_provides.golden
@@ -6,6 +6,7 @@ Architecture: amd64
 Maintainer: Carlos A Becker <pkg@carlosbecker.com>
 Installed-Size: 0
 Replaces: svn
+Pre-Depends: less
 Depends: bash
 Recommends: git
 Suggests: bash
diff --git a/deb/testdata/control.golden b/deb/testdata/control.golden
index 513f5e9..807461b 100644
--- a/deb/testdata/control.golden
+++ b/deb/testdata/control.golden
@@ -7,6 +7,7 @@ Maintainer: Carlos A Becker <pkg@carlosbecker.com>
 Installed-Size: 10
 Replaces: svn
 Provides: bzr
+Pre-Depends: less
 Depends: bash
 Recommends: git
 Suggests: bash