Repository: goreleaser/goreleaser
Pull request #2287 (2021-06-05 02:26:10)

feat: remove :latest imgs from release notes
I was thinking... does it makes sense to add the `:latest` docker images to the release notes? After all, **it will be wrong** eventually anyway...

I'm thinking... maybe its better if we just don't print those imgs there?

wdyt?



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/EQ8j3wQ7GAK4ZnekXrMYouRm3g69](https://vercel.com/goreleaser/goreleaser/EQ8j3wQ7GAK4ZnekXrMYouRm3g69)  
✅ Preview: [https://goreleaser-git-remove-latest-from-release-notes-goreleaser.vercel.app](https://goreleaser-git-remove-latest-from-release-notes-goreleaser.vercel.app)


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2287](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (4d7be17) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/a9ea729c96884a905505ef29b747675033f714a1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (a9ea729) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2287/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2287      +/-   ##
==========================================
+ Coverage   82.64%   82.66%   +0.02%     
==========================================
  Files          79       79              
  Lines        4292     4297       +5     
==========================================
+ Hits         3547     3552       +5     
  Misses        605      605              
  Partials      140      140              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/pipe/release/body.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2287/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS9yZWxlYXNlL2JvZHkuZ28=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [a9ea729...4d7be17](https://codecov.io/gh/goreleaser/goreleaser/pull/2287?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).

marcauberer: @caarlos0 Because in older releases the image for `latest` is also included, but will reference a newer image version? Yes, that is a justified thought ...
caarlos0: > Because in older releases the image for `latest` is also included, but will reference a newer image version?

exactly...

Patch:
diff --git a/internal/pipe/release/body.go b/internal/pipe/release/body.go
index 5e775041..05c7c720 100644
--- a/internal/pipe/release/body.go
+++ b/internal/pipe/release/body.go
@@ -2,6 +2,7 @@ package release
 
 import (
 	"bytes"
+	"strings"
 	"text/template"
 
 	"github.com/goreleaser/goreleaser/internal/artifact"
@@ -21,15 +22,25 @@ const bodyTemplateText = `{{ with .Header }}{{ . }}{{ "\n" }}{{ end }}
 {{- with .Footer }}{{ "\n" }}{{ . }}{{ end }}
 `
 
+func isLatest(img string) bool {
+	return strings.HasSuffix(img, ":latest") || !strings.Contains(img, ":")
+}
+
 func describeBody(ctx *context.Context) (bytes.Buffer, error) {
 	var out bytes.Buffer
 	// nolint:prealloc
 	var dockers []string
 	for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerManifest)).List() {
+		if isLatest(a.Name) {
+			continue
+		}
 		dockers = append(dockers, a.Name)
 	}
 	if len(dockers) == 0 {
 		for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() {
+			if isLatest(a.Name) {
+				continue
+			}
 			dockers = append(dockers, a.Name)
 		}
 	}


Test patch:
diff --git a/internal/pipe/release/body_test.go b/internal/pipe/release/body_test.go
index 5546de20..440d2da8 100644
--- a/internal/pipe/release/body_test.go
+++ b/internal/pipe/release/body_test.go
@@ -17,6 +17,7 @@ func TestDescribeBody(t *testing.T) {
 	for _, d := range []string{
 		"goreleaser/goreleaser:0.40.0",
 		"goreleaser/goreleaser:latest",
+		"goreleaser/goreleaser",
 		"goreleaser/godownloader:v0.1.0",
 	} {
 		ctx.Artifacts.Add(&artifact.Artifact{
@@ -94,7 +95,7 @@ func TestDescribeBodyWithHeaderAndFooter(t *testing.T) {
 	})
 	ctx.ReleaseNotes = changelog
 	ctx.Artifacts.Add(&artifact.Artifact{
-		Name: "goreleaser/goreleaser:latest",
+		Name: "goreleaser/goreleaser:v1.2.3",
 		Type: artifact.DockerImage,
 	})
 	out, err := describeBody(ctx)
diff --git a/internal/pipe/release/testdata/TestDescribeBody.golden b/internal/pipe/release/testdata/TestDescribeBody.golden
index 1005de7a..2aba26e7 100644
--- a/internal/pipe/release/testdata/TestDescribeBody.golden
+++ b/internal/pipe/release/testdata/TestDescribeBody.golden
@@ -4,5 +4,4 @@ feature2: other description
 ## Docker images
 
 - `docker pull goreleaser/goreleaser:0.40.0`
-- `docker pull goreleaser/goreleaser:latest`
 - `docker pull goreleaser/godownloader:v0.1.0`
diff --git a/internal/pipe/release/testdata/TestDescribeBodyWithDockerManifest.golden b/internal/pipe/release/testdata/TestDescribeBodyWithDockerManifest.golden
index 1005de7a..2aba26e7 100644
--- a/internal/pipe/release/testdata/TestDescribeBodyWithDockerManifest.golden
+++ b/internal/pipe/release/testdata/TestDescribeBodyWithDockerManifest.golden
@@ -4,5 +4,4 @@ feature2: other description
 ## Docker images
 
 - `docker pull goreleaser/goreleaser:0.40.0`
-- `docker pull goreleaser/goreleaser:latest`
 - `docker pull goreleaser/godownloader:v0.1.0`
diff --git a/internal/pipe/release/testdata/TestDescribeBodyWithHeaderAndFooter.golden b/internal/pipe/release/testdata/TestDescribeBodyWithHeaderAndFooter.golden
index 3cfbe383..12f31767 100644
--- a/internal/pipe/release/testdata/TestDescribeBodyWithHeaderAndFooter.golden
+++ b/internal/pipe/release/testdata/TestDescribeBodyWithHeaderAndFooter.golden
@@ -6,7 +6,7 @@ feature2: other description
 
 ## Docker images
 
-- `docker pull goreleaser/goreleaser:latest`
+- `docker pull goreleaser/goreleaser:v1.2.3`
 
 ---