2017-10-15 20:21:35 -02:00
|
|
|
package changelog
|
|
|
|
|
|
|
|
import (
|
2019-11-15 13:22:11 +00:00
|
|
|
"os"
|
2018-05-01 20:54:16 -07:00
|
|
|
"path/filepath"
|
2017-10-15 20:21:35 -02:00
|
|
|
"testing"
|
|
|
|
|
2019-01-22 01:56:16 -02:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-14 23:50:20 -03:00
|
|
|
|
2021-10-04 09:32:30 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2017-10-15 20:21:35 -02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-10-15 20:21:35 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangelogProvidedViaFlag(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseNotesFile = "testdata/changes.md"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes)
|
|
|
|
}
|
|
|
|
|
2020-05-31 09:18:48 -03:00
|
|
|
func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseNotesFile = "testdata/changes.md"
|
|
|
|
ctx.ReleaseNotesTmpl = "testdata/changes-templated.md"
|
2020-05-31 09:18:48 -03:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "c0ff33 coffeee v0.0.1\n", ctx.ReleaseNotes)
|
|
|
|
}
|
|
|
|
|
2019-01-22 01:56:16 -02:00
|
|
|
func TestChangelogProvidedViaFlagDoesntExist(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseNotesFile = "testdata/changes.nope"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/changes.nope: no such file or directory")
|
2017-10-15 20:21:35 -02:00
|
|
|
}
|
|
|
|
|
2019-11-15 13:22:11 +00:00
|
|
|
func TestReleaseHeaderProvidedViaFlagDoesntExist(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseHeaderFile = "testdata/header.nope"
|
2019-11-15 13:22:11 +00:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/header.nope: no such file or directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseFooterProvidedViaFlagDoesntExist(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseFooterFile = "testdata/footer.nope"
|
2019-11-15 13:22:11 +00:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "open testdata/footer.nope: no such file or directory")
|
|
|
|
}
|
|
|
|
|
2017-10-15 20:21:35 -02:00
|
|
|
func TestChangelog(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
folder := testlib.Mktmp(t)
|
2017-10-15 20:21:35 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "first")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "added feature 1")
|
|
|
|
testlib.GitCommit(t, "fixed bug 2")
|
2017-10-15 20:40:53 -02:00
|
|
|
testlib.GitCommit(t, "ignored: whatever")
|
|
|
|
testlib.GitCommit(t, "docs: whatever")
|
2017-10-17 23:45:19 -02:00
|
|
|
testlib.GitCommit(t, "something about cArs we dont need")
|
2017-10-15 20:40:53 -02:00
|
|
|
testlib.GitCommit(t, "feat: added that thing")
|
2017-10-17 23:45:19 -02:00
|
|
|
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
|
|
|
|
testlib.GitCommit(t, "this is not a Merge pull request")
|
2017-10-15 20:21:35 -02:00
|
|
|
testlib.GitTag(t, "v0.0.2")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2018-05-01 20:54:16 -07:00
|
|
|
Dist: folder,
|
2017-10-15 20:40:53 -02:00
|
|
|
Changelog: config.Changelog{
|
|
|
|
Filters: config.Filters{
|
|
|
|
Exclude: []string{
|
|
|
|
"docs:",
|
|
|
|
"ignored:",
|
2017-10-17 23:45:19 -02:00
|
|
|
"(?i)cars",
|
|
|
|
"^Merge pull request",
|
2017-10-15 20:40:53 -02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-10-15 20:21:35 -02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.2"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "first")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "added feature 1")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "fixed bug 2")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "docs")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "ignored")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "cArs")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "from goreleaser/some-branch")
|
2018-05-01 20:54:16 -07:00
|
|
|
|
2021-04-25 13:00:51 -03:00
|
|
|
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, string(bts))
|
2017-10-15 20:21:35 -02:00
|
|
|
}
|
|
|
|
|
2020-01-31 19:38:56 +01:00
|
|
|
func TestChangelogPreviousTagEnv(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
folder := testlib.Mktmp(t)
|
2020-01-31 19:38:56 +01:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "first")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "second")
|
|
|
|
testlib.GitTag(t, "v0.0.2")
|
|
|
|
testlib.GitCommit(t, "third")
|
|
|
|
testlib.GitTag(t, "v0.0.3")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2021-10-04 09:32:30 -03:00
|
|
|
Dist: folder,
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "git",
|
|
|
|
Filters: config.Filters{},
|
|
|
|
},
|
2020-01-31 19:38:56 +01:00
|
|
|
})
|
|
|
|
ctx.Git.CurrentTag = "v0.0.3"
|
|
|
|
require.NoError(t, os.Setenv("GORELEASER_PREVIOUS_TAG", "v0.0.1"))
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.NoError(t, os.Setenv("GORELEASER_PREVIOUS_TAG", ""))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "first")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "second")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "third")
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
func TestChangelogForGitlab(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
folder := testlib.Mktmp(t)
|
2019-06-29 16:02:40 +02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "first")
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCommit(t, "added feature 1")
|
|
|
|
testlib.GitCommit(t, "fixed bug 2")
|
|
|
|
testlib.GitCommit(t, "ignored: whatever")
|
|
|
|
testlib.GitCommit(t, "docs: whatever")
|
|
|
|
testlib.GitCommit(t, "something about cArs we dont need")
|
|
|
|
testlib.GitCommit(t, "feat: added that thing")
|
|
|
|
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
|
|
|
|
testlib.GitCommit(t, "this is not a Merge pull request")
|
|
|
|
testlib.GitTag(t, "v0.0.2")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2019-06-29 16:02:40 +02:00
|
|
|
Dist: folder,
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Filters: config.Filters{
|
|
|
|
Exclude: []string{
|
|
|
|
"docs:",
|
|
|
|
"ignored:",
|
|
|
|
"(?i)cars",
|
|
|
|
"^Merge pull request",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.TokenType = context.TokenTypeGitLab
|
|
|
|
ctx.Git.CurrentTag = "v0.0.2"
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "first")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "added feature 1") // no whitespace because its the last entry of the changelog
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "fixed bug 2 ") // whitespaces are on purpose
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "docs")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "ignored")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "cArs")
|
|
|
|
require.NotContains(t, ctx.ReleaseNotes, "from goreleaser/some-branch")
|
|
|
|
|
2021-04-25 13:00:51 -03:00
|
|
|
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
|
2019-06-29 16:02:40 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, string(bts))
|
|
|
|
}
|
|
|
|
|
2017-10-19 20:44:12 -02:00
|
|
|
func TestChangelogSort(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-10-19 20:44:12 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "whatever")
|
|
|
|
testlib.GitTag(t, "v0.9.9")
|
|
|
|
testlib.GitCommit(t, "c: commit")
|
|
|
|
testlib.GitCommit(t, "a: commit")
|
|
|
|
testlib.GitCommit(t, "b: commit")
|
|
|
|
testlib.GitTag(t, "v1.0.0")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2017-10-19 20:44:12 -02:00
|
|
|
Changelog: config.Changelog{},
|
|
|
|
})
|
|
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
|
|
|
|
|
|
|
for _, cfg := range []struct {
|
|
|
|
Sort string
|
|
|
|
Entries []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Sort: "",
|
|
|
|
Entries: []string{
|
|
|
|
"b: commit",
|
|
|
|
"a: commit",
|
|
|
|
"c: commit",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Sort: "asc",
|
|
|
|
Entries: []string{
|
|
|
|
"a: commit",
|
|
|
|
"b: commit",
|
|
|
|
"c: commit",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Sort: "desc",
|
|
|
|
Entries: []string{
|
|
|
|
"c: commit",
|
|
|
|
"b: commit",
|
|
|
|
"a: commit",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run("changelog sort='"+cfg.Sort+"'", func(t *testing.T) {
|
|
|
|
ctx.Config.Changelog.Sort = cfg.Sort
|
|
|
|
entries, err := buildChangelog(ctx)
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, entries, len(cfg.Entries))
|
2017-10-19 20:44:12 -02:00
|
|
|
var changes []string
|
|
|
|
for _, line := range entries {
|
2019-10-09 16:07:51 -03:00
|
|
|
changes = append(changes, extractCommitInfo(line))
|
2017-10-19 20:44:12 -02:00
|
|
|
}
|
2019-01-22 01:56:16 -02:00
|
|
|
require.EqualValues(t, cfg.Entries, changes)
|
2017-10-19 20:44:12 -02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangelogInvalidSort(t *testing.T) {
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2017-10-19 20:44:12 -02:00
|
|
|
Changelog: config.Changelog{
|
|
|
|
Sort: "dope",
|
|
|
|
},
|
|
|
|
})
|
2019-01-22 01:56:16 -02:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), ErrInvalidSortDirection.Error())
|
2017-10-19 20:44:12 -02:00
|
|
|
}
|
|
|
|
|
2017-10-15 20:21:35 -02:00
|
|
|
func TestChangelogOfFirstRelease(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-10-15 20:21:35 -02:00
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2017-10-15 20:21:35 -02:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2017-10-15 20:21:35 -02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
2017-10-15 20:21:35 -02:00
|
|
|
for _, msg := range msgs {
|
2019-01-22 01:56:16 -02:00
|
|
|
require.Contains(t, ctx.ReleaseNotes, msg)
|
2017-10-15 20:21:35 -02:00
|
|
|
}
|
|
|
|
}
|
2017-10-15 20:33:39 -02:00
|
|
|
|
2017-10-18 00:37:03 -02:00
|
|
|
func TestChangelogFilterInvalidRegex(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-10-18 00:37:03 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "commitssss")
|
|
|
|
testlib.GitTag(t, "v0.0.3")
|
|
|
|
testlib.GitCommit(t, "commitzzz")
|
|
|
|
testlib.GitTag(t, "v0.0.4")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{
|
2017-10-18 00:37:03 -02:00
|
|
|
Changelog: config.Changelog{
|
|
|
|
Filters: config.Filters{
|
|
|
|
Exclude: []string{
|
|
|
|
"(?iasdr4qasd)not a valid regex i guess",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Git.CurrentTag = "v0.0.4"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), "error parsing regexp: invalid or unsupported Perl syntax: `(?ia`")
|
2017-10-18 00:37:03 -02:00
|
|
|
}
|
|
|
|
|
2017-10-15 20:33:39 -02:00
|
|
|
func TestChangelogNoTags(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2017-10-15 20:33:39 -02:00
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitCommit(t, "first")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2019-01-22 01:56:16 -02:00
|
|
|
require.Error(t, Pipe{}.Run(ctx))
|
|
|
|
require.Empty(t, ctx.ReleaseNotes)
|
2017-10-15 20:33:39 -02:00
|
|
|
}
|
2018-10-05 14:18:39 -05:00
|
|
|
|
|
|
|
func TestChangelogOnBranchWithSameNameAsTag(t *testing.T) {
|
2020-12-12 13:27:35 -03:00
|
|
|
testlib.Mktmp(t)
|
2018-10-05 14:18:39 -05:00
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2018-10-05 14:18:39 -05:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2018-10-05 14:18:39 -05:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2019-01-22 01:56:16 -02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
2018-10-05 14:18:39 -05:00
|
|
|
for _, msg := range msgs {
|
2019-01-22 01:56:16 -02:00
|
|
|
require.Contains(t, ctx.ReleaseNotes, msg)
|
2018-10-05 14:18:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-11-15 13:22:11 +00:00
|
|
|
|
|
|
|
func TestChangeLogWithReleaseHeader(t *testing.T) {
|
|
|
|
current, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
tmpdir := testlib.Mktmp(t)
|
2019-11-15 13:22:11 +00:00
|
|
|
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
|
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2019-11-15 13:22:11 +00:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2019-11-15 13:22:11 +00:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseHeaderFile = "testdata/release-header.md"
|
2019-11-15 13:22:11 +00:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "test header")
|
|
|
|
}
|
|
|
|
|
2020-05-31 09:18:48 -03:00
|
|
|
func TestChangeLogWithTemplatedReleaseHeader(t *testing.T) {
|
|
|
|
current, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
tmpdir := testlib.Mktmp(t)
|
2020-05-31 09:18:48 -03:00
|
|
|
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
|
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2020-05-31 09:18:48 -03:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2020-05-31 09:18:48 -03:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseHeaderTmpl = "testdata/release-header-templated.md"
|
2020-05-31 09:18:48 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "test header with tag v0.0.1")
|
|
|
|
}
|
2021-04-25 14:20:49 -03:00
|
|
|
|
2019-11-15 13:22:11 +00:00
|
|
|
func TestChangeLogWithReleaseFooter(t *testing.T) {
|
|
|
|
current, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
tmpdir := testlib.Mktmp(t)
|
2019-11-15 13:22:11 +00:00
|
|
|
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
|
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2019-11-15 13:22:11 +00:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2019-11-15 13:22:11 +00:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseFooterFile = "testdata/release-footer.md"
|
2019-11-15 13:22:11 +00:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "test footer")
|
2020-11-25 03:39:59 +01:00
|
|
|
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
|
2019-11-15 13:22:11 +00:00
|
|
|
}
|
2020-05-31 09:18:48 -03:00
|
|
|
|
|
|
|
func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
|
|
|
|
current, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
tmpdir := testlib.Mktmp(t)
|
2020-05-31 09:18:48 -03:00
|
|
|
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
|
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2020-05-31 09:18:48 -03:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2020-05-31 09:18:48 -03:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2021-05-21 21:07:47 -03:00
|
|
|
ctx.ReleaseFooterTmpl = "testdata/release-footer-templated.md"
|
2020-05-31 09:18:48 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "test footer with tag v0.0.1")
|
2020-11-25 03:39:59 +01:00
|
|
|
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeLogWithoutReleaseFooter(t *testing.T) {
|
|
|
|
current, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
2021-04-25 14:20:49 -03:00
|
|
|
tmpdir := testlib.Mktmp(t)
|
2020-11-25 03:39:59 +01:00
|
|
|
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
|
|
|
|
testlib.GitInit(t)
|
2021-04-25 14:20:49 -03:00
|
|
|
msgs := []string{
|
2020-11-25 03:39:59 +01:00
|
|
|
"initial commit",
|
|
|
|
"another one",
|
|
|
|
"one more",
|
|
|
|
"and finally this one",
|
|
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
|
|
testlib.GitCommit(t, msg)
|
|
|
|
}
|
|
|
|
testlib.GitTag(t, "v0.0.1")
|
|
|
|
testlib.GitCheckoutBranch(t, "v0.0.1")
|
2021-04-25 14:20:49 -03:00
|
|
|
ctx := context.New(config.Project{})
|
2020-11-25 03:39:59 +01:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
|
|
|
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
|
2020-05-31 09:18:48 -03:00
|
|
|
}
|
2021-09-18 10:21:29 -03:00
|
|
|
|
2021-10-04 09:32:30 -03:00
|
|
|
func TestGetChangelogGitHub(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "github",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-10-04 23:35:28 -03:00
|
|
|
l := scmChangeloger{
|
|
|
|
client: client.NewUnauthenticatedGitHub(),
|
|
|
|
repo: client.Repo{
|
|
|
|
Owner: "goreleaser",
|
|
|
|
Name: "goreleaser",
|
|
|
|
},
|
|
|
|
}
|
2021-10-04 09:32:30 -03:00
|
|
|
log, err := l.Log(ctx, "v0.180.1", "v0.180.2")
|
|
|
|
require.NoError(t, err)
|
2021-10-06 01:15:31 -03:00
|
|
|
require.Equal(t, "c90f1085f255d0af0b055160bfff5ee40f47af79: fix: do not skip any defaults (#2521) (@caarlos0)", log)
|
2021-10-04 09:32:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetChangeloger(t *testing.T) {
|
|
|
|
t.Run("default", func(t *testing.T) {
|
|
|
|
c, err := getChangeloger(context.New(config.Project{}))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.IsType(t, c, gitChangeloger{})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("git", func(t *testing.T) {
|
|
|
|
c, err := getChangeloger(context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "git",
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.IsType(t, c, gitChangeloger{})
|
|
|
|
})
|
|
|
|
|
2021-11-06 16:58:07 -03:00
|
|
|
t.Run("github", func(t *testing.T) {
|
2021-10-04 09:32:30 -03:00
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "github",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
|
|
c, err := getChangeloger(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.IsType(t, c, &scmChangeloger{})
|
|
|
|
})
|
|
|
|
|
2021-11-06 16:58:07 -03:00
|
|
|
t.Run("gitlab", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "gitlab",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.TokenType = context.TokenTypeGitLab
|
|
|
|
c, err := getChangeloger(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.IsType(t, c, &scmChangeloger{})
|
|
|
|
})
|
|
|
|
|
2021-10-04 09:32:30 -03:00
|
|
|
t.Run("invalid", func(t *testing.T) {
|
|
|
|
c, err := getChangeloger(context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Use: "nope",
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
require.EqualError(t, err, `invalid changelog.use: "nope"`)
|
|
|
|
require.Nil(t, c)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func TestSkip(t *testing.T) {
|
|
|
|
t.Run("skip on snapshot", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
ctx.Snapshot = true
|
|
|
|
require.True(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("skip", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{
|
|
|
|
Changelog: config.Changelog{
|
|
|
|
Skip: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.True(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
|
|
|
ctx := context.New(config.Project{})
|
|
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
|
|
})
|
|
|
|
}
|