Skip to content

Commit

Permalink
feat: Fail the go build early if go version is not compatible with go…
Browse files Browse the repository at this point in the history
….mod file (#1292)

Fixes issue #1184

Note: `TestGenerateAllTypes` in `build_kotlin_test.go` is failing on
`main`. This PR touches the code for that but doesn't change any of the
behavior or assertions so it will continue to fail.

Tested manually as well:
```
$ ftl build highgoversion
info:highgoversion: Building module
ftl: error: go version "1.22.2" is not recent enough for this module, needs minimum version "9000.1.1"
```
  • Loading branch information
deniseli authored Apr 17, 2024
1 parent bcd6c62 commit 398a85d
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 14 deletions.
34 changes: 31 additions & 3 deletions buildengine/build_go_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package buildengine

import (
"fmt"
"runtime"
"testing"

"github.com/TBD54566975/ftl/backend/schema"
Expand Down Expand Up @@ -120,7 +122,7 @@ func Nothing(context.Context) error {
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("go/modules/other/external_module.go", expected),
})
}
Expand Down Expand Up @@ -169,7 +171,7 @@ func Call(context.Context, Req) (Resp, error) {
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("go/modules/test/external_module.go", expected),
})
}
Expand All @@ -183,11 +185,37 @@ func TestExternalType(t *testing.T) {
buildDir: "_ftl",
sch: &schema.Schema{},
}
testBuild(t, bctx, true, []assertion{
testBuild(t, bctx, "unsupported external type", []assertion{
assertBuildProtoErrors(
"unsupported external type \"time.Month\"",
"unsupported type \"time.Month\" for field \"Month\"",
"unsupported response type \"ftl/external.ExternalResponse\"",
),
})
}

func TestGoModVersion(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
sch := &schema.Schema{
Modules: []*schema.Module{
schema.Builtins(),
{Name: "highgoversion", Decls: []schema.Decl{
&schema.Data{Name: "EchoReq"},
&schema.Data{Name: "EchoResp"},
&schema.Verb{
Name: "echo",
Request: &schema.Ref{Name: "EchoRequest"},
Response: &schema.Ref{Name: "EchoResponse"},
},
}},
},
}
bctx := buildContext{
moduleDir: "testdata/projects/highgoversion",
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, fmt.Sprintf("go version %q is not recent enough for this module, needs minimum version \"9000.1.1\"", runtime.Version()[2:]), []assertion{})
}
17 changes: 9 additions & 8 deletions buildengine/build_kotlin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package ftl.test
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/test/Test.kt", expected),
})
}
Expand Down Expand Up @@ -152,7 +152,7 @@ data class TestResponse(
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/test/Test.kt", expected),
})
}
Expand Down Expand Up @@ -213,7 +213,7 @@ fun testVerb(context: Context, req: Request): ftl.builtin.Empty = throw
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/test/Test.kt", expected),
})
}
Expand Down Expand Up @@ -267,7 +267,7 @@ class Empty
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/builtin/Builtin.kt", expected),
})
}
Expand Down Expand Up @@ -311,7 +311,7 @@ fun emptyVerb(context: Context, req: ftl.builtin.Empty): ftl.builtin.Empty = thr
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/test/Test.kt", expected),
})
}
Expand Down Expand Up @@ -391,7 +391,7 @@ fun nothing(context: Context): Unit = throw
buildDir: "target",
sch: sch,
}
testBuild(t, bctx, false, []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("generated-sources/ftl/test/Test.kt", expected),
})
}
Expand All @@ -405,7 +405,8 @@ func TestKotlinExternalType(t *testing.T) {
buildDir: "target",
sch: &schema.Schema{},
}
testBuild(t, bctx, true, []assertion{
assertBuildProtoErrors("expected module name to be in the form ftl.<module>, but was com.google.type.DayOfWeek"),
expectedErrMsg := "expected module name to be in the form ftl.<module>, but was com.google.type.DayOfWeek"
testBuild(t, bctx, expectedErrMsg, []assertion{
assertBuildProtoErrors(expectedErrMsg),
})
}
5 changes: 3 additions & 2 deletions buildengine/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type assertion func(t testing.TB, bctx buildContext) error
func testBuild(
t *testing.T,
bctx buildContext,
expectFail bool,
expectedBuildErrMsg string, // emptystr if no error expected
assertions []assertion,
) {
t.Helper()
Expand All @@ -33,8 +33,9 @@ func testBuild(
module, err := LoadModule(abs)
assert.NoError(t, err)
err = Build(ctx, bctx.sch, module)
if expectFail {
if len(expectedBuildErrMsg) > 0 {
assert.Error(t, err)
assert.Contains(t, err.Error(), expectedBuildErrMsg)
} else {
assert.NoError(t, err)
}
Expand Down
12 changes: 12 additions & 0 deletions buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ func TestDiscoverModules(t *testing.T) {
},
},
},
Module{
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/projects/highgoversion",
Language: "go",
Realm: "home",
Module: "highgoversion",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
},
},
Module{
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/projects/other",
Expand Down
2 changes: 2 additions & 0 deletions buildengine/testdata/projects/highgoversion/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "highgoversion"
language = "go"
46 changes: 46 additions & 0 deletions buildengine/testdata/projects/highgoversion/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module ftl/highgoversion

go 9000.1.1

require github.com/TBD54566975/ftl v0.177.1

require (
connectrpc.com/connect v1.16.0 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/TBD54566975/scaffolder v0.8.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v0.9.0 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.14.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/swaggest/jsonschema-go v0.3.70 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.4 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

replace github.com/TBD54566975/ftl => /Users/dli/Development/ftl
142 changes: 142 additions & 0 deletions buildengine/testdata/projects/highgoversion/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions buildengine/testdata/projects/highgoversion/highgoversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package highgoversion

import (
"context"
"fmt"

"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

type EchoRequest struct {
Name ftl.Option[string] `json:"name"`
}

type EchoResponse struct {
Message string `json:"message"`
}

//ftl:export
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
return EchoResponse{Message: fmt.Sprintf("Hello, %s!", req.Name.Default("anonymous"))}, nil
}
Loading

0 comments on commit 398a85d

Please sign in to comment.