diff --git a/internal/pipe/aur/aur.go b/internal/pipe/aur/aur.go index 151431f710e..981d8138ea4 100644 --- a/internal/pipe/aur/aur.go +++ b/internal/pipe/aur/aur.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" "sort" "strings" @@ -89,11 +90,12 @@ func runAll(ctx *context.Context, cli client.ReleaseURLTemplater) error { } func doRun(ctx *context.Context, aur config.AUR, cl client.ReleaseURLTemplater) error { - name, err := tmpl.New(ctx).Apply(aur.Name) - if err != nil { + if err := tmpl.New(ctx).ApplyAll( + &aur.Name, + &aur.Directory, + ); err != nil { return err } - aur.Name = name filters := []artifact.Filter{ artifact.ByGoos("linux"), @@ -392,7 +394,7 @@ func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error { return err } files = append(files, client.RepoFile{ - Path: pkg.Name, + Path: path.Join(cfg.Directory, pkg.Name), Content: content, }) } diff --git a/internal/pipe/aur/aur_test.go b/internal/pipe/aur/aur_test.go index 5b551044a4f..7769f808485 100644 --- a/internal/pipe/aur/aur_test.go +++ b/internal/pipe/aur/aur_test.go @@ -164,6 +164,13 @@ func TestFullPipe(t *testing.T) { ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" }, }, + "custom-dir": { + prepare: func(ctx *context.Context) { + ctx.TokenType = context.TokenTypeGitHub + ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" + ctx.Config.AURs[0].Directory = "foo" + }, + }, "with-more-opts": { prepare: func(ctx *context.Context) { ctx.TokenType = context.TokenTypeGitHub @@ -345,7 +352,7 @@ func TestFullPipe(t *testing.T) { require.NoError(t, Pipe{}.Publish(ctx)) - requireEqualRepoFiles(t, folder, name, url) + requireEqualRepoFiles(t, folder, ctx.Config.AURs[0].Directory, name, url) }) } } @@ -472,7 +479,7 @@ func TestRunPipe(t *testing.T) { require.NoError(t, runAll(ctx, client)) require.NoError(t, Pipe{}.Publish(ctx)) - requireEqualRepoFiles(t, folder, "foo", url) + requireEqualRepoFiles(t, folder, ".", "foo", url) } func TestRunPipeNoBuilds(t *testing.T) { @@ -529,7 +536,7 @@ func TestRunPipeBinaryRelease(t *testing.T) { require.NoError(t, runAll(ctx, client)) require.NoError(t, Pipe{}.Publish(ctx)) - requireEqualRepoFiles(t, folder, "foo", url) + requireEqualRepoFiles(t, folder, ".", "foo", url) } func TestRunPipeNoUpload(t *testing.T) { @@ -717,7 +724,7 @@ func TestSkip(t *testing.T) { }) } -func requireEqualRepoFiles(tb testing.TB, folder, name, url string) { +func requireEqualRepoFiles(tb testing.TB, distDir, repoDir, name, url string) { tb.Helper() dir := tb.TempDir() _, err := git.Run(testctx.New(), "-C", dir, "clone", url, "repo") @@ -727,12 +734,12 @@ func requireEqualRepoFiles(tb testing.TB, folder, name, url string) { "PKGBUILD": ".pkgbuild", ".SRCINFO": ".srcinfo", } { - path := filepath.Join(folder, "aur", name+"-bin"+ext) + path := filepath.Join(distDir, "aur", name+"-bin"+ext) bts, err := os.ReadFile(path) require.NoError(tb, err) golden.RequireEqualExt(tb, bts, ext) - bts, err = os.ReadFile(filepath.Join(dir, "repo", reponame)) + bts, err = os.ReadFile(filepath.Join(dir, "repo", repoDir, reponame)) require.NoError(tb, err) golden.RequireEqualExt(tb, bts, ext) } diff --git a/internal/pipe/aur/testdata/TestFullPipe/custom-dir.pkgbuild.golden b/internal/pipe/aur/testdata/TestFullPipe/custom-dir.pkgbuild.golden new file mode 100644 index 00000000000..57ce0aee7af --- /dev/null +++ b/internal/pipe/aur/testdata/TestFullPipe/custom-dir.pkgbuild.golden @@ -0,0 +1,18 @@ +# This file was generated by GoReleaser. DO NOT EDIT. + +pkgname='custom-dir-bin' +pkgver=1.0.1 +pkgrel=1 +pkgdesc='A run pipe test fish food and FOO=foo_is_bar' +url='https://github.com/goreleaser' +arch=('x86_64') +license=('MIT') +provides=('custom-dir') +conflicts=('custom-dir') + +source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz") +sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') + +package() { + install -Dm755 "./name" "${pkgdir}/usr/bin/name" +} diff --git a/internal/pipe/aur/testdata/TestFullPipe/custom-dir.srcinfo.golden b/internal/pipe/aur/testdata/TestFullPipe/custom-dir.srcinfo.golden new file mode 100644 index 00000000000..de0f35e2b5b --- /dev/null +++ b/internal/pipe/aur/testdata/TestFullPipe/custom-dir.srcinfo.golden @@ -0,0 +1,13 @@ +pkgbase = custom-dir-bin + pkgdesc = A run pipe test fish food and FOO=foo_is_bar + pkgver = 1.0.1 + pkgrel = 1 + url = https://github.com/goreleaser + license = MIT + conflicts = custom-dir + provides = custom-dir + arch = x86_64 + source_x86_64 = https://dummyhost/download/v1.0.1-foo/bin.tar.gz + sha256sums_x86_64 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + +pkgname = custom-dir-bin diff --git a/pkg/config/config.go b/pkg/config/config.go index b1bd8fcef2f..6fe5c4541b8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -219,6 +219,7 @@ type AUR struct { GitSSHCommand string `yaml:"git_ssh_command,omitempty" json:"git_ssh_command,omitempty"` PrivateKey string `yaml:"private_key,omitempty" json:"private_key,omitempty"` Goamd64 string `yaml:"goamd64,omitempty" json:"goamd64,omitempty"` + Directory string `yaml:"directory,omitempty" json:"directory,omitempty"` } // Homebrew contains the brew section. diff --git a/www/docs/customization/aur.md b/www/docs/customization/aur.md index 406541682ae..915f7a64c7e 100644 --- a/www/docs/customization/aur.md +++ b/www/docs/customization/aur.md @@ -6,6 +6,7 @@ After releasing to GitHub, GitLab, or Gitea, GoReleaser can generate and publish a `PKGBUILD` to an _Arch User Repository_. !!! warning + Before going further on this, make sure to read [AUR's Submission Guidelines](https://wiki.archlinux.org/title/AUR_submission_guidelines). @@ -153,11 +154,22 @@ aurs: # Default: depends on the client # Templates: allowed url_template: "http://github.mycompany.com/foo/bar/releases/{{ .Tag }}/{{ .ArtifactName }}" + + # Directory in which the files will be created inside the repository. + # Only useful if you're creating your own AUR with multiple packages in a + # single repository. + # + # Default: . + # Templates: allowed + # Since: v1.23. + url_template: "http://github.mycompany.com/foo/bar/releases/{{ .Tag }}/{{ .ArtifactName }}" ``` !!! tip + Learn more about the [name template engine](/customization/templates/). !!! tip + For more info about what each field does, please refer to [Arch's PKGBUILD reference](https://wiki.archlinux.org/title/PKGBUILD).