2016-12-29 11:21:50 -02:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-03-26 15:56:35 -03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-02-11 16:10:41 -03:00
|
|
|
"strings"
|
2016-12-30 12:03:43 -02:00
|
|
|
"testing"
|
2017-01-02 10:47:19 -02:00
|
|
|
|
2017-12-17 21:26:03 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2020-03-22 17:03:31 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2017-08-20 16:50:34 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 09:48:04 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-12-29 11:21:50 -02:00
|
|
|
)
|
|
|
|
|
2017-03-25 20:46:02 -03:00
|
|
|
func TestPipeDescription(t *testing.T) {
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-03-25 20:43:42 -03:00
|
|
|
}
|
2017-03-26 15:56:35 -03:00
|
|
|
|
2021-11-11 22:56:03 -03:00
|
|
|
func createTmpFile(tb testing.TB, folder, path string) string {
|
|
|
|
tb.Helper()
|
|
|
|
f, err := os.Create(filepath.Join(folder, path))
|
|
|
|
require.NoError(tb, err)
|
|
|
|
require.NoError(tb, f.Close())
|
|
|
|
return f.Name()
|
|
|
|
}
|
|
|
|
|
2019-10-19 20:01:11 +01:00
|
|
|
func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
folder := t.TempDir()
|
2021-11-11 22:56:03 -03:00
|
|
|
tarfile := createTmpFile(t, folder, "bin.tar.gz")
|
|
|
|
srcfile := createTmpFile(t, folder, "source.tar.gz")
|
|
|
|
debfile := createTmpFile(t, folder, "bin.deb")
|
2024-03-26 23:41:41 -03:00
|
|
|
metafile := createTmpFile(t, folder, "metadata.json")
|
2021-11-11 22:56:03 -03:00
|
|
|
checksumfile := createTmpFile(t, folder, "checksum")
|
|
|
|
checksumsigfile := createTmpFile(t, folder, "checksum.sig")
|
|
|
|
checksumpemfile := createTmpFile(t, folder, "checksum.pem")
|
|
|
|
filteredtarfile := createTmpFile(t, folder, "filtered.tar.gz")
|
|
|
|
filtereddebfile := createTmpFile(t, folder, "filtered.deb")
|
2019-10-19 20:01:11 +01:00
|
|
|
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2017-07-15 16:49:52 -03:00
|
|
|
Dist: folder,
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-03-26 15:56:35 -03:00
|
|
|
},
|
2024-03-26 23:41:41 -03:00
|
|
|
IncludeMeta: true,
|
2017-03-26 15:56:35 -03:00
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-17 21:26:03 -02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
2021-11-11 22:56:03 -03:00
|
|
|
Path: tarfile,
|
2019-10-19 20:01:11 +01:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "foo",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
2017-12-17 21:26:03 -02:00
|
|
|
})
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-17 21:26:03 -02:00
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "bin.deb",
|
2021-11-11 22:56:03 -03:00
|
|
|
Path: debfile,
|
2019-10-19 20:01:11 +01:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "foo",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "filtered.tar.gz",
|
2021-11-11 22:56:03 -03:00
|
|
|
Path: filteredtarfile,
|
2019-10-19 20:01:11 +01:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "bar",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "filtered.deb",
|
2021-11-11 22:56:03 -03:00
|
|
|
Path: filtereddebfile,
|
2019-10-19 20:01:11 +01:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "bar",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
2020-04-12 11:47:46 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableSourceArchive,
|
|
|
|
Name: "source.tar.gz",
|
2021-11-11 22:56:03 -03:00
|
|
|
Path: srcfile,
|
2020-04-12 11:47:46 -03:00
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraFormat: "tar.gz",
|
2020-04-12 11:47:46 -03:00
|
|
|
},
|
|
|
|
})
|
2021-11-11 22:56:03 -03:00
|
|
|
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.Checksum,
|
|
|
|
Name: "checksum",
|
|
|
|
Path: checksumfile,
|
|
|
|
Extra: map[string]interface{}{
|
2024-03-26 23:41:41 -03:00
|
|
|
artifact.ExtraID: "doesnt-matter",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.Metadata,
|
|
|
|
Name: "metadata.json",
|
|
|
|
Path: metafile,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "doesnt-matter",
|
2021-11-11 22:56:03 -03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.Signature,
|
|
|
|
Name: "checksum.sig",
|
|
|
|
Path: checksumsigfile,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "bar",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.Certificate,
|
|
|
|
Name: "checksum.pem",
|
|
|
|
Path: checksumpemfile,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
artifact.ExtraID: "bar",
|
|
|
|
},
|
|
|
|
})
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.True(t, client.UploadedFile)
|
2024-02-19 13:50:47 +01:00
|
|
|
require.True(t, client.ReleasePublished)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Contains(t, client.UploadedFileNames, "source.tar.gz")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "bin.deb")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "filtered.deb")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "filtered.tar.gz")
|
2024-03-26 23:41:41 -03:00
|
|
|
require.Contains(t, client.UploadedFileNames, "metadata.json")
|
2021-11-11 22:56:03 -03:00
|
|
|
require.Contains(t, client.UploadedFileNames, "checksum")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "checksum.pem")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "checksum.sig")
|
2019-10-19 20:01:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeWithIDsThenFilters(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
folder := t.TempDir()
|
2019-10-19 20:01:11 +01:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, tarfile.Close())
|
2019-10-19 20:01:11 +01:00
|
|
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, debfile.Close())
|
2019-10-19 20:01:11 +01:00
|
|
|
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, filteredtarfile.Close())
|
2019-10-19 20:01:11 +01:00
|
|
|
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-04-25 11:34:40 -03:00
|
|
|
require.NoError(t, filtereddebfile.Close())
|
2019-10-19 20:01:11 +01:00
|
|
|
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2019-10-19 20:01:11 +01:00
|
|
|
Dist: folder,
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
IDs: []string{"foo"},
|
2020-02-11 16:10:41 -03:00
|
|
|
ExtraFiles: []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/**/*"},
|
|
|
|
},
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2019-10-19 20:01:11 +01:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "foo",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "bin.deb",
|
|
|
|
Path: debfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "foo",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "filtered.tar.gz",
|
|
|
|
Path: filteredtarfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "bar",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "filtered.deb",
|
|
|
|
Path: filtereddebfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
2021-10-16 22:46:11 -03:00
|
|
|
artifact.ExtraID: "bar",
|
2019-10-19 20:01:11 +01:00
|
|
|
},
|
2017-12-17 21:26:03 -02:00
|
|
|
})
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.True(t, client.UploadedFile)
|
2024-02-19 13:50:47 +01:00
|
|
|
require.True(t, client.ReleasePublished)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Contains(t, client.UploadedFileNames, "bin.deb")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
|
|
|
require.Contains(t, client.UploadedFileNames, "f1")
|
|
|
|
require.NotContains(t, client.UploadedFileNames, "filtered.deb")
|
|
|
|
require.NotContains(t, client.UploadedFileNames, "filtered.tar.gz")
|
2017-03-26 15:56:35 -03:00
|
|
|
}
|
|
|
|
|
2017-04-15 12:18:09 -03:00
|
|
|
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2017-07-15 16:49:52 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 12:18:09 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{
|
2017-04-15 12:18:09 -03:00
|
|
|
FailToCreateRelease: true,
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, doPublish(ctx, client))
|
|
|
|
require.False(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
2024-02-19 13:50:47 +01:00
|
|
|
require.False(t, client.ReleasePublished)
|
2017-04-15 12:18:09 -03:00
|
|
|
}
|
|
|
|
|
2017-04-14 15:53:36 -03:00
|
|
|
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2017-07-15 16:49:52 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-14 15:53:36 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-17 21:26:03 -02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: "/nope/nope/nope",
|
|
|
|
})
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
2017-04-14 15:53:36 -03:00
|
|
|
}
|
|
|
|
|
2017-04-15 12:18:09 -03:00
|
|
|
func TestRunPipeUploadFailure(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
folder := t.TempDir()
|
2017-04-15 12:18:09 -03:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2017-07-15 16:49:52 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 12:18:09 -03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-17 21:26:03 -02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
})
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{
|
2017-04-15 12:18:09 -03:00
|
|
|
FailToUpload: true,
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
2024-02-19 13:50:47 +01:00
|
|
|
require.False(t, client.ReleasePublished)
|
2017-04-15 12:18:09 -03:00
|
|
|
}
|
|
|
|
|
2020-02-11 16:10:41 -03:00
|
|
|
func TestRunPipeExtraFileNotFound(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2020-02-11 16:10:41 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
ExtraFiles: []config.ExtraFile{
|
2021-05-30 21:53:40 -03:00
|
|
|
{Glob: "./testdata/f1.txt"},
|
2020-02-11 16:10:41 -03:00
|
|
|
{Glob: "./nope"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{}
|
2021-03-01 14:19:13 -03:00
|
|
|
require.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: matching \"./nope\": file does not exist")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
2020-02-11 16:10:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeExtraOverride(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2020-02-11 16:10:41 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
ExtraFiles: []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/**/*"},
|
|
|
|
{Glob: "./testdata/upload_same_name/f1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.True(t, client.UploadedFile)
|
|
|
|
require.Contains(t, client.UploadedFileNames, "f1")
|
|
|
|
require.True(t, strings.HasSuffix(client.UploadedFilePaths["f1"], "testdata/upload_same_name/f1"))
|
2020-02-11 16:10:41 -03:00
|
|
|
}
|
|
|
|
|
2018-12-28 19:17:40 -02:00
|
|
|
func TestRunPipeUploadRetry(t *testing.T) {
|
2021-03-01 14:19:13 -03:00
|
|
|
folder := t.TempDir()
|
2018-12-28 19:17:40 -02:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, err)
|
2021-03-01 14:19:13 -03:00
|
|
|
config := config.Project{
|
2018-12-28 19:17:40 -02:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config, testctx.WithCurrentTag("v1.0.0"))
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2018-12-28 19:17:40 -02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
})
|
2021-10-03 13:24:20 -03:00
|
|
|
client := &client.Mock{
|
2018-12-28 19:17:40 -02:00
|
|
|
FailFirstUpload: true,
|
|
|
|
}
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.True(t, client.UploadedFile)
|
2024-02-19 13:50:47 +01:00
|
|
|
require.True(t, client.ReleasePublished)
|
2018-12-28 19:17:40 -02:00
|
|
|
}
|
|
|
|
|
2017-12-02 23:21:13 -02:00
|
|
|
func TestDefault(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-12-02 23:21:13 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
|
|
|
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
2021-11-06 16:54:01 -03:00
|
|
|
require.Equal(t, "https://github.com/goreleaser/goreleaser/releases/tag/v1.0.0", ctx.ReleaseURL)
|
2017-12-02 23:21:13 -02:00
|
|
|
}
|
|
|
|
|
2022-05-09 09:32:43 -03:00
|
|
|
func TestDefaultInvalidURL(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser.git")
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitHubURLs: config.GitHubURLs{
|
|
|
|
Download: "https://github.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2022-05-09 09:32:43 -03:00
|
|
|
require.Error(t, Pipe{}.Default(ctx))
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
func TestDefaultWithGitlab(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2019-06-29 16:02:40 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitlab.com:gitlabowner/gitlabrepo.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitLabURLs: config.GitLabURLs{
|
|
|
|
Download: "https://gitlab.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GitLabTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "gitlabrepo", ctx.Config.Release.GitLab.Name)
|
|
|
|
require.Equal(t, "gitlabowner", ctx.Config.Release.GitLab.Owner)
|
2021-11-06 16:54:01 -03:00
|
|
|
require.Equal(t, "https://gitlab.com/gitlabowner/gitlabrepo/-/releases/v1.0.0", ctx.ReleaseURL)
|
2019-06-29 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 09:32:43 -03:00
|
|
|
func TestDefaultWithGitlabInvalidURL(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitlab.com:gitlabrepo.git")
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GitLabURLs: config.GitLabURLs{
|
|
|
|
Download: "https://gitlab.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GiteaTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2022-05-09 09:32:43 -03:00
|
|
|
require.Error(t, Pipe{}.Default(ctx))
|
|
|
|
}
|
|
|
|
|
2019-08-26 10:31:38 +03:00
|
|
|
func TestDefaultWithGitea(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2019-08-26 10:31:38 +03:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitea.example.com:giteaowner/gitearepo.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
|
|
|
Download: "https://git.honk.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GiteaTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "gitearepo", ctx.Config.Release.Gitea.Name)
|
|
|
|
require.Equal(t, "giteaowner", ctx.Config.Release.Gitea.Owner)
|
2021-11-06 15:58:31 -03:00
|
|
|
require.Equal(t, "https://git.honk.com/giteaowner/gitearepo/releases/tag/v1.0.0", ctx.ReleaseURL)
|
2019-08-26 10:31:38 +03:00
|
|
|
}
|
|
|
|
|
2022-05-09 09:32:43 -03:00
|
|
|
func TestDefaultWithGiteaInvalidURL(t *testing.T) {
|
|
|
|
testlib.Mktmp(t)
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitea.example.com:gitearepo.git")
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
|
|
|
Download: "https://git.honk.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
testctx.GiteaTokenType,
|
|
|
|
testctx.WithCurrentTag("v1.0.0"),
|
|
|
|
)
|
2022-05-09 09:32:43 -03:00
|
|
|
require.Error(t, Pipe{}.Default(ctx))
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:58:31 -03:00
|
|
|
func TestDefaultPreRelease(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2018-11-29 19:42:14 +01:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2021-11-06 15:58:31 -03:00
|
|
|
t.Run("prerelease", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-11-06 15:58:31 -03:00
|
|
|
Release: config.Release{
|
|
|
|
Prerelease: "true",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 0,
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.True(t, ctx.PreRelease)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("release", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
|
|
|
Release: config.Release{},
|
2021-11-06 15:58:31 -03:00
|
|
|
})
|
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 0,
|
|
|
|
Prerelease: "rc1",
|
|
|
|
}
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.False(t, ctx.PreRelease)
|
|
|
|
})
|
|
|
|
|
2018-11-29 19:42:14 +01:00
|
|
|
t.Run("auto-release", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Prerelease: "auto",
|
|
|
|
},
|
2018-11-29 19:42:14 +01:00
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithSemver(1, 0, 0, ""),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-12-17 15:34:28 -03:00
|
|
|
require.False(t, ctx.PreRelease)
|
2018-11-29 19:42:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("auto-rc", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Prerelease: "auto",
|
|
|
|
},
|
2018-11-29 19:42:14 +01:00
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithSemver(1, 0, 0, "rc1"),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-12-17 15:34:28 -03:00
|
|
|
require.True(t, ctx.PreRelease)
|
2018-11-29 19:42:14 +01:00
|
|
|
})
|
2019-01-10 17:08:08 -02:00
|
|
|
|
2019-01-19 16:57:58 -02:00
|
|
|
t.Run("auto-rc-github-setup", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(
|
|
|
|
config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "foo",
|
|
|
|
},
|
|
|
|
Prerelease: "auto",
|
2019-01-10 17:08:08 -02:00
|
|
|
},
|
|
|
|
},
|
2023-03-02 00:01:11 -03:00
|
|
|
testctx.GitHubTokenType,
|
|
|
|
testctx.WithSemver(1, 0, 0, "rc1"),
|
|
|
|
)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-12-17 15:34:28 -03:00
|
|
|
require.True(t, ctx.PreRelease)
|
2019-01-10 17:08:08 -02:00
|
|
|
})
|
2018-11-29 19:42:14 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 20:57:19 -07:00
|
|
|
func TestDefaultPipeDisabled(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2018-04-24 20:57:19 -07:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2018-04-24 20:57:19 -07:00
|
|
|
Release: config.Release{
|
2023-01-23 22:27:01 -03:00
|
|
|
Disable: "true",
|
2018-04-24 20:57:19 -07:00
|
|
|
},
|
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 11:23:38 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Default(ctx))
|
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.Name)
|
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.Owner)
|
2018-04-24 20:57:19 -07:00
|
|
|
}
|
|
|
|
|
2017-12-02 23:21:13 -02:00
|
|
|
func TestDefaultFilled(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-12-02 23:21:13 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-04-12 08:35:19 -03:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "bar",
|
2017-12-02 23:21:13 -02:00
|
|
|
},
|
|
|
|
},
|
2022-04-12 08:35:19 -03:00
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
|
|
|
require.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
2017-12-02 23:21:13 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultNotAGitRepo(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New(testctx.GitHubTokenType)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
2018-02-25 20:17:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New(testctx.GitHubTokenType)
|
2017-12-02 23:21:13 -02:00
|
|
|
testlib.GitInit(t)
|
2021-09-15 22:12:45 +03:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
2018-02-25 20:17:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New(testctx.GitHubTokenType, testctx.Snapshot)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
2017-12-02 23:21:13 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New(testctx.GitHubTokenType)
|
2020-10-06 09:48:04 -03:00
|
|
|
require.Error(t, Pipe{}.Default(ctx))
|
|
|
|
require.Empty(t, ctx.Config.Release.GitHub.String())
|
2017-12-02 23:21:13 -02:00
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
func TestDefaultMultipleReleasesDefined(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2019-06-29 16:02:40 +02:00
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "githubName",
|
|
|
|
Name: "githubName",
|
|
|
|
},
|
|
|
|
GitLab: config.Repo{
|
|
|
|
Owner: "gitlabOwner",
|
|
|
|
Name: "gitlabName",
|
|
|
|
},
|
2019-08-26 10:31:38 +03:00
|
|
|
Gitea: config.Repo{
|
|
|
|
Owner: "giteaOwner",
|
|
|
|
Name: "giteaName",
|
|
|
|
},
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
|
|
|
})
|
2020-10-06 09:48:04 -03:00
|
|
|
require.EqualError(t, Pipe{}.Default(ctx), ErrMultipleReleases.Error())
|
2019-06-29 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-09-18 10:21:29 -03:00
|
|
|
Release: config.Release{
|
2023-01-23 22:27:01 -03:00
|
|
|
Disable: "true",
|
2021-09-18 10:21:29 -03:00
|
|
|
},
|
|
|
|
})
|
2023-01-28 23:21:43 -03:00
|
|
|
b, err := Pipe{}.Skip(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, b)
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
|
2023-01-23 22:27:01 -03:00
|
|
|
t.Run("skip tmpl", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2023-01-23 22:27:01 -03:00
|
|
|
Env: []string{"FOO=true"},
|
|
|
|
Release: config.Release{
|
|
|
|
Disable: "{{ .Env.FOO }}",
|
|
|
|
},
|
|
|
|
})
|
2023-01-28 23:21:43 -03:00
|
|
|
b, err := Pipe{}.Skip(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, b)
|
2023-01-23 22:27:01 -03:00
|
|
|
})
|
|
|
|
|
2023-01-28 23:21:43 -03:00
|
|
|
t.Run("tmpl err", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2023-01-23 22:27:01 -03:00
|
|
|
Release: config.Release{
|
|
|
|
Disable: "{{ .Env.FOO }}",
|
|
|
|
},
|
|
|
|
})
|
2023-01-28 23:21:43 -03:00
|
|
|
_, err := Pipe{}.Skip(ctx)
|
|
|
|
require.Error(t, err)
|
2023-01-23 22:27:01 -03:00
|
|
|
})
|
|
|
|
|
2022-08-06 18:59:59 -03:00
|
|
|
t.Run("skip upload", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2023-01-23 22:27:01 -03:00
|
|
|
Env: []string{"FOO=true"},
|
|
|
|
Release: config.Release{
|
|
|
|
SkipUpload: "{{ .Env.FOO }}",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
client := &client.Mock{}
|
|
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("skip upload tmpl", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-08-06 18:59:59 -03:00
|
|
|
Release: config.Release{
|
2023-01-23 22:27:01 -03:00
|
|
|
SkipUpload: "true",
|
2022-08-06 18:59:59 -03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
client := &client.Mock{}
|
|
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
|
|
|
require.True(t, client.CreatedRelease)
|
|
|
|
require.False(t, client.UploadedFile)
|
|
|
|
})
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
b, err := Pipe{}.Skip(testctx.New())
|
2023-01-28 23:21:43 -03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, b)
|
2021-09-18 10:21:29 -03:00
|
|
|
})
|
|
|
|
}
|