Repository: goreleaser/goreleaser
Pull request #1552 (2020-05-23 12:45:50)

feat: allow signing only the source
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Please fill the fields above:

-->

<!-- If applied, this commit will... -->
Allow to sign the source artifact only.

<!-- Why is this change being made? -->
I wanted to sign both checksum and source without having to sign all the artifacts

<!-- # Provide links to any relevant tickets, URLs or other resources -->

```yaml
source:
  enabled: true
checksum:
  name_template: 'checksums.txt'
signs:
- id: default
  artifacts: checksum
- id: source
  artifacts: source
```

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 on the icon next to each commit.
	
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1552?src=pr&el=h1) Report
> Merging [#1552](https://codecov.io/gh/goreleaser/goreleaser/pull/1552?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/b2b418c6a7cce4b6b9c46c2d68876c0508e21c1b&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `50.00%`.

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

```diff
@@            Coverage Diff             @@
##           master    #1552      +/-   ##
==========================================
- Coverage   85.55%   85.51%   -0.04%     
==========================================
  Files          69       69              
  Lines        3815     3819       +4     
==========================================
+ Hits         3264     3266       +2     
- Misses        457      458       +1     
- Partials       94       95       +1     
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1552?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/sign/sign.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1552/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9zaWduL3NpZ24uZ28=) | `97.80% <50.00%> (-2.20%)` | :arrow_down: |

------

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

caarlos0: Thanks for the PR 🚀 

Patch:
diff --git a/internal/pipe/sign/sign.go b/internal/pipe/sign/sign.go
index bffba548..b48d9b26 100644
--- a/internal/pipe/sign/sign.go
+++ b/internal/pipe/sign/sign.go
@@ -67,6 +67,11 @@ func (Pipe) Run(ctx *context.Context) error {
 				if len(cfg.IDs) > 0 {
 					log.Warn("when artifacts is `checksum`, `ids` has no effect. ignoring")
 				}
+			case "source":
+				filters = append(filters, artifact.ByType(artifact.UploadableSourceArchive))
+				if len(cfg.IDs) > 0 {
+					log.Warn("when artifacts is `source`, `ids` has no effect. ignoring")
+				}
 			case "all":
 				filters = append(filters, artifact.Or(
 					artifact.ByType(artifact.UploadableArchive),
diff --git a/www/docs/customization/sign.md b/www/docs/customization/sign.md
index c58b0158..ead008c9 100644
--- a/www/docs/customization/sign.md
+++ b/www/docs/customization/sign.md
@@ -58,13 +58,14 @@ signs:
     #   checksum: only checksum file(s)
     #   all:      all artifacts
     #   none:     no signing
+    #   source:   source archive
     #
     # defaults to `none`
     artifacts: all
 
     # IDs of the artifacts to sign.
     # Defaults to all.
-    # If `artifacts` is checksum, this fields has no effect.
+    # If `artifacts` is checksum or source, this fields has no effect.
     ids:
       - foo
       - bar


Test patch:
diff --git a/internal/pipe/sign/sign_test.go b/internal/pipe/sign/sign_test.go
index 046adaea..bdb42aa1 100644
--- a/internal/pipe/sign/sign_test.go
+++ b/internal/pipe/sign/sign_test.go
@@ -128,8 +128,8 @@ func TestSignArtifacts(t *testing.T) {
 					},
 				},
 			),
-			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig"},
-			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig"},
+			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig", "artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig", "artifact5.tar.gz.sig"},
 		},
 		{
 			desc: "sign all artifacts",
@@ -142,8 +142,8 @@ func TestSignArtifacts(t *testing.T) {
 					},
 				},
 			),
-			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig"},
-			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig"},
+			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig", "artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig", "artifact5.tar.gz.sig"},
 		},
 		{
 			desc: "multiple sign configs",
@@ -187,8 +187,8 @@ func TestSignArtifacts(t *testing.T) {
 					},
 				},
 			),
-			signaturePaths: []string{"artifact1.sig", "artifact3.sig", "checksum.sig", "checksum2.sig"},
-			signatureNames: []string{"artifact1.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig"},
+			signaturePaths: []string{"artifact1.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact1.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact5.tar.gz.sig"},
 		},
 		{
 			desc: "sign only checksums",
@@ -219,6 +219,20 @@ func TestSignArtifacts(t *testing.T) {
 			signaturePaths: []string{"checksum.sig", "checksum2.sig"},
 			signatureNames: []string{"checksum.sig", "checksum2.sig"},
 		},
+		{
+			desc: "sign only source",
+			ctx: context.New(
+				config.Project{
+					Signs: []config.Sign{
+						{
+							Artifacts: "source",
+						},
+					},
+				},
+			),
+			signaturePaths: []string{"artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact5.tar.gz.sig"},
+		},
 		{
 			desc: "sign all artifacts with env",
 			ctx: context.New(
@@ -241,8 +255,8 @@ func TestSignArtifacts(t *testing.T) {
 					},
 				},
 			),
-			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig"},
-			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig"},
+			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig", "artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig", "artifact5.tar.gz.sig"},
 		},
 		{
 			desc: "sign all artifacts with template",
@@ -266,8 +280,8 @@ func TestSignArtifacts(t *testing.T) {
 					},
 				},
 			),
-			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig"},
-			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig"},
+			signaturePaths: []string{"artifact1.sig", "artifact2.sig", "artifact3.sig", "checksum.sig", "checksum2.sig", "linux_amd64/artifact4.sig", "artifact5.tar.gz.sig"},
+			signatureNames: []string{"artifact1.sig", "artifact2.sig", "artifact3_1.0.0_linux_amd64.sig", "checksum.sig", "checksum2.sig", "artifact4_1.0.0_linux_amd64.sig", "artifact5.tar.gz.sig"},
 		},
 	}
 
@@ -298,6 +312,8 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
 	}
 	assert.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "linux_amd64", "artifact4"), []byte("foo"), 0644))
 	artifacts = append(artifacts, "linux_amd64/artifact4")
+	assert.NoError(t, ioutil.WriteFile(filepath.Join(tmpdir, "artifact5.tar.gz"), []byte("foo"), 0644))
+	artifacts = append(artifacts, "artifact5.tar.gz")
 	ctx.Artifacts.Add(&artifact.Artifact{
 		Name: "artifact1",
 		Path: filepath.Join(tmpdir, "artifact1"),
@@ -340,6 +356,11 @@ func testSign(t *testing.T, ctx *context.Context, signaturePaths []string, signa
 			"ID": "foo3",
 		},
 	})
+	ctx.Artifacts.Add(&artifact.Artifact{
+		Name: "artifact5.tar.gz",
+		Path: filepath.Join(tmpdir, "artifact5.tar.gz"),
+		Type: artifact.UploadableSourceArchive,
+	})
 
 	// configure the pipeline
 	// make sure we are using the test keyring