You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-03 00:57:43 +02:00
ci: run build/test workflow on windows too (#5263)
Maybe 3rd time is the charm! This makes the CI build run on windows too, and fix broken tests/featuers on Windows. Most of the changes are related to ignoring certain tests on windows, or making sure to use the right path separators. More work to do in the future, probably! #4293 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c65b2258cb
commit
2bf08f11a6
@ -19,6 +19,18 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
echo = "echo "
|
||||
touch = "touch "
|
||||
)
|
||||
|
||||
func init() {
|
||||
if testlib.IsWindows() {
|
||||
touch = "cmd.exe /c copy nul "
|
||||
echo = "cmd.exe /c echo "
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
require.NotEmpty(t, Pipe{}.String())
|
||||
}
|
||||
@ -175,11 +187,11 @@ func TestRun(t *testing.T) {
|
||||
NameTemplate: "foo",
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: "touch " + pre},
|
||||
{Cmd: touch + pre},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: "touch " + post},
|
||||
{Cmd: `sh -c 'echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post'`, Output: true},
|
||||
{Cmd: touch + post},
|
||||
{Cmd: shc(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`), Output: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -208,11 +220,14 @@ func TestRun(t *testing.T) {
|
||||
ModTimestamp: fmt.Sprintf("%d", modTime.Unix()),
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: "touch " + pre},
|
||||
{Cmd: touch + pre},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: "touch " + post},
|
||||
{Cmd: `sh -c 'echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post'`, Output: true},
|
||||
{Cmd: touch + post},
|
||||
{
|
||||
Cmd: shc(`echo "{{ .Name }} {{ .Os }} {{ .Arch }} {{ .Arm }} {{ .Target }} {{ .Ext }}" > {{ .Path }}.post`),
|
||||
Output: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -309,13 +324,13 @@ func TestRun(t *testing.T) {
|
||||
require.FileExists(t, post)
|
||||
bts, err := os.ReadFile(post)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "foo darwin all darwin_all \n", string(bts))
|
||||
require.Contains(t, string(bts), "foo darwin all darwin_all")
|
||||
})
|
||||
|
||||
t.Run("failing pre-hook", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "exit 1"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "echo post"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: echo + "post"}}
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
require.ErrorContains(t, err, "pre hook failed")
|
||||
@ -323,7 +338,7 @@ func TestRun(t *testing.T) {
|
||||
|
||||
t.Run("failing post-hook", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "echo pre"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: echo + "pre"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.ErrorIs(t, err, exec.ErrNotFound)
|
||||
@ -349,7 +364,7 @@ func TestRun(t *testing.T) {
|
||||
ctx.Skips[string(skips.PostBuildHooks)] = false
|
||||
ctx.Skips[string(skips.PreBuildHooks)] = false
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: "echo {{.Env.FOO}}",
|
||||
Cmd: echo + "{{.Env.FOO}}",
|
||||
Env: []string{"FOO=foo-{{.Tag}}"},
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -361,7 +376,7 @@ func TestRun(t *testing.T) {
|
||||
ctx.Skips[string(skips.PostBuildHooks)] = false
|
||||
ctx.Skips[string(skips.PreBuildHooks)] = false
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: "echo blah",
|
||||
Cmd: echo + "blah",
|
||||
Env: []string{"FOO=foo-{{.Tag}"},
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -371,7 +386,7 @@ func TestRun(t *testing.T) {
|
||||
t.Run("hook with bad dir tmpl", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: "echo blah",
|
||||
Cmd: echo + "blah",
|
||||
Dir: "{{.Tag}",
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
@ -381,7 +396,7 @@ func TestRun(t *testing.T) {
|
||||
t.Run("hook with bad cmd tmpl", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{
|
||||
Cmd: "echo blah-{{.Tag }",
|
||||
Cmd: echo + "blah-{{.Tag }",
|
||||
}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{}
|
||||
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||
@ -414,3 +429,10 @@ func checkUniversalBinary(tb testing.TB, unibin *artifact.Artifact) {
|
||||
require.NoError(tb, err)
|
||||
require.Len(tb, f.Arches, 2)
|
||||
}
|
||||
|
||||
func shc(cmd string) string {
|
||||
if testlib.IsWindows() {
|
||||
return fmt.Sprintf("cmd.exe /c '%s'", cmd)
|
||||
}
|
||||
return fmt.Sprintf("sh -c '%s'", cmd)
|
||||
}
|
||||
|
Reference in New Issue
Block a user