diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index c67925cc50..7092742213 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -42,22 +42,17 @@ jobs: go.sum **/testdata/** - - uses: actions/cache@v3 - if: env.GIT_DIFF - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - uses: actions/setup-go@v4 if: env.GIT_DIFF with: - go-version: '1.21' + go-version: 'stable' + - name: Run Integration Tests if: env.GIT_DIFF - run: GOSUMDB=off go test -v -timeout 120m ./integration/${{ matrix.test-path }} + env: + GOTOOLCHAIN: local+path + GOSUMDB: off + run: go test -v -timeout 120m ./integration/${{ matrix.test-path }} status: runs-on: ubuntu-latest diff --git a/.github/workflows/test-lint.yml b/.github/workflows/test-lint.yml index 46cc7973c2..58c3d30fbb 100644 --- a/.github/workflows/test-lint.yml +++ b/.github/workflows/test-lint.yml @@ -24,10 +24,13 @@ jobs: **/*.go go.mod go.sum + - uses: actions/setup-go@v4 if: env.GIT_DIFF with: go-version-file: go.mod + cache: false + - uses: golangci/golangci-lint-action@v3 if: env.GIT_DIFF with: diff --git a/ignite/pkg/cache/cache.go b/ignite/pkg/cache/cache.go index 061818ed5c..ad115d7888 100644 --- a/ignite/pkg/cache/cache.go +++ b/ignite/pkg/cache/cache.go @@ -94,7 +94,7 @@ func (c Cache[T]) Put(key string, value T) error { func (c Cache[T]) Get(key string) (val T, err error) { db, err := openDB(c.storage.storagePath) if err != nil { - return + return val, err } defer db.Close() diff --git a/ignite/pkg/cosmosanalysis/app/app.go b/ignite/pkg/cosmosanalysis/app/app.go index 5ae88cac5f..ca82b60a28 100644 --- a/ignite/pkg/cosmosanalysis/app/app.go +++ b/ignite/pkg/cosmosanalysis/app/app.go @@ -220,25 +220,25 @@ func newUnexpectedTypeErr(n any) error { func findBasicManagerRegistrations(n ast.Node, pkgDir string, fileImports map[string]string) (packages []string, err error) { callExprType, ok := n.(*ast.CallExpr) if !ok { - return + return packages, err } selectorExprType, ok := callExprType.Fun.(*ast.SelectorExpr) if !ok { - return + return packages, err } identExprType, ok := selectorExprType.X.(*ast.Ident) if !ok { - return + return packages, err } basicModulePkgName := findBasicManagerPkgName(fileImports) if basicModulePkgName == "" { // cosmos-sdk/types/module is not imported in this file, skip - return + return packages, err } if identExprType.Name != basicModulePkgName || selectorExprType.Sel.Name != "NewBasicManager" { - return + return packages, err } // Node "n" defines the call to NewBasicManager, let's loop on its args to discover modules diff --git a/ignite/pkg/cosmosbuf/buf.go b/ignite/pkg/cosmosbuf/buf.go index df3416b7a1..0f8dbf13c8 100644 --- a/ignite/pkg/cosmosbuf/buf.go +++ b/ignite/pkg/cosmosbuf/buf.go @@ -200,7 +200,7 @@ func (b Buf) Generate( // Cleanup deletes temporary files and directories. func (b Buf) Cleanup() error { if b.sdkProtoDir != "" { - return os.Remove(b.sdkProtoDir) + return os.RemoveAll(b.sdkProtoDir) } return nil } diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 2ec051dcd4..b91d81d800 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -2,6 +2,7 @@ package cosmosgen import ( "context" + "os" "path/filepath" "strings" @@ -36,12 +37,6 @@ type generateOptions struct { specOut string } -// TODO add WithInstall. -type ModuleIncludes struct { - Includes []string - Modules []module.Module -} - // ModulePathFunc defines a function type that returns a path based on a Cosmos SDK module. type ModulePathFunc func(module.Module) string @@ -110,18 +105,27 @@ func IncludeDirs(dirs []string) Option { // generator generates code for sdk and sdk apps. type generator struct { - ctx context.Context - buf cosmosbuf.Buf - cacheStorage cache.Storage - appPath string - protoDir string - gomodPath string - o *generateOptions - sdkImport string - deps []gomodule.Version - appModules []module.Module - appIncludes []string - thirdModules map[string]ModuleIncludes // app dependency-modules/includes pair. + ctx context.Context + buf cosmosbuf.Buf + cacheStorage cache.Storage + appPath string + protoDir string + gomodPath string + o *generateOptions + sdkImport string + deps []gomodule.Version + appModules []module.Module + appIncludes []string + thirdModules map[string][]module.Module + thirdModuleIncludes map[string][]string + tmpDirs []string +} + +func (g *generator) cleanup() { + // Remove temporary directories created during generation + for _, path := range g.tmpDirs { + _ = os.RemoveAll(path) + } } // Generate generates code from protoDir of an SDK app residing at appPath with given options. @@ -135,15 +139,18 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir defer b.Cleanup() g := &generator{ - ctx: ctx, - buf: b, - appPath: appPath, - protoDir: protoDir, - gomodPath: gomodPath, - o: &generateOptions{}, - thirdModules: make(map[string]ModuleIncludes), - cacheStorage: cacheStorage, - } + ctx: ctx, + buf: b, + appPath: appPath, + protoDir: protoDir, + gomodPath: gomodPath, + o: &generateOptions{}, + thirdModules: make(map[string][]module.Module), + thirdModuleIncludes: make(map[string][]string), + cacheStorage: cacheStorage, + } + + defer g.cleanup() for _, apply := range options { apply(g.o) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index c804d72ade..b01b28fc7f 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -30,8 +30,9 @@ var protocGlobalInclude = xfilepath.List( ) type ModulesInPath struct { - Path string - ModuleIncludes ModuleIncludes + Path string + Modules []module.Module + Includes []string } func (g *generator) setup() (err error) { @@ -117,20 +118,20 @@ func (g *generator) setup() (err error) { if err != nil { return err } - includes := []string{} - if len(modules) > 0 { - includes, err = g.resolveIncludes(path) // For versioning issues, we do dependency/includes resolution per module + var includes []string + if len(modules) > 0 { + // For versioning issues, we do dependency/includes resolution per module + includes, err = g.resolveIncludes(path) if err != nil { return err } } + modulesInPath = ModulesInPath{ - Path: path, // Each go module - ModuleIncludes: ModuleIncludes{ // Has a set of sdk modules and a set of includes to build them - Includes: includes, - Modules: modules, - }, + Path: path, + Modules: modules, + Includes: includes, } if err := moduleCache.Put(cacheKey, modulesInPath); err != nil { @@ -138,7 +139,17 @@ func (g *generator) setup() (err error) { } } - g.thirdModules[modulesInPath.Path] = modulesInPath.ModuleIncludes + g.thirdModules[modulesInPath.Path] = append( + g.thirdModules[modulesInPath.Path], + modulesInPath.Modules..., + ) + + if modulesInPath.Includes != nil { + g.thirdModuleIncludes[modulesInPath.Path] = append( + g.thirdModuleIncludes[modulesInPath.Path], + modulesInPath.Includes..., + ) + } } return nil @@ -200,9 +211,10 @@ func (g *generator) generateBufIncludeFolder(modpath string) (string, error) { return "", err } + g.tmpDirs = append(g.tmpDirs, protoPath) + err = g.buf.Export(g.ctx, modpath, protoPath) if err != nil { - os.Remove(protoPath) return "", err } return protoPath, nil diff --git a/ignite/pkg/cosmosgen/generate_composables.go b/ignite/pkg/cosmosgen/generate_composables.go index 4b399f85bd..75a15239a1 100644 --- a/ignite/pkg/cosmosgen/generate_composables.go +++ b/ignite/pkg/cosmosgen/generate_composables.go @@ -103,7 +103,7 @@ func (g *generator) generateComposables(frontendType string) error { } for _, modules := range g.thirdModules { - data.Modules = append(data.Modules, modules.Modules...) + data.Modules = append(data.Modules, modules...) } vsg := newComposablesGenerator(g, frontendType) diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index 137f2cbe0f..aced9dea0d 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -129,7 +129,7 @@ func (g *generator) generateOpenAPISpec() error { } for src, modules := range g.thirdModules { - if err := add(src, modules.Modules); err != nil { + if err := add(src, modules); err != nil { return err } } diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 7f43506fe1..9ea13b1e54 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -55,8 +55,8 @@ func (g *generator) generateTS() error { // custom modules losing the registration of the third party // modules when the root templates are re-generated. for _, modules := range g.thirdModules { - data.Modules = append(data.Modules, modules.Modules...) - for _, m := range modules.Modules { + data.Modules = append(data.Modules, modules...) + for _, m := range modules { if strings.HasPrefix(m.Pkg.Name, "interchain_security.ccv.consumer") { data.IsConsumerChain = true } @@ -140,7 +140,8 @@ func (g *tsGenerator) generateModuleTemplates() error { // is available and not generated it would lead to the registration of a new not generated // 3rd party module. for sourcePath, modules := range g.g.thirdModules { - add(sourcePath, modules.Modules, append(g.g.appIncludes, modules.Includes...)) + includes := g.g.thirdModuleIncludes[sourcePath] + add(sourcePath, modules, append(g.g.appIncludes, includes...)) } return gg.Wait() diff --git a/ignite/pkg/cosmosgen/generate_vuex.go b/ignite/pkg/cosmosgen/generate_vuex.go index d7d422c530..35ff5ebf86 100644 --- a/ignite/pkg/cosmosgen/generate_vuex.go +++ b/ignite/pkg/cosmosgen/generate_vuex.go @@ -171,7 +171,7 @@ func (g *generator) generateVuex() error { } for _, modules := range g.thirdModules { - data.Modules = append(data.Modules, modules.Modules...) + data.Modules = append(data.Modules, modules...) } vsg := newVuexGenerator(g) diff --git a/ignite/pkg/nodetime/programs/ts-proto/tsproto.go b/ignite/pkg/nodetime/programs/ts-proto/tsproto.go index ca5575ab03..9b7944ab56 100644 --- a/ignite/pkg/nodetime/programs/ts-proto/tsproto.go +++ b/ignite/pkg/nodetime/programs/ts-proto/tsproto.go @@ -25,7 +25,7 @@ func BinaryPath() (path string, cleanup func(), err error) { // Create binary for the TypeScript protobuf generator command, cleanupBin, err := nodetime.Command(nodetime.CommandTSProto) if err != nil { - return + return path, cleanup, err } defer func() { @@ -39,7 +39,7 @@ func BinaryPath() (path string, cleanup func(), err error) { // test overwriting the generator script while it is being run in a separate test process. tmpDir, err := os.MkdirTemp("", "ts_proto_plugin") if err != nil { - return + return path, cleanup, err } cleanupScriptDir := func() { os.RemoveAll(tmpDir) } diff --git a/ignite/pkg/placeholder/error.go b/ignite/pkg/placeholder/error.go index a649d95a12..a2fe398a42 100644 --- a/ignite/pkg/placeholder/error.go +++ b/ignite/pkg/placeholder/error.go @@ -1,6 +1,7 @@ package placeholder import ( + "errors" "fmt" "strings" @@ -18,8 +19,8 @@ type MissingPlaceholdersError struct { // Is true if both errors have the same list of missing placeholders. func (e *MissingPlaceholdersError) Is(err error) bool { - other, ok := err.(*MissingPlaceholdersError) //nolint:errorlint - if !ok { + var other *MissingPlaceholdersError + if !errors.As(err, &other) { return false } if len(other.missing) != len(e.missing) {