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

fix: aur error messages #2880

Merged
merged 2 commits into from Feb 4, 2022
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
38 changes: 19 additions & 19 deletions internal/pipe/aur/aur.go
Expand Up @@ -24,7 +24,7 @@ import (
)

const (
pkgBuildExtra = "AURConfig"
aurExtra = "AURConfig"
defaultSSHCommand = "ssh -i {{ .KeyPath }} -o StrictHostKeyChecking=accept-new -F /dev/null"
defaultCommitMsg = "Update to {{ .Tag }}"
)
Expand Down Expand Up @@ -78,21 +78,21 @@ func (Pipe) Run(ctx *context.Context) error {
}

func runAll(ctx *context.Context, cli client.Client) error {
for _, pkgbuild := range ctx.Config.AURs {
err := doRun(ctx, pkgbuild, cli)
for _, aur := range ctx.Config.AURs {
err := doRun(ctx, aur, cli)
if err != nil {
return err
}
}
return nil
}

func doRun(ctx *context.Context, pkgbuild config.AUR, cl client.Client) error {
name, err := tmpl.New(ctx).Apply(pkgbuild.Name)
func doRun(ctx *context.Context, aur config.AUR, cl client.Client) error {
name, err := tmpl.New(ctx).Apply(aur.Name)
if err != nil {
return err
}
pkgbuild.Name = name
aur.Name = name

filters := []artifact.Filter{
artifact.ByGoos("linux"),
Expand All @@ -113,16 +113,16 @@ func doRun(ctx *context.Context, pkgbuild config.AUR, cl client.Client) error {
artifact.ByType(artifact.UploadableBinary),
),
}
if len(pkgbuild.IDs) > 0 {
filters = append(filters, artifact.ByIDs(pkgbuild.IDs...))
if len(aur.IDs) > 0 {
filters = append(filters, artifact.ByIDs(aur.IDs...))
}

archives := ctx.Artifacts.Filter(artifact.And(filters...)).List()
if len(archives) == 0 {
return ErrNoArchivesFound
}

pkg, err := tmpl.New(ctx).Apply(pkgbuild.Package)
pkg, err := tmpl.New(ctx).Apply(aur.Package)
if err != nil {
return err
}
Expand All @@ -141,15 +141,15 @@ func doRun(ctx *context.Context, pkgbuild config.AUR, cl client.Client) error {
}
log.Warnf("guessing package to be %q", pkg)
}
pkgbuild.Package = pkg
aur.Package = pkg

for _, info := range []struct {
name, tpl, ext string
kind artifact.Type
}{
{
name: "PKGBUILD",
tpl: pkgBuildTemplate,
tpl: aurTemplateData,
ext: ".pkgbuild",
kind: artifact.PkgBuild,
},
Expand All @@ -160,12 +160,12 @@ func doRun(ctx *context.Context, pkgbuild config.AUR, cl client.Client) error {
kind: artifact.SrcInfo,
},
} {
pkgContent, err := buildPkgFile(ctx, pkgbuild, cl, archives, info.tpl)
pkgContent, err := buildPkgFile(ctx, aur, cl, archives, info.tpl)
if err != nil {
return err
}

path := filepath.Join(ctx.Config.Dist, "aur", pkgbuild.Name+info.ext)
path := filepath.Join(ctx.Config.Dist, "aur", aur.Name+info.ext)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return fmt.Errorf("failed to write %s: %w", info.kind, err)
}
Expand All @@ -179,8 +179,8 @@ func doRun(ctx *context.Context, pkgbuild config.AUR, cl client.Client) error {
Path: path,
Type: info.kind,
Extra: map[string]interface{}{
pkgBuildExtra: pkgbuild,
artifact.ExtraID: pkgbuild.Name,
aurExtra: aur,
artifact.ExtraID: aur.Name,
},
})
}
Expand Down Expand Up @@ -346,10 +346,10 @@ func (Pipe) Publish(ctx *context.Context) error {
}

func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error {
cfg := pkgs[0].Extra[pkgBuildExtra].(config.AUR)
cfg := pkgs[0].Extra[aurExtra].(config.AUR)

if strings.TrimSpace(cfg.SkipUpload) == "true" {
return pipe.Skip("pkgbuild.skip_upload is set")
return pipe.Skip("aur.skip_upload is set")
}

if strings.TrimSpace(cfg.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" {
Expand All @@ -372,7 +372,7 @@ func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error {
}

if url == "" {
return pipe.Skip("pkgbuild.git_url is empty")
return pipe.Skip("aur.git_url is empty")
}

sshcmd, err := tmpl.New(ctx).WithExtraFields(tmpl.Fields{
Expand Down Expand Up @@ -442,7 +442,7 @@ func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error {

func keyPath(key string) (string, error) {
if key == "" {
return "", pipe.Skip("pkgbuild.private_key is empty")
return "", pipe.Skip("aur.private_key is empty")
}
if _, err := ssh.ParsePrivateKey([]byte(key)); err == nil {
f, err := os.CreateTemp("", "id_*")
Expand Down
16 changes: 8 additions & 8 deletions internal/pipe/aur/aur_test.go
Expand Up @@ -88,18 +88,18 @@ func createTemplateData() templateData {
}
}

func TestFullPkgBuild(t *testing.T) {
func TestFullAur(t *testing.T) {
data := createTemplateData()
pkg, err := applyTemplate(context.New(config.Project{
ProjectName: "foo",
}), pkgBuildTemplate, data)
}), aurTemplateData, data)
require.NoError(t, err)

golden.RequireEqual(t, []byte(pkg))
}

func TestPkgBuildSimple(t *testing.T) {
pkg, err := applyTemplate(context.New(config.Project{}), pkgBuildTemplate, createTemplateData())
func TestAurSimple(t *testing.T) {
pkg, err := applyTemplate(context.New(config.Project{}), aurTemplateData, createTemplateData())
require.NoError(t, err)
require.Contains(t, pkg, `# Maintainer: Ciclano <ciclano@example.com>`)
require.Contains(t, pkg, `# Maintainer: Cicrano <cicrano@example.com>`)
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestFullPipe(t *testing.T) {
prepare: func(ctx *context.Context) {
ctx.Config.AURs[0].PrivateKey = ""
},
expectedPublishError: `pkgbuild.private_key is empty`,
expectedPublishError: `aur.private_key is empty`,
},
"key-not-found": {
prepare: func(ctx *context.Context) {
Expand All @@ -211,7 +211,7 @@ func TestFullPipe(t *testing.T) {
prepare: func(ctx *context.Context) {
ctx.Config.AURs[0].GitURL = ""
},
expectedPublishError: `pkgbuild.git_url is empty`,
expectedPublishError: `aur.git_url is empty`,
},
"invalid-ssh-cmd-template": {
prepare: func(ctx *context.Context) {
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestRunPipe(t *testing.T) {
AURs: []config.AUR{
{
License: "MIT",
Description: "A run pipe test pkgbuild and FOO={{ .Env.FOO }}",
Description: "A run pipe test aur and FOO={{ .Env.FOO }}",
Homepage: "https://github.com/goreleaser",
IDs: []string{"foo"},
GitURL: url,
Expand Down Expand Up @@ -731,7 +731,7 @@ func TestKeyPath(t *testing.T) {
})
t.Run("empty", func(t *testing.T) {
result, err := keyPath("")
require.EqualError(t, err, `pkgbuild.private_key is empty`)
require.EqualError(t, err, `aur.private_key is empty`)
require.Equal(t, "", result)
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/aur/testdata/TestRunPipe.pkgbuild.golden
Expand Up @@ -3,7 +3,7 @@
pkgname='foo-bin'
pkgver=1.0.1
pkgrel=1
pkgdesc='A run pipe test pkgbuild and FOO=foo_is_bar'
pkgdesc='A run pipe test aur and FOO=foo_is_bar'
url='https://github.com/goreleaser'
arch=('aarch64' 'armv6h' 'armv7h' 'i686' 'x86_64')
license=('MIT')
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/aur/testdata/TestRunPipe.srcinfo.golden
@@ -1,5 +1,5 @@
pkgbase = foo-bin
pkgdesc = A run pipe test pkgbuild and FOO=foo_is_bar
pkgdesc = A run pipe test aur and FOO=foo_is_bar
pkgver = 1.0.1
pkgrel = 1
url = https://github.com/goreleaser
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/aur/tmpl.go
Expand Up @@ -24,7 +24,7 @@ type releasePackage struct {
Arch string
}

const pkgBuildTemplate = `# This file was generated by GoReleaser. DO NOT EDIT.
const aurTemplateData = `# This file was generated by GoReleaser. DO NOT EDIT.

{{- range .Maintainers }}
# Maintainer: {{ . }}
Expand Down