1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
goreleaser/internal/pipe/changelog/changelog_test.go

1074 lines
30 KiB
Go
Raw Normal View History

package changelog
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"github.com/goreleaser/goreleaser/v2/internal/client"
"github.com/goreleaser/goreleaser/v2/internal/git"
"github.com/goreleaser/goreleaser/v2/internal/testctx"
"github.com/goreleaser/goreleaser/v2/internal/testlib"
"github.com/goreleaser/goreleaser/v2/pkg/config"
"github.com/goreleaser/goreleaser/v2/pkg/context"
"github.com/stretchr/testify/require"
)
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}
func TestChangelogProvidedViaFlag(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseNotesFile = "testdata/changes.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes)
}
func TestChangelogProvidedViaFlagIsAWhitespaceOnlyFile(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseNotesFile = "testdata/changes-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n", ctx.ReleaseNotes)
}
func TestChangelogProvidedViaFlagIsReallyEmpty(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseNotesFile = "testdata/changes-really-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "", ctx.ReleaseNotes)
}
func TestChangelogTmplProvidedViaFlagIsReallyEmpty(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseNotesTmpl = "testdata/changes-really-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "", ctx.ReleaseNotes)
}
func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseNotesFile = "testdata/changes.md"
ctx.ReleaseNotesTmpl = "testdata/changes-templated.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "c0ff33 coffeee v0.0.1\n", ctx.ReleaseNotes)
}
func TestTemplatedChangelogProvidedViaFlagResultIsEmpty(t *testing.T) {
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseNotesTmpl = "testdata/changes-templated-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n\n", ctx.ReleaseNotes)
}
func TestChangelogProvidedViaFlagDoesntExist(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseNotesFile = "testdata/changes.nope"
require.ErrorIs(t, Pipe{}.Run(ctx), os.ErrNotExist)
}
func TestReleaseHeaderProvidedViaFlagDoesntExist(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseHeaderFile = "testdata/header.nope"
require.ErrorIs(t, Pipe{}.Run(ctx), os.ErrNotExist)
}
func TestReleaseFooterProvidedViaFlagDoesntExist(t *testing.T) {
ctx := testctx.New()
ctx.ReleaseFooterFile = "testdata/footer.nope"
require.ErrorIs(t, Pipe{}.Run(ctx), os.ErrNotExist)
}
func TestChangelog(t *testing.T) {
folder := testlib.Mktmp(t)
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")
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Use: "git",
Filters: config.Filters{
Exclude: []string{
"docs:",
"ignored:",
"(?i)cars",
"^Merge pull request",
},
},
},
}, testctx.WithCurrentTag("v0.0.2"), testctx.WithPreviousTag("v0.0.1"))
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")
for _, line := range strings.Split(ctx.ReleaseNotes, "\n")[1:] {
if line == "" {
continue
}
require.Truef(t, strings.HasPrefix(line, "* "), "%q: changelog commit must be a list item", line)
}
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
require.NoError(t, err)
require.NotEmpty(t, string(bts))
}
func TestChangelogInclude(t *testing.T) {
folder := testlib.Mktmp(t)
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")
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Use: "git",
Filters: config.Filters{
Include: []string{
"docs:",
"ignored:",
"(?i)cars",
"^Merge pull request",
},
},
},
}, testctx.WithCurrentTag("v0.0.2"), testctx.WithPreviousTag("v0.0.1"))
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.NotContains(t, ctx.ReleaseNotes, "first")
require.NotContains(t, ctx.ReleaseNotes, "added feature 1")
require.NotContains(t, ctx.ReleaseNotes, "fixed bug 2")
require.Contains(t, ctx.ReleaseNotes, "docs")
require.Contains(t, ctx.ReleaseNotes, "ignored")
require.Contains(t, ctx.ReleaseNotes, "cArs")
require.Contains(t, ctx.ReleaseNotes, "from goreleaser/some-branch")
for _, line := range strings.Split(ctx.ReleaseNotes, "\n")[1:] {
if line == "" {
continue
}
require.Truef(t, strings.HasPrefix(line, "* "), "%q: changelog commit must be a list item", line)
}
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
require.NoError(t, err)
require.NotEmpty(t, string(bts))
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
func TestChangelogForGitlab(t *testing.T) {
folder := testlib.Mktmp(t)
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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")
ctx := testctx.NewWithCfg(
config.Project{
Dist: folder,
Changelog: config.Changelog{
Filters: config.Filters{
Exclude: []string{
"docs:",
"ignored:",
"(?i)cars",
"^Merge pull request",
},
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
},
},
},
testctx.GitLabTokenType,
testctx.WithCurrentTag("v0.0.2"),
testctx.WithPreviousTag("v0.0.1"),
)
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +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") // 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")
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
require.NoError(t, err)
require.NotEmpty(t, string(bts))
}
func TestChangelogSort(t *testing.T) {
testlib.Mktmp(t)
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")
ctx := testctx.New(
testctx.WithCurrentTag("v1.0.0"),
testctx.WithPreviousTag("v0.9.9"),
)
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)
require.NoError(t, err)
require.Len(t, entries, len(cfg.Entries))
var changes []string
for _, line := range entries {
changes = append(changes, extractCommitInfo(line))
}
require.EqualValues(t, cfg.Entries, changes)
})
}
}
func Benchmark_sortEntries(b *testing.B) {
ctx := testctx.New()
entries := []string{
"added feature 1",
"fixed bug 2",
"ignored: whatever",
"docs: whatever",
"something about cArs we dont need",
"feat: added that thing",
"Merge pull request #999 from goreleaser/some-branch",
"this is not a Merge pull request",
}
b.Run("asc", func(b *testing.B) {
ctx.Config.Changelog.Sort = "asc"
for range b.N {
sortEntries(ctx, entries)
}
})
b.Run("desc", func(b *testing.B) {
ctx.Config.Changelog.Sort = "desc"
for range b.N {
sortEntries(ctx, entries)
}
})
}
func TestChangelogInvalidSort(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Sort: "dope",
},
})
require.EqualError(t, Pipe{}.Run(ctx), ErrInvalidSortDirection.Error())
}
func TestChangelogOfFirstRelease(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
msgs := []string{
"initial commit",
"another one",
"one more",
"and finally this one",
}
for _, msg := range msgs {
testlib.GitCommit(t, msg)
}
testlib.GitTag(t, "v0.0.1")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
for _, msg := range msgs {
require.Contains(t, ctx.ReleaseNotes, msg)
}
}
func TestChangelogFilterInvalidRegex(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "commitssss")
testlib.GitTag(t, "v0.0.3")
testlib.GitCommit(t, "commitzzz")
testlib.GitTag(t, "v0.0.4")
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Filters: config.Filters{
Exclude: []string{
"(?iasdr4qasd)not a valid regex i guess",
},
},
},
}, testctx.WithCurrentTag("v0.0.4"), testctx.WithPreviousTag("v0.0.3"))
require.EqualError(t, Pipe{}.Run(ctx), "error parsing regexp: invalid or unsupported Perl syntax: `(?ia`")
}
func TestChangelogFilterIncludeInvalidRegex(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "commitssss")
testlib.GitTag(t, "v0.0.3")
testlib.GitCommit(t, "commitzzz")
testlib.GitTag(t, "v0.0.4")
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Filters: config.Filters{
Include: []string{
"(?iasdr4qasd)not a valid regex i guess",
},
},
},
}, testctx.WithCurrentTag("v0.0.4"), testctx.WithPreviousTag("v0.0.3"))
require.EqualError(t, Pipe{}.Run(ctx), "error parsing regexp: invalid or unsupported Perl syntax: `(?ia`")
}
func TestChangelogNoTags(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
msgs := []string{"first", "second", "third"}
for _, msg := range msgs {
testlib.GitCommit(t, msg)
}
ctx := testctx.New()
require.NoError(t, Pipe{}.Run(ctx))
require.NotEmpty(t, ctx.ReleaseNotes)
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
for _, msg := range msgs {
require.Contains(t, ctx.ReleaseNotes, msg)
}
}
func TestChangelogOnBranchWithSameNameAsTag(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
for _, msg := range msgs {
require.Contains(t, ctx.ReleaseNotes, msg)
}
}
func TestChangeLogWithReleaseHeader(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseHeaderFile = "testdata/release-header.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test header")
}
func TestChangeLogWithTemplatedReleaseHeader(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseHeaderTmpl = "testdata/release-header-templated.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test header with tag v0.0.1")
}
func TestChangeLogWithReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseFooterFile = "testdata/release-footer.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test footer")
require.Equal(t, '\n', rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]))
}
func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
ctx.ReleaseFooterTmpl = "testdata/release-footer-templated.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test footer with tag v0.0.1")
require.Equal(t, '\n', rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]))
}
func TestChangeLogWithoutReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir := testlib.Mktmp(t)
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
msgs := []string{
"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")
ctx := testctx.New(testctx.WithCurrentTag("v0.0.1"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Equal(t, '\n', rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]))
}
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
func TestGetChangelogGitHub(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHub,
},
}, testctx.WithCurrentTag("v0.180.2"), testctx.WithPreviousTag("v0.180.1"))
require.NoError(t, Pipe{}.Default(ctx))
expected := "c90f1085f255d0af0b055160bfff5ee40f47af79: fix: do not skip any defaults (#2521) (@caarlos0)"
mock := client.NewMock()
mock.Changes = []client.ChangelogItem{
{
SHA: "c90f1085f255d0af0b055160bfff5ee40f47af79",
Message: "fix: do not skip any defaults (#2521)",
AuthorName: "Carlos",
AuthorEmail: "nope@nope.com",
AuthorUsername: "caarlos0",
},
}
l := scmChangeloger{
client: mock,
repo: client.Repo{
Owner: "goreleaser",
Name: "goreleaser",
},
}
log, err := l.Log(ctx)
require.NoError(t, err)
require.Equal(t, expected, log)
}
func TestGetChangelogGitHubNative(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHubNative,
},
}, testctx.WithCurrentTag("v0.180.2"), testctx.WithPreviousTag("v0.180.1"))
expected := `## What's changed
* Foo bar test
**Full Changelog**: https://github.com/gorelease/goreleaser/compare/v0.180.1...v0.180.2
`
mock := client.NewMock()
mock.ReleaseNotes = expected
l := githubNativeChangeloger{
client: mock,
repo: client.Repo{
Owner: "goreleaser",
Name: "goreleaser",
},
}
log, err := l.Log(ctx)
require.NoError(t, err)
require.Equal(t, expected, log)
require.Equal(t, []string{"v0.180.1", "v0.180.2"}, mock.ReleaseNotesParams)
}
func TestGetChangelogGitHubNativeFirstRelease(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHubNative,
},
}, testctx.WithCurrentTag("v0.1.0"))
expected := `## What's changed
* Foo bar test
**Full Changelog**: https://github.com/gorelease/goreleaser/commits/v0.1.0
`
mock := client.NewMock()
mock.ReleaseNotes = expected
l := githubNativeChangeloger{
client: mock,
repo: client.Repo{
Owner: "goreleaser",
Name: "goreleaser",
},
}
log, err := l.Log(ctx)
require.NoError(t, err)
require.Equal(t, expected, log)
require.Equal(t, []string{"", "v0.1.0"}, mock.ReleaseNotesParams)
}
func TestGetChangeloger(t *testing.T) {
t.Run("default", func(t *testing.T) {
c, err := getChangeloger(testctx.New())
require.NoError(t, err)
require.IsType(t, gitChangeloger{}, c)
})
t.Run(useGit, func(t *testing.T) {
c, err := getChangeloger(testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGit,
},
}))
require.NoError(t, err)
require.IsType(t, gitChangeloger{}, c)
})
t.Run(useGitHub, func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHub,
},
}, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3"))
c, err := getChangeloger(ctx)
require.NoError(t, err)
require.IsType(t, &scmChangeloger{}, c)
})
t.Run(useGitHub+" no previous", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHub,
},
}, testctx.GitHubTokenType)
c, err := getChangeloger(ctx)
require.NoError(t, err)
require.IsType(t, gitChangeloger{}, c)
})
t.Run(useGitHubNative, func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHubNative,
},
}, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3"))
c, err := getChangeloger(ctx)
require.NoError(t, err)
require.IsType(t, &githubNativeChangeloger{}, c)
})
t.Run(useGitHubNative+"-invalid-repo", func(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "https://gist.github.com/")
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHubNative,
},
}, testctx.GitHubTokenType)
c, err := getChangeloger(ctx)
require.EqualError(t, err, "unsupported repository URL: https://gist.github.com/")
require.Nil(t, c)
})
t.Run(useGitLab, func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
2021-11-06 16:58:07 -03:00
Changelog: config.Changelog{
Use: useGitLab,
2021-11-06 16:58:07 -03:00
},
}, testctx.GitLabTokenType, testctx.WithPreviousTag("v1.2.3"))
2021-11-06 16:58:07 -03:00
c, err := getChangeloger(ctx)
require.NoError(t, err)
require.IsType(t, &scmChangeloger{}, c)
2021-11-06 16:58:07 -03:00
})
t.Run(useGitHub+"-invalid-repo", func(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "https://gist.github.com/")
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitHub,
},
}, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3"))
c, err := getChangeloger(ctx)
require.EqualError(t, err, "unsupported repository URL: https://gist.github.com/")
require.Nil(t, c)
})
t.Run(useGitea, func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
if strings.HasSuffix(r.URL.Path, "api/v1/version") {
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "{\"version\":\"1.22.0\"}")
}
}))
defer srv.Close()
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: useGitea,
},
GiteaURLs: config.GiteaURLs{
API: srv.URL,
},
}, testctx.GiteaTokenType, testctx.WithPreviousTag("v1.2.3"))
c, err := getChangeloger(ctx)
require.NoError(t, err)
require.IsType(t, &scmChangeloger{}, c)
})
t.Run("invalid", func(t *testing.T) {
c, err := getChangeloger(testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Use: "nope",
},
}))
require.EqualError(t, err, `invalid changelog.use: "nope"`)
require.Nil(t, c)
})
}
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
func TestSkip(t *testing.T) {
t.Run("skip", func(t *testing.T) {
ctx := testctx.New(testctx.Snapshot)
b, err := Pipe{}.Skip(ctx)
require.NoError(t, err)
require.True(t, b)
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
})
t.Run("skip/disable", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
Changelog: config.Changelog{
Disable: "{{gt .Patch 0}}",
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
},
}, testctx.WithSemver(0, 0, 1, ""))
b, err := Pipe{}.Skip(ctx)
require.NoError(t, err)
require.True(t, b)
})
t.Run("disable on patches", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Disable: "{{gt .Patch 0}}",
},
}, testctx.WithSemver(0, 0, 1, ""))
b, err := Pipe{}.Skip(ctx)
require.NoError(t, err)
require.True(t, b)
})
t.Run("invalid template", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Disable: "{{if eq .Patch 123}",
},
}, testctx.WithSemver(0, 0, 1, ""))
_, err := Pipe{}.Skip(ctx)
require.Error(t, err)
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
})
t.Run("dont skip", func(t *testing.T) {
b, err := Pipe{}.Skip(testctx.New())
require.NoError(t, err)
require.False(t, b)
})
t.Run("dont skip based on template", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Changelog: config.Changelog{
Disable: "{{gt .Patch 0}}",
},
})
b, err := Pipe{}.Skip(ctx)
require.NoError(t, err)
require.False(t, b)
feat: improve output and pipe skipping (#2480) * refactor: improve middleware Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: upload tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: twitter tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: source tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapshot tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: improved some tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: snapcraft skip Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip slack Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip sign Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip reddit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip discord Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip publish Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip nfpm Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip milestone Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip custompublishers Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip checksums Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip changelog Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip blob Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip before Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip announce Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip defaults Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: cmds Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: todo Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: go.mod Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip release Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: remove old skip pipe errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip teams Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix/test: skip smtp Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip brew and scoop Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip docker Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: skip http/artifactory Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: increase coverage Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00
})
}
func TestGroup(t *testing.T) {
folder := testlib.Mktmp(t)
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, "feat(deps): update foobar [bot]")
testlib.GitCommit(t, "fix: whatever")
testlib.GitCommit(t, "docs: whatever")
testlib.GitCommit(t, "chore: something about cArs we dont need")
testlib.GitCommit(t, "feat: added that thing")
testlib.GitCommit(t, "bug: Merge pull request #999 from goreleaser/some-branch")
testlib.GitCommit(t, "this is not a Merge pull request")
testlib.GitTag(t, "v0.0.2")
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Groups: []config.ChangelogGroup{
{
Title: "Bots",
Regexp: ".*bot.*",
Order: 900,
},
{
Title: "Features",
Regexp: `^.*?feat(\([[:word:]]+\))??!?:.+$`,
Order: 0,
},
{
Title: "Bug Fixes",
Regexp: `^.*?bug(\([[:word:]]+\))??!?:.+$`,
Order: 1,
},
{
Title: "Catch nothing",
Regexp: "yada yada yada honk the planet",
Order: 10,
},
{
Title: "Others",
Order: 999,
},
},
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
require.Regexp(t, `## Changelog
### Features
\* \w+ feat: added that thing
### Bug Fixes
\* \w+ bug: Merge pull request #999 from goreleaser\/some-branch
### Bots
\* \w+ feat\(deps\): update foobar \[bot\]
### Others
\* \w+ this is not a Merge pull request
\* \w+ chore: something about cArs we dont need
\* \w+ docs: whatever
\* \w+ fix: whatever
\* \w+ ignored: whatever
\* \w+ fixed bug 2
\* \w+ added feature 1
fix(changelog): fix random order of first commit in first release (#5173) ## Background This is a bug that occurs randomly under a very specific condition. Not sure how long this bug has been around. I first noticed it in the failed Dagger test job in https://github.com/goreleaser/goreleaser/pull/5161 after the `TestGroup` unit test was updated to use regex matching https://github.com/goreleaser/goreleaser/pull/5161#discussion_r1781302054. Log: https://github.com/goreleaser/goreleaser/actions/runs/11108665571/job/30862144417#step:4:680 ``` --- FAIL: TestGroup (0.23s) changelog_test.go:843: Error Trace: /src/internal/pipe/changelog/changelog_test.go:843 Error: Expect "## Changelog ### Features * a77c0b89a457ee6a78447f6c9113b79cf4dce8ce feat: added that thing ### Bug Fixes * 3e2908a87e5fdfdbd5efaad013c0b2d196c64c40 bug: Merge pull request #999 from goreleaser/some-branch ### Bots * e2b7fbaaf1387cd4af575f5e329d9441ce1a917b feat(deps): update foobar [bot] ### Others * 3643389d7150dc191eca4ac8428274fb31213a12 this is not a Merge pull request * 3e1421263cd99fbd9a1a6c0196a355efe96e631d chore: something about cArs we dont need * c094f150bc948d76f920219ef9729fd63747324b docs: whatever * 242178ede64b3ff570dfbde6416f2c4718dd5b68 fix: whatever * 02b7e77076dfed7475d42d728d69d13d19a10a39 ignored: whatever * c3b78e347e5c38acc6b78e5a963b28221ac0cfee fixed bug 2 * fc5f56a9d915d19bc3630dc40aabd99a3eede02b added feature 1 * dc67ddaae25db36fe70d3b96311243621c176169 first " to match "## Changelog ### Features \* \w+ feat: added that thing ### Bug Fixes \* \w+ bug: Merge pull request #999 from goreleaser\/some-branch ### Bots \* \w+ feat\(deps\): update foobar \[bot\] ### Others \* \w+ first \* \w+ this is not a Merge pull request \* \w+ chore: something about cArs we dont need \* \w+ docs: whatever \* \w+ fix: whatever \* \w+ ignored: whatever \* \w+ fixed bug 2 \* \w+ added feature 1 " Test: TestGroup ``` Then it also failed in: 1. 71e7a63ca111d184ac9ab3f68187b12c63b2c13e Log: https://github.com/goreleaser/goreleaser/actions/runs/11166871425/job/31041794426#step:4:667 ``` --- FAIL: TestGroup (0.13s) changelog_test.go:843: Error Trace: /src/internal/pipe/changelog/changelog_test.go:843 Error: Expect "## Changelog ### Features * 7a9c58e3f299b347754c02a149f77d4450768aba feat: added that thing ### Bug Fixes * 9d5982da0fa36817c9c907271ece0a238bc24918 bug: Merge pull request #999 from goreleaser/some-branch ### Bots * 6890859be3907f8f1b60b1a82cb4af277a0bc425 feat(deps): update foobar [bot] ### Others * 6acc3600c5fe17d0330b566e6d5703e48725f300 this is not a Merge pull request * 31abf613e4c3a5fcaebb0a1a23bcd418d61d2c4d first * 14a53e66c59c532a81e729b6717aa4137cc292fb chore: something about cArs we dont need * df77c2f0d8b1bbdc697e843e1dd2764a716a2aa5 docs: whatever * a4802f6fc858cbc12ceca360a89894a61a0a097f fix: whatever * 7a2645a1262516ca24443a65c137680e2e3857fc ignored: whatever * b66e319579a7eeb319d1d2a95cb938d6316d3edb fixed bug 2 * 377012fb77758238b46a20c8bbd348e55d011168 added feature 1 " to match "## Changelog ### Features \* \w+ feat: added that thing ### Bug Fixes \* \w+ bug: Merge pull request #999 from goreleaser\/some-branch ### Bots \* \w+ feat\(deps\): update foobar \[bot\] ### Others \* \w+ first \* \w+ this is not a Merge pull request \* \w+ chore: something about cArs we dont need \* \w+ docs: whatever \* \w+ fix: whatever \* \w+ ignored: whatever \* \w+ fixed bug 2 \* \w+ added feature 1 " Test: TestGroup ``` 2. 747c11d83301405c40df3a5b56adf976c8382b0f Log: https://github.com/goreleaser/goreleaser/actions/runs/11166873534/job/31041800714#step:4:677 ``` --- FAIL: TestGroup (0.09s) changelog_test.go:843: Error Trace: /src/internal/pipe/changelog/changelog_test.go:843 Error: Expect "## Changelog ### Features * 49f56e2d8ca352d4641828efd167dbfe91f5769a feat: added that thing ### Bug Fixes * 11c8dafa67d5973c359ed3bcf859b81d571396ed bug: Merge pull request #999 from goreleaser/some-branch ### Bots * df888fe601a92afe5d8d4fcae5a551b0eaa57684 feat(deps): update foobar [bot] ### Others * 03f397c28cd4f5484afee71f7edd99977f85deec this is not a Merge pull request * 16333c2d178e4911a049ba63b0b8783bbc7e497b chore: something about cArs we dont need * e7b30e58579bdaaeea184d78ddb5017a2bdc3459 docs: whatever * ab9abbc7aa88208f2b3dc44dc9f7b0e55771b826 fix: whatever * 87fc355911ca94f0a1e5a6c332e36b1f73654fbe ignored: whatever * 189fa3fb4ceb246084404247ad1b521747f30991 fixed bug 2 * 49fdca4fd96ec600d79722f3453c1b84e82dd6e5 added feature 1 * ea1e16eb97b432d9c111df934ea4b6ce3691438a first " to match "## Changelog ### Features \* \w+ feat: added that thing ### Bug Fixes \* \w+ bug: Merge pull request #999 from goreleaser\/some-branch ### Bots \* \w+ feat\(deps\): update foobar \[bot\] ### Others \* \w+ first \* \w+ this is not a Merge pull request \* \w+ chore: something about cArs we dont need \* \w+ docs: whatever \* \w+ fix: whatever \* \w+ ignored: whatever \* \w+ fixed bug 2 \* \w+ added feature 1 " Test: TestGroup ``` 3. 10980311a53bf90e3d5d469a9c3e916d67c0050d Log: https://github.com/goreleaser/goreleaser/actions/runs/11183904433/job/31093519567#step:14:41 ``` --- FAIL: TestGroup (0.14s) changelog_test.go:843: Error Trace: /home/runner/work/goreleaser/goreleaser/internal/pipe/changelog/changelog_test.go:843 Error: Expect "## Changelog ### Features * ec216fc3537667e300da4181c6b51520367afd28 feat: added that thing ### Bug Fixes * 5132e678d5f69a366415474cefce012c640a7de9 bug: Merge pull request #999 from goreleaser/some-branch ### Bots * dd9571e27c5a4f19882b8062a790636376b677bc feat(deps): update foobar [bot] ### Others * c9b95e3b52ad6a82bacabae63decd45b1038d137 this is not a Merge pull request * 260f70d5c2b6e31a35058b727818a78a7d589a22 chore: something about cArs we dont need * 0969cba5b1363473e05eb251ffefbccd46fa6fc8 first * c504cb0173a1f312ab39d17852f86b95504ff767 docs: whatever * d57cab9360470d0e0a03d1ecb4763e89fe182f8f fix: whatever * 2e659ceef3f2231ed107c80954833d9073091dd3 ignored: whatever * 72658b11fd2789a03e83496d723a9196f7b14467 fixed bug 2 * 883d4fab813e6849520463b5325077a9ef45131d added feature 1 " to match "## Changelog ### Features \* \w+ feat: added that thing ### Bug Fixes \* \w+ bug: Merge pull request #999 from goreleaser\/some-branch ### Bots \* \w+ feat\(deps\): update foobar \[bot\] ### Others \* \w+ first \* \w+ this is not a Merge pull request \* \w+ chore: something about cArs we dont need \* \w+ docs: whatever \* \w+ fix: whatever \* \w+ ignored: whatever \* \w+ fixed bug 2 \* \w+ added feature 1 " Test: TestGroup ``` As we can see from the log, the first commit with the `first` message can appear in a random order in the changelog. --- ## Solution In the `TestGroup` unit test, we are making 11 git commits, all within a second. There seems to be a bug with `git log` where it is unable to order the commits in reverse chronological order if all commits have the same authored and committed date, as shown below. > [!note] > `/tmp/TestGroup4125952855/001` is the temporary directory created by `testlib.Mktmp` in `TestGroup` test. `git log` without revision range: ``` /tmp/TestGroup4125952855/001 main ❯ git log --oneline 85f005f (HEAD -> main, tag: v0.0.2) this is not a Merge pull request 27dbd0e bug: Merge pull request #999 from goreleaser/some-branch 3495034 feat: added that thing 9f0db77 chore: something about cArs we dont need 634e043 docs: whatever ef52fef fix: whatever ff49bea feat(deps): update foobar [bot] e0f4e4b ignored: whatever ce7fbfa fixed bug 2 940a684 added feature 1 2750980 (tag: v0.0.1) first ``` `git log` with multiple revision ranges, the "first" commit appears at the top: ``` /tmp/TestGroup4125952855/001 main ❯ git log --oneline 2750980 v0.0.2 2750980 (tag: v0.0.1) first 85f005f (HEAD -> main, tag: v0.0.2) this is not a Merge pull request 27dbd0e bug: Merge pull request #999 from goreleaser/some-branch 3495034 feat: added that thing 9f0db77 chore: something about cArs we dont need 634e043 docs: whatever ef52fef fix: whatever ff49bea feat(deps): update foobar [bot] e0f4e4b ignored: whatever ce7fbfa fixed bug 2 940a684 added feature 1 ``` If we specify only one revision, then the commits are ordered correctly in reverse chronological order: ``` /tmp/TestGroup4125952855/001 main ❯ git log --oneline v0.0.2 85f005f (HEAD -> main, tag: v0.0.2) this is not a Merge pull request 27dbd0e bug: Merge pull request #999 from goreleaser/some-branch 3495034 feat: added that thing 9f0db77 chore: something about cArs we dont need 634e043 docs: whatever ef52fef fix: whatever ff49bea feat(deps): update foobar [bot] e0f4e4b ignored: whatever ce7fbfa fixed bug 2 940a684 added feature 1 2750980 (tag: v0.0.1) first ``` Based on my observations, this bug can only happen when all commits are created at the same time, and the user is creating their first release note. This commit fixes the bug by excluding the first commit SHA-1 hash from `git log` in `gitChangeLogger`. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2024-10-08 08:45:32 +08:00
\* \w+ first
`, ctx.ReleaseNotes)
}
func TestGroupBadRegex(t *testing.T) {
folder := testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitCommit(t, "first")
testlib.GitTag(t, "v0.0.1")
testlib.GitTag(t, "v0.0.2")
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Groups: []config.ChangelogGroup{
{
Title: "Something",
Regexp: "^.*feat[a-z", // unterminated regex
},
},
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.EqualError(t, Pipe{}.Run(ctx), "failed to group into \"Something\": error parsing regexp: missing closing ]: `[a-z`")
}
func TestChangelogFormat(t *testing.T) {
t.Run("without groups", func(t *testing.T) {
makeConf := func(u string) config.Project {
return config.Project{Changelog: config.Changelog{Use: u}}
}
for _, use := range []string{useGit, useGitHub, useGitLab, useGitea} {
t.Run(use, func(t *testing.T) {
out, err := formatChangelog(
testctx.NewWithCfg(makeConf(use)),
[]string{
"aea123 foo",
"aef653 bar",
},
)
require.NoError(t, err)
require.Equal(t, `## Changelog
* aea123 foo
* aef653 bar`, out)
})
}
t.Run(useGitHubNative, func(t *testing.T) {
out, err := formatChangelog(
testctx.NewWithCfg(makeConf(useGitHubNative)),
[]string{
"# What's changed",
"* aea123 foo",
"* aef653 bar",
},
)
require.NoError(t, err)
require.Equal(t, `# What's changed
* aea123 foo
* aef653 bar`, out)
})
})
t.Run("with groups", func(t *testing.T) {
makeConf := func(u string) config.Project {
return config.Project{
Changelog: config.Changelog{
Use: u,
Groups: []config.ChangelogGroup{
{Title: "catch-all"},
},
},
}
}
t.Run(useGitHubNative, func(t *testing.T) {
out, err := formatChangelog(
testctx.NewWithCfg(makeConf(useGitHubNative)),
[]string{
"# What's changed",
"* aea123 foo",
"* aef653 bar",
},
)
require.NoError(t, err)
require.Equal(t, `# What's changed
* aea123 foo
* aef653 bar`, out)
})
for _, use := range []string{useGit, useGitHub, useGitLab, useGitea} {
t.Run(use, func(t *testing.T) {
out, err := formatChangelog(
testctx.NewWithCfg(makeConf(use)),
[]string{
"aea123 foo",
"aef653 bar",
},
)
require.NoError(t, err)
require.Equal(t, `## Changelog
### catch-all
* aea123 foo
* aef653 bar`, out)
})
}
})
}
func TestAbbrev(t *testing.T) {
folder := testlib.Mktmp(t)
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, "feat(deps): update foobar [bot]")
testlib.GitCommit(t, "fix: whatever")
testlib.GitCommit(t, "docs: whatever")
testlib.GitCommit(t, "chore: something about cArs we dont need")
testlib.GitCommit(t, "feat: added that thing")
testlib.GitCommit(t, "bug: Merge pull request #999 from goreleaser/some-branch")
testlib.GitCommit(t, "this is not a Merge pull request")
testlib.GitTag(t, "v0.0.2")
t.Run("no abbrev", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
ensureCommitHashLen(t, ctx.ReleaseNotes, 40)
})
t.Run("abbrev -1", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Abbrev: -1,
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
})
t.Run("abbrev 3", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Abbrev: 3,
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
ensureCommitHashLen(t, ctx.ReleaseNotes, 3)
})
t.Run("abbrev 7", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Abbrev: 7,
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
ensureCommitHashLen(t, ctx.ReleaseNotes, 7)
})
t.Run("abbrev 50", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: folder,
Changelog: config.Changelog{
Abbrev: 50,
},
}, testctx.WithCurrentTag("v0.0.2"), withFirstCommit(t))
require.NoError(t, Pipe{}.Run(ctx))
ensureCommitHashLen(t, ctx.ReleaseNotes, 40)
})
}
func ensureCommitHashLen(tb testing.TB, log string, l int) {
tb.Helper()
for _, line := range strings.Split(log, "\n") {
if strings.HasPrefix(line, "#") || strings.TrimSpace(line) == "" {
continue
}
parts := strings.SplitN(line, " ", 3)
commit := strings.TrimPrefix(parts[1], "* ")
require.Len(tb, commit, l)
}
}
func withFirstCommit(tb testing.TB) testctx.Opt {
tb.Helper()
return func(ctx *context.Context) {
s, err := git.Clean(git.Run(testctx.New(), "rev-list", "--max-parents=0", "HEAD"))
require.NoError(tb, err)
ctx.Git.FirstCommit = s
}
}