Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: aur dir #4484

Merged
merged 1 commit into from Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/pipe/aur/aur.go
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
})
}
Expand Down
19 changes: 13 additions & 6 deletions internal/pipe/aur/aur_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
18 changes: 18 additions & 0 deletions 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"
}
13 changes: 13 additions & 0 deletions 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
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions www/docs/customization/aur.md
Expand Up @@ -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).

Expand Down Expand Up @@ -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).