2022-01-20 19:59:39 +02:00
|
|
|
package aur
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/golden"
|
2023-11-04 01:30:48 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/skips"
|
2023-03-02 05:01:11 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2022-01-20 19:59:39 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-06-20 14:33:59 +02:00
|
|
|
func TestContinueOnError(t *testing.T) {
|
|
|
|
require.True(t, Pipe{}.ContinueOnError())
|
|
|
|
}
|
|
|
|
|
2022-01-20 19:59:39 +02:00
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func createTemplateData() templateData {
|
|
|
|
return templateData{
|
|
|
|
Name: "test-bin",
|
|
|
|
Desc: "Some desc",
|
|
|
|
Homepage: "https://example.com",
|
|
|
|
Conflicts: []string{"nope"},
|
|
|
|
Depends: []string{"nope"},
|
|
|
|
Arches: []string{"x86_64", "i686", "aarch64", "armv6h", "armv7h"},
|
|
|
|
Rel: "1",
|
|
|
|
Provides: []string{"test"},
|
|
|
|
OptDepends: []string{"nfpm"},
|
2022-10-05 14:42:17 +02:00
|
|
|
Backup: []string{
|
|
|
|
"/etc/mypkg.conf",
|
|
|
|
"/var/share/mypkg",
|
|
|
|
},
|
2022-01-20 19:59:39 +02:00
|
|
|
Maintainers: []string{
|
|
|
|
"Ciclano <ciclano@example.com>",
|
|
|
|
"Cicrano <cicrano@example.com>",
|
|
|
|
},
|
|
|
|
Contributors: []string{
|
|
|
|
"Fulano <fulano@example.com>",
|
|
|
|
"Beltrano <beltrano@example.com>",
|
|
|
|
},
|
|
|
|
License: "MIT",
|
|
|
|
Version: "0.1.3",
|
|
|
|
Package: `# bin
|
|
|
|
install -Dm755 "./goreleaser" "${pkgdir}/usr/bin/goreleaser"
|
|
|
|
|
|
|
|
# license
|
|
|
|
install -Dm644 "./LICENSE.md" "${pkgdir}/usr/share/licenses/goreleaser/LICENSE"
|
|
|
|
|
|
|
|
# completions
|
|
|
|
mkdir -p "${pkgdir}/usr/share/bash-completion/completions/"
|
|
|
|
mkdir -p "${pkgdir}/usr/share/zsh/site-functions/"
|
|
|
|
mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/"
|
|
|
|
install -Dm644 "./completions/goreleaser.bash" "${pkgdir}/usr/share/bash-completion/completions/goreleaser"
|
|
|
|
install -Dm644 "./completions/goreleaser.zsh" "${pkgdir}/usr/share/zsh/site-functions/_goreleaser"
|
|
|
|
install -Dm644 "./completions/goreleaser.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/goreleaser.fish"
|
|
|
|
|
|
|
|
# man pages
|
|
|
|
install -Dm644 "./manpages/goreleaser.1.gz" "${pkgdir}/usr/share/man/man1/goreleaser.1.gz"`,
|
|
|
|
ReleasePackages: []releasePackage{
|
|
|
|
{
|
|
|
|
Arch: "x86_64",
|
|
|
|
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz",
|
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
2022-03-09 14:50:57 +02:00
|
|
|
Format: "tar.gz",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Arch: "armv6h",
|
|
|
|
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz",
|
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
2022-03-09 14:50:57 +02:00
|
|
|
Format: "tar.gz",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Arch: "aarch64",
|
|
|
|
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz",
|
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
2022-03-09 14:50:57 +02:00
|
|
|
Format: "tar.gz",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Arch: "i686",
|
|
|
|
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz",
|
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
2022-03-09 14:50:57 +02:00
|
|
|
Format: "tar.gz",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Arch: "armv7h",
|
|
|
|
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz",
|
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
2022-03-09 14:50:57 +02:00
|
|
|
Format: "tar.gz",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 19:45:02 +02:00
|
|
|
func TestFullAur(t *testing.T) {
|
2022-01-20 19:59:39 +02:00
|
|
|
data := createTemplateData()
|
2023-03-02 05:01:11 +02:00
|
|
|
pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{
|
2022-01-20 19:59:39 +02:00
|
|
|
ProjectName: "foo",
|
2022-02-04 19:45:02 +02:00
|
|
|
}), aurTemplateData, data)
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
golden.RequireEqual(t, []byte(pkg))
|
|
|
|
}
|
|
|
|
|
2022-02-04 19:45:02 +02:00
|
|
|
func TestAurSimple(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
pkg, err := applyTemplate(testctx.New(), aurTemplateData, createTemplateData())
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Contains(t, pkg, `# Maintainer: Ciclano <ciclano@example.com>`)
|
|
|
|
require.Contains(t, pkg, `# Maintainer: Cicrano <cicrano@example.com>`)
|
|
|
|
require.Contains(t, pkg, `# Contributor: Fulano <fulano@example.com>`)
|
|
|
|
require.Contains(t, pkg, `# Contributor: Beltrano <beltrano@example.com>`)
|
|
|
|
require.Contains(t, pkg, `pkgname='test-bin'`)
|
|
|
|
require.Contains(t, pkg, `url='https://example.com'`)
|
2022-03-12 03:23:19 +02:00
|
|
|
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")`)
|
2022-01-20 19:59:39 +02:00
|
|
|
require.Contains(t, pkg, `sha256sums_x86_64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')`)
|
|
|
|
require.Contains(t, pkg, `pkgver=0.1.3`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFullSrcInfo(t *testing.T) {
|
|
|
|
data := createTemplateData()
|
|
|
|
data.License = "MIT"
|
2023-03-02 05:01:11 +02:00
|
|
|
pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{
|
2022-01-20 19:59:39 +02:00
|
|
|
ProjectName: "foo",
|
|
|
|
}), srcInfoTemplate, data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
golden.RequireEqual(t, []byte(pkg))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSrcInfoSimple(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
pkg, err := applyTemplate(testctx.New(), srcInfoTemplate, createTemplateData())
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Contains(t, pkg, `pkgbase = test-bin`)
|
|
|
|
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, `sha256sums_x86_64 = 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67`)
|
|
|
|
require.Contains(t, pkg, `pkgver = 0.1.3`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFullPipe(t *testing.T) {
|
|
|
|
type testcase struct {
|
2023-08-25 03:06:12 +02:00
|
|
|
prepare func(ctx *context.Context)
|
|
|
|
expectedRunError string
|
|
|
|
expectedRunErrorCheck func(testing.TB, error)
|
|
|
|
expectedPublishError string
|
|
|
|
expectedPublishErrorIs error
|
|
|
|
expectedPublishErrorCheck func(testing.TB, error)
|
2022-01-20 19:59:39 +02:00
|
|
|
}
|
|
|
|
for name, tt := range map[string]testcase{
|
|
|
|
"default": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"with-more-opts": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser"
|
|
|
|
ctx.Config.AURs[0].Maintainers = []string{"me"}
|
|
|
|
ctx.Config.AURs[0].Contributors = []string{"me as well"}
|
|
|
|
ctx.Config.AURs[0].Depends = []string{"curl", "bash"}
|
|
|
|
ctx.Config.AURs[0].OptDepends = []string{"wget: stuff", "foo: bar"}
|
|
|
|
ctx.Config.AURs[0].Provides = []string{"git", "svn"}
|
|
|
|
ctx.Config.AURs[0].Conflicts = []string{"libcurl", "cvs", "blah"}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"default-gitlab": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.TokenType = context.TokenTypeGitLab
|
|
|
|
ctx.Config.AURs[0].Homepage = "https://gitlab.com/goreleaser"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid-name-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].Name = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedRunErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-package-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].Package = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedRunErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-commit-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].CommitMessageTemplate = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedPublishErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-key-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].PrivateKey = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedPublishErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"no-key": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].PrivateKey = ""
|
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
expectedPublishError: `private_key is empty`,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"key-not-found": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].PrivateKey = "testdata/nope"
|
|
|
|
},
|
2023-03-04 17:16:26 +02:00
|
|
|
expectedPublishErrorIs: os.ErrNotExist,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-git-url-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].GitURL = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedPublishErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"no-git-url": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].GitURL = ""
|
|
|
|
},
|
2023-04-30 15:18:13 +02:00
|
|
|
expectedPublishError: `url is empty`,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-ssh-cmd-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].GitSSHCommand = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedPublishErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
"invalid-commit-author-template": {
|
|
|
|
prepare: func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].CommitAuthor.Name = "{{ .Asdsa }"
|
|
|
|
},
|
2023-08-25 03:06:12 +02:00
|
|
|
expectedPublishErrorCheck: testlib.RequireTemplateError,
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
url := testlib.GitMakeBareRepository(t)
|
2023-10-06 16:16:51 +02:00
|
|
|
key := testlib.MakeNewSSHKey(t, "")
|
2022-01-20 19:59:39 +02:00
|
|
|
|
|
|
|
folder := t.TempDir()
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: name,
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{
|
|
|
|
Name: name,
|
|
|
|
IDs: []string{"foo"},
|
|
|
|
PrivateKey: key,
|
|
|
|
License: "MIT",
|
|
|
|
GitURL: url,
|
|
|
|
Description: "A run pipe test fish food and FOO={{ .Env.FOO }}",
|
|
|
|
},
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
Env: []string{"FOO=foo_is_bar"},
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.WithCurrentTag("v1.0.1-foo"),
|
|
|
|
testctx.WithSemver(1, 0, 1, "foo"),
|
|
|
|
testctx.WithVersion("1.0.1-foo"),
|
|
|
|
)
|
2022-04-12 13:35:19 +02:00
|
|
|
|
2022-01-20 19:59:39 +02:00
|
|
|
tt.prepare(ctx)
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "should-be-ignored.tar.gz",
|
|
|
|
Path: "doesnt matter",
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Goamd64: "v3",
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "bar",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"bar"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "bar_bin.tar.gz",
|
|
|
|
Path: "doesnt matter",
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
2022-01-20 19:59:39 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "bar",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"bar"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
path := filepath.Join(folder, "bin.tar.gz")
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: path,
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
2022-01-20 19:59:39 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"name"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
client := client.NewMock()
|
|
|
|
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
|
|
|
|
if tt.expectedRunError != "" {
|
|
|
|
require.EqualError(t, runAll(ctx, client), tt.expectedRunError)
|
|
|
|
return
|
|
|
|
}
|
2023-08-25 03:06:12 +02:00
|
|
|
if tt.expectedRunErrorCheck != nil {
|
|
|
|
tt.expectedRunErrorCheck(t, runAll(ctx, client))
|
|
|
|
return
|
|
|
|
}
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, runAll(ctx, client))
|
|
|
|
|
|
|
|
if tt.expectedPublishError != "" {
|
|
|
|
require.EqualError(t, Pipe{}.Publish(ctx), tt.expectedPublishError)
|
|
|
|
return
|
|
|
|
}
|
2023-03-04 17:16:26 +02:00
|
|
|
|
|
|
|
if tt.expectedPublishErrorIs != nil {
|
|
|
|
require.ErrorIs(t, Pipe{}.Publish(ctx), tt.expectedPublishErrorIs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-08-25 03:06:12 +02:00
|
|
|
if tt.expectedPublishErrorCheck != nil {
|
|
|
|
tt.expectedPublishErrorCheck(t, Pipe{}.Publish(ctx))
|
2023-04-30 15:18:13 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, Pipe{}.Publish(ctx))
|
|
|
|
|
|
|
|
requireEqualRepoFiles(t, folder, name, url)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipe(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
url := testlib.GitMakeBareRepository(t)
|
2023-10-06 16:16:51 +02:00
|
|
|
key := testlib.MakeNewSSHKey(t, "")
|
2022-01-20 19:59:39 +02:00
|
|
|
|
|
|
|
folder := t.TempDir()
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "foo",
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{
|
|
|
|
License: "MIT",
|
|
|
|
Description: "A run pipe test aur and FOO={{ .Env.FOO }}",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
IDs: []string{"foo"},
|
|
|
|
GitURL: url,
|
|
|
|
PrivateKey: key,
|
|
|
|
},
|
2022-04-12 13:35:19 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Env: []string{"FOO=foo_is_bar"},
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithSemver(1, 0, 1, ""),
|
|
|
|
testctx.WithVersion("1.0.1"),
|
|
|
|
)
|
2022-04-12 13:35:19 +02:00
|
|
|
|
2022-01-20 19:59:39 +02:00
|
|
|
for _, a := range []struct {
|
|
|
|
name string
|
|
|
|
goos string
|
|
|
|
goarch string
|
|
|
|
goarm string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "darwin",
|
|
|
|
goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "darwin",
|
|
|
|
goarch: "arm64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "windows",
|
|
|
|
goarch: "arm64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "windows",
|
|
|
|
goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "386",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "amd64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "arm64",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "arm64",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "armv5",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "arm",
|
|
|
|
goarm: "5",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "armv6",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "arm",
|
|
|
|
goarm: "6",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "armv7",
|
|
|
|
goos: "linux",
|
|
|
|
goarch: "arm",
|
|
|
|
goarm: "7",
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: fmt.Sprintf("%s.tar.gz", a.name),
|
|
|
|
Path: path,
|
|
|
|
Goos: a.goos,
|
|
|
|
Goarch: a.goarch,
|
|
|
|
Goarm: a.goarm,
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
2022-01-20 19:59:39 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"foo"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
client := client.NewMock()
|
|
|
|
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.NoError(t, runAll(ctx, client))
|
|
|
|
require.NoError(t, Pipe{}.Publish(ctx))
|
|
|
|
|
|
|
|
requireEqualRepoFiles(t, folder, "foo", url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeNoBuilds(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
ProjectName: "foo",
|
|
|
|
AURs: []config.AUR{{}},
|
|
|
|
}, testctx.GitHubTokenType)
|
2022-01-20 19:59:39 +02:00
|
|
|
client := client.NewMock()
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
|
|
|
|
require.False(t, client.CreatedFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeBinaryRelease(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
url := testlib.GitMakeBareRepository(t)
|
2023-10-06 16:16:51 +02:00
|
|
|
key := testlib.MakeNewSSHKey(t, "")
|
2022-01-20 19:59:39 +02:00
|
|
|
folder := t.TempDir()
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "foo",
|
|
|
|
AURs: []config.AUR{{
|
|
|
|
GitURL: url,
|
|
|
|
PrivateKey: key,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
testctx.WithVersion("1.2.1"),
|
|
|
|
testctx.WithCurrentTag("v1.2.1"),
|
|
|
|
testctx.WithSemver(1, 2, 1, ""),
|
|
|
|
)
|
2022-01-20 19:59:39 +02:00
|
|
|
|
|
|
|
path := filepath.Join(folder, "dist/foo_linux_amd64/foo")
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2022-04-12 03:43:22 +02:00
|
|
|
Name: "foo_linux_amd64",
|
|
|
|
Path: path,
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-04-12 03:43:22 +02:00
|
|
|
Type: artifact.UploadableBinary,
|
2022-01-20 19:59:39 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "binary",
|
|
|
|
artifact.ExtraBinary: "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
|
|
|
|
client := client.NewMock()
|
|
|
|
require.NoError(t, runAll(ctx, client))
|
|
|
|
require.NoError(t, Pipe{}.Publish(ctx))
|
|
|
|
|
|
|
|
requireEqualRepoFiles(t, folder, "foo", url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeNoUpload(t *testing.T) {
|
|
|
|
folder := t.TempDir()
|
2023-04-30 15:18:13 +02:00
|
|
|
testPublish := func(tb testing.TB, modifier func(ctx *context.Context)) {
|
|
|
|
tb.Helper()
|
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "foo",
|
|
|
|
Release: config.Release{},
|
|
|
|
AURs: []config.AUR{{}},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.1"),
|
|
|
|
testctx.WithSemver(1, 0, 1, ""),
|
|
|
|
)
|
2022-01-27 05:23:37 +02:00
|
|
|
|
2023-04-30 15:18:13 +02:00
|
|
|
path := filepath.Join(folder, "whatever.tar.gz")
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "bin",
|
|
|
|
Path: path,
|
|
|
|
Goos: "linux",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Goamd64: "v1",
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"foo"},
|
|
|
|
},
|
|
|
|
})
|
2022-01-20 19:59:39 +02:00
|
|
|
|
2023-04-30 15:18:13 +02:00
|
|
|
modifier(ctx)
|
2022-01-20 19:59:39 +02:00
|
|
|
|
2023-04-30 15:18:13 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
client := client.NewMock()
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, runAll(ctx, client))
|
2023-04-30 15:18:13 +02:00
|
|
|
t.Log(Pipe{}.Publish(ctx))
|
2022-01-20 19:59:39 +02:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Publish(ctx))
|
|
|
|
require.False(t, client.CreatedFile)
|
|
|
|
}
|
2023-04-30 15:18:13 +02:00
|
|
|
|
2022-01-20 19:59:39 +02:00
|
|
|
t.Run("skip upload true", func(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
testPublish(t, func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].SkipUpload = "true"
|
|
|
|
ctx.Semver.Prerelease = ""
|
|
|
|
})
|
2022-01-20 19:59:39 +02:00
|
|
|
})
|
|
|
|
t.Run("skip upload auto", func(t *testing.T) {
|
2023-04-30 15:18:13 +02:00
|
|
|
testPublish(t, func(ctx *context.Context) {
|
|
|
|
ctx.Config.AURs[0].SkipUpload = "auto"
|
|
|
|
ctx.Semver.Prerelease = "beta1"
|
|
|
|
})
|
2022-01-20 19:59:39 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunEmptyTokenType(t *testing.T) {
|
|
|
|
folder := t.TempDir()
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "foo",
|
|
|
|
Release: config.Release{},
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{},
|
|
|
|
},
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
testctx.WithGitInfo(context.GitInfo{CurrentTag: "v1.0.1"}),
|
|
|
|
testctx.WithSemver(1, 0, 1, ""),
|
|
|
|
)
|
2022-01-20 19:59:39 +02:00
|
|
|
path := filepath.Join(folder, "whatever.tar.gz")
|
|
|
|
f, err := os.Create(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, f.Close())
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: "bin",
|
|
|
|
Path: path,
|
2022-08-16 06:16:45 +02:00
|
|
|
Goos: "linux",
|
2022-01-20 19:59:39 +02:00
|
|
|
Goarch: "amd64",
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "foo",
|
|
|
|
artifact.ExtraFormat: "tar.gz",
|
|
|
|
artifact.ExtraBinaries: []string{"foo"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
client := client.NewMock()
|
|
|
|
require.NoError(t, runAll(ctx, client))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefault(t *testing.T) {
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
ProjectName: "myproject",
|
|
|
|
AURs: []config.AUR{{}},
|
|
|
|
}, testctx.GitHubTokenType)
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, config.AUR{
|
|
|
|
Name: "myproject-bin",
|
|
|
|
Conflicts: []string{"myproject"},
|
|
|
|
Provides: []string{"myproject"},
|
|
|
|
Rel: "1",
|
|
|
|
CommitMessageTemplate: defaultCommitMsg,
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-01-20 19:59:39 +02:00
|
|
|
CommitAuthor: config.CommitAuthor{
|
|
|
|
Name: "goreleaserbot",
|
2022-05-18 17:12:42 +02:00
|
|
|
Email: "bot@goreleaser.com",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
}, ctx.Config.AURs[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("name-without-bin-suffix", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
ProjectName: "myproject",
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
}, testctx.GitHubTokenType)
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, config.AUR{
|
|
|
|
Name: "foo-bin",
|
|
|
|
Conflicts: []string{"myproject"},
|
|
|
|
Provides: []string{"myproject"},
|
|
|
|
Rel: "1",
|
|
|
|
CommitMessageTemplate: defaultCommitMsg,
|
2022-04-14 02:29:39 +02:00
|
|
|
Goamd64: "v1",
|
2022-01-20 19:59:39 +02:00
|
|
|
CommitAuthor: config.CommitAuthor{
|
|
|
|
Name: "goreleaserbot",
|
2022-05-18 17:12:42 +02:00
|
|
|
Email: "bot@goreleaser.com",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
}, ctx.Config.AURs[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("partial", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
ProjectName: "myproject",
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{
|
|
|
|
Conflicts: []string{"somethingelse"},
|
|
|
|
Goamd64: "v3",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
},
|
2023-03-02 05:01:11 +02:00
|
|
|
}, testctx.GitHubTokenType)
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, config.AUR{
|
|
|
|
Name: "myproject-bin",
|
|
|
|
Conflicts: []string{"somethingelse"},
|
|
|
|
Provides: []string{"myproject"},
|
|
|
|
Rel: "1",
|
|
|
|
CommitMessageTemplate: defaultCommitMsg,
|
2022-04-12 03:43:22 +02:00
|
|
|
Goamd64: "v3",
|
2022-01-20 19:59:39 +02:00
|
|
|
CommitAuthor: config.CommitAuthor{
|
|
|
|
Name: "goreleaserbot",
|
2022-05-18 17:12:42 +02:00
|
|
|
Email: "bot@goreleaser.com",
|
2022-01-20 19:59:39 +02:00
|
|
|
},
|
|
|
|
}, ctx.Config.AURs[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
require.True(t, Pipe{}.Skip(testctx.New()))
|
2022-01-20 19:59:39 +02:00
|
|
|
})
|
2023-11-04 01:30:48 +02:00
|
|
|
t.Run("skip flag", func(t *testing.T) {
|
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
AURs: []config.AUR{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
}, testctx.Skip(skips.AUR))
|
2023-11-04 02:34:18 +02:00
|
|
|
require.True(t, Pipe{}.Skip(ctx))
|
2023-11-04 01:30:48 +02:00
|
|
|
})
|
2022-01-20 19:59:39 +02:00
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 05:01:11 +02:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-01-20 19:59:39 +02:00
|
|
|
AURs: []config.AUR{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func requireEqualRepoFiles(tb testing.TB, folder, name, url string) {
|
|
|
|
tb.Helper()
|
|
|
|
dir := tb.TempDir()
|
2023-03-02 05:01:11 +02:00
|
|
|
_, err := git.Run(testctx.New(), "-C", dir, "clone", url, "repo")
|
2022-01-20 19:59:39 +02:00
|
|
|
require.NoError(tb, err)
|
|
|
|
|
|
|
|
for reponame, ext := range map[string]string{
|
|
|
|
"PKGBUILD": ".pkgbuild",
|
|
|
|
".SRCINFO": ".srcinfo",
|
|
|
|
} {
|
|
|
|
path := filepath.Join(folder, "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))
|
|
|
|
require.NoError(tb, err)
|
|
|
|
golden.RequireEqualExt(tb, bts, ext)
|
|
|
|
}
|
|
|
|
}
|