Repository: goreleaser/goreleaser
Pull request #2965 (2022-03-09 01:15:38)

fix(aur): improve yay caching
both @muesli and @toby reported at separated times/versions that `yay` would fail to install the latest goreleaser version with an error like this:


![image](https://user-images.githubusercontent.com/245435/157353373-9a614939-3e2e-43af-abe0-803335360f02.png)

my best guess is that, since our archive names don't have the version in them, the archives were being cached by yay.

This probably happens with many more projects.

In any case, this should solve it by changing the file name to have the version in it. It also drops the redundant `linux` thing in it, as we wont have other OSs there anyway.

## workarounds

- clean build caches 

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2965?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2965](https://codecov.io/gh/goreleaser/goreleaser/pull/2965?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (978a562) into [main](https://codecov.io/gh/goreleaser/goreleaser/commit/2d9acf65b512ccf8b5a0f6a94f991223bbf1ce5d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (2d9acf6) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2965/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/2965?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@           Coverage Diff           @@
##             main    #2965   +/-   ##
=======================================
  Coverage   84.48%   84.48%           
=======================================
  Files         111      111           
  Lines        9008     9009    +1     
=======================================
+ Hits         7610     7611    +1     
  Misses       1124     1124           
  Partials      274      274           
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2965?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/2965?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [2d9acf6...978a562](https://codecov.io/gh/goreleaser/goreleaser/pull/2965?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).


Patch:
diff --git a/internal/pipe/aur/aur.go b/internal/pipe/aur/aur.go
index b045ca23..a1598141 100644
--- a/internal/pipe/aur/aur.go
+++ b/internal/pipe/aur/aur.go
@@ -312,6 +312,7 @@ func dataFor(ctx *context.Context, cfg config.AUR, cl client.Client, artifacts [
 			DownloadURL: url,
 			SHA256:      sum,
 			Arch:        toPkgBuildArch(art.Goarch + art.Goarm),
+			Format:      art.ExtraOr(artifact.ExtraFormat, "").(string),
 		}
 		result.ReleasePackages = append(result.ReleasePackages, releasePackage)
 		result.Arches = append(result.Arches, releasePackage.Arch)
diff --git a/internal/pipe/aur/tmpl.go b/internal/pipe/aur/tmpl.go
index afb97112..5e756432 100644
--- a/internal/pipe/aur/tmpl.go
+++ b/internal/pipe/aur/tmpl.go
@@ -22,6 +22,7 @@ type releasePackage struct {
 	DownloadURL string
 	SHA256      string
 	Arch        string
+	Format      string
 }
 
 const aurTemplateData = `# This file was generated by GoReleaser. DO NOT EDIT.
@@ -54,7 +55,7 @@ optdepends=({{ pkgArray . }})
 {{- end }}
 
 {{ range .ReleasePackages -}}
-source_{{ .Arch }}=('{{ .DownloadURL }}')
+source_{{ .Arch }}=('${pkgname}_${pkgver}_{{ .Arch }}.{{ .Format }}::{{ .DownloadURL }}')
 sha256sums_{{ .Arch }}=('{{ .SHA256 }}')
 {{ printf "" }}
 {{ end }}


Test patch:
diff --git a/internal/pipe/aur/aur_test.go b/internal/pipe/aur/aur_test.go
index 949d79e3..89055f45 100644
--- a/internal/pipe/aur/aur_test.go
+++ b/internal/pipe/aur/aur_test.go
@@ -64,26 +64,31 @@ func createTemplateData() templateData {
 				Arch:        "x86_64",
 				DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz",
 				SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
+				Format:      "tar.gz",
 			},
 			{
 				Arch:        "armv6h",
 				DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz",
 				SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
+				Format:      "tar.gz",
 			},
 			{
 				Arch:        "aarch64",
 				DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz",
 				SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
+				Format:      "tar.gz",
 			},
 			{
 				Arch:        "i686",
 				DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz",
 				SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
+				Format:      "tar.gz",
 			},
 			{
 				Arch:        "armv7h",
 				DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz",
 				SHA256:      "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
+				Format:      "tar.gz",
 			},
 		},
 	}
@@ -108,7 +113,7 @@ func TestAurSimple(t *testing.T) {
 	require.Contains(t, pkg, `# Contributor: Beltrano <beltrano@example.com>`)
 	require.Contains(t, pkg, `pkgname='test-bin'`)
 	require.Contains(t, pkg, `url='https://example.com'`)
-	require.Contains(t, pkg, `source_x86_64=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz')`)
+	require.Contains(t, pkg, `source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz')`)
 	require.Contains(t, pkg, `sha256sums_x86_64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')`)
 	require.Contains(t, pkg, `pkgver=0.1.3`)
 }
diff --git a/internal/pipe/aur/testdata/TestFullAur.golden b/internal/pipe/aur/testdata/TestFullAur.golden
index c1ce5ff5..ec859b63 100644
--- a/internal/pipe/aur/testdata/TestFullAur.golden
+++ b/internal/pipe/aur/testdata/TestFullAur.golden
@@ -16,19 +16,19 @@ conflicts=('nope')
 depends=('nope')
 optdepends=('nfpm')
 
-source_x86_64=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz')
 sha256sums_x86_64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')
 
-source_armv6h=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz')
+source_armv6h=('${pkgname}_${pkgver}_armv6h.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz')
 sha256sums_armv6h=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')
 
-source_aarch64=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz')
+source_aarch64=('${pkgname}_${pkgver}_aarch64.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz')
 sha256sums_aarch64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')
 
-source_i686=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz')
+source_i686=('${pkgname}_${pkgver}_i686.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz')
 sha256sums_i686=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')
 
-source_armv7h=('https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz')
+source_armv7h=('${pkgname}_${pkgver}_armv7h.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz')
 sha256sums_armv7h=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')
 
 package() {
diff --git a/internal/pipe/aur/testdata/TestFullPipe/default-gitlab.pkgbuild.golden b/internal/pipe/aur/testdata/TestFullPipe/default-gitlab.pkgbuild.golden
index 10543e1f..59208702 100644
--- a/internal/pipe/aur/testdata/TestFullPipe/default-gitlab.pkgbuild.golden
+++ b/internal/pipe/aur/testdata/TestFullPipe/default-gitlab.pkgbuild.golden
@@ -10,7 +10,7 @@ license=('MIT')
 provides=('default-gitlab')
 conflicts=('default-gitlab')
 
-source_x86_64=('https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
 sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
 package() {
diff --git a/internal/pipe/aur/testdata/TestFullPipe/default.pkgbuild.golden b/internal/pipe/aur/testdata/TestFullPipe/default.pkgbuild.golden
index ead70e19..397f4558 100644
--- a/internal/pipe/aur/testdata/TestFullPipe/default.pkgbuild.golden
+++ b/internal/pipe/aur/testdata/TestFullPipe/default.pkgbuild.golden
@@ -10,7 +10,7 @@ license=('MIT')
 provides=('default')
 conflicts=('default')
 
-source_x86_64=('https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
 sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
 package() {
diff --git a/internal/pipe/aur/testdata/TestFullPipe/with-more-opts.pkgbuild.golden b/internal/pipe/aur/testdata/TestFullPipe/with-more-opts.pkgbuild.golden
index c7a3348e..ad4fad1e 100644
--- a/internal/pipe/aur/testdata/TestFullPipe/with-more-opts.pkgbuild.golden
+++ b/internal/pipe/aur/testdata/TestFullPipe/with-more-opts.pkgbuild.golden
@@ -14,7 +14,7 @@ conflicts=('libcurl' 'cvs' 'blah')
 depends=('curl' 'bash')
 optdepends=('wget: stuff' 'foo: bar')
 
-source_x86_64=('https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz')
 sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
 package() {
diff --git a/internal/pipe/aur/testdata/TestRunPipe.pkgbuild.golden b/internal/pipe/aur/testdata/TestRunPipe.pkgbuild.golden
index ecf34aaa..16526bb2 100644
--- a/internal/pipe/aur/testdata/TestRunPipe.pkgbuild.golden
+++ b/internal/pipe/aur/testdata/TestRunPipe.pkgbuild.golden
@@ -10,19 +10,19 @@ license=('MIT')
 provides=('foo')
 conflicts=('foo')
 
-source_aarch64=('https://dummyhost/download/v1.0.1/arm64.tar.gz')
+source_aarch64=('${pkgname}_${pkgver}_aarch64.tar.gz::https://dummyhost/download/v1.0.1/arm64.tar.gz')
 sha256sums_aarch64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
-source_armv6h=('https://dummyhost/download/v1.0.1/armv6.tar.gz')
+source_armv6h=('${pkgname}_${pkgver}_armv6h.tar.gz::https://dummyhost/download/v1.0.1/armv6.tar.gz')
 sha256sums_armv6h=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
-source_armv7h=('https://dummyhost/download/v1.0.1/armv7.tar.gz')
+source_armv7h=('${pkgname}_${pkgver}_armv7h.tar.gz::https://dummyhost/download/v1.0.1/armv7.tar.gz')
 sha256sums_armv7h=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
-source_i686=('https://dummyhost/download/v1.0.1/bin.tar.gz')
+source_i686=('${pkgname}_${pkgver}_i686.tar.gz::https://dummyhost/download/v1.0.1/bin.tar.gz')
 sha256sums_i686=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
-source_x86_64=('https://dummyhost/download/v1.0.1/bin.tar.gz')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1/bin.tar.gz')
 sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
 package() {
diff --git a/internal/pipe/aur/testdata/TestRunPipeBinaryRelease.pkgbuild.golden b/internal/pipe/aur/testdata/TestRunPipeBinaryRelease.pkgbuild.golden
index c8a311ae..1d928755 100644
--- a/internal/pipe/aur/testdata/TestRunPipeBinaryRelease.pkgbuild.golden
+++ b/internal/pipe/aur/testdata/TestRunPipeBinaryRelease.pkgbuild.golden
@@ -10,7 +10,7 @@ license=('')
 provides=('foo')
 conflicts=('foo')
 
-source_x86_64=('https://dummyhost/download/v1.2.1/foo_linux_amd64')
+source_x86_64=('${pkgname}_${pkgver}_x86_64.binary::https://dummyhost/download/v1.2.1/foo_linux_amd64')
 sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
 
 package() {