2020-04-27 21:42:44 -03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type exitMemento struct {
|
|
|
|
code int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *exitMemento) Exit(i int) {
|
|
|
|
e.code = i
|
|
|
|
}
|
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
func setup(tb testing.TB) string {
|
|
|
|
tb.Helper()
|
|
|
|
|
2020-04-27 21:42:44 -03:00
|
|
|
_ = os.Unsetenv("GITHUB_TOKEN")
|
|
|
|
_ = os.Unsetenv("GITLAB_TOKEN")
|
|
|
|
|
|
|
|
previous, err := os.Getwd()
|
2021-03-01 14:45:06 -03:00
|
|
|
require.NoError(tb, err)
|
2020-12-12 13:27:35 -03:00
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
tb.Cleanup(func() {
|
|
|
|
require.NoError(tb, os.Chdir(previous))
|
2020-12-12 13:27:35 -03:00
|
|
|
})
|
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
folder := tb.TempDir()
|
|
|
|
require.NoError(tb, os.Chdir(folder))
|
|
|
|
|
2023-04-30 00:03:03 +00:00
|
|
|
createGoReleaserYaml(tb)
|
2021-03-01 14:45:06 -03:00
|
|
|
createMainGo(tb)
|
|
|
|
goModInit(tb)
|
|
|
|
testlib.GitInit(tb)
|
|
|
|
testlib.GitAdd(tb)
|
|
|
|
testlib.GitCommit(tb, "asdf")
|
|
|
|
testlib.GitTag(tb, "v0.0.1")
|
|
|
|
testlib.GitCommit(tb, "asas89d")
|
|
|
|
testlib.GitCommit(tb, "assssf")
|
|
|
|
testlib.GitCommit(tb, "assd")
|
|
|
|
testlib.GitTag(tb, "v0.0.2")
|
|
|
|
testlib.GitRemoteAdd(tb, "git@github.com:goreleaser/fake.git")
|
2020-12-12 13:27:35 -03:00
|
|
|
|
|
|
|
return folder
|
2020-04-27 21:42:44 -03:00
|
|
|
}
|
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
func createFile(tb testing.TB, filename, contents string) {
|
|
|
|
tb.Helper()
|
2021-04-25 13:00:51 -03:00
|
|
|
require.NoError(tb, os.WriteFile(filename, []byte(contents), 0o644))
|
2020-04-27 21:42:44 -03:00
|
|
|
}
|
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
func createMainGo(tb testing.TB) {
|
|
|
|
tb.Helper()
|
|
|
|
createFile(tb, "main.go", "package main\nfunc main() {println(0)}")
|
2020-04-27 21:42:44 -03:00
|
|
|
}
|
|
|
|
|
2021-03-01 14:45:06 -03:00
|
|
|
func goModInit(tb testing.TB) {
|
|
|
|
tb.Helper()
|
|
|
|
createFile(tb, "go.mod", `module foo
|
2020-04-27 21:42:44 -03:00
|
|
|
|
2024-02-09 09:57:38 -03:00
|
|
|
go 1.22
|
2020-04-27 21:42:44 -03:00
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2023-04-30 00:03:03 +00:00
|
|
|
func createGoReleaserYaml(tb testing.TB) {
|
2021-03-01 14:45:06 -03:00
|
|
|
tb.Helper()
|
|
|
|
yaml := `build:
|
2020-04-27 21:42:44 -03:00
|
|
|
binary: fake
|
|
|
|
goos:
|
|
|
|
- linux
|
|
|
|
goarch:
|
|
|
|
- amd64
|
|
|
|
release:
|
|
|
|
github:
|
|
|
|
owner: goreleaser
|
|
|
|
name: fake
|
|
|
|
`
|
2021-03-01 14:45:06 -03:00
|
|
|
createFile(tb, "goreleaser.yml", yaml)
|
2020-04-27 21:42:44 -03:00
|
|
|
}
|