cli: validate pro plugin version

GitOrigin-RevId: 2bcb64256b357d07d0f06d8347260c649bfcc132
This commit is contained in:
Vishnu Bharathi 2021-05-20 14:43:39 +05:30 committed by hasura-bot
parent d8d4626ba3
commit 9e3f5a9f01
2 changed files with 32 additions and 0 deletions

View File

@ -48,6 +48,7 @@ $ hasura metadata export -o json
- cli: fix applying migrations in a different environment after config v3 update (#6861)
- cli: fix bug caused by usage of space character in database name (#6852)
- cli: fix issues with generated filepaths in windows (#6813)
- cli: add warning for incompatible pro plugin version
## v2.0.0-alpha.10

View File

@ -43,6 +43,7 @@ import (
"github.com/hasura/graphql-engine/cli/internal/hasura"
"github.com/Masterminds/semver"
"github.com/briandowns/spinner"
"github.com/gofrs/uuid"
"github.com/hasura/graphql-engine/cli/internal/metadataobject/actions/types"
@ -439,6 +440,10 @@ type ExecutionContext struct {
// already this configuration option will disable this step
// more details in: https://github.com/hasura/graphql-engine/issues/6861
DisableAutoStateMigration bool
// proPluginVersionValidated is used to avoid validating pro plugin multiple times
// while preparing the execution context
proPluginVersionValidated bool
}
type Source struct {
@ -488,6 +493,11 @@ func (ec *ExecutionContext) Prepare() error {
return errors.Wrap(err, "setting up plugins path failed")
}
if !ec.proPluginVersionValidated {
ec.validateProPluginVersion()
ec.proPluginVersionValidated = true
}
err = ec.setupCodegenAssetsRepo()
if err != nil {
return errors.Wrap(err, "setting up codegen-assets repo failed")
@ -539,6 +549,27 @@ func (ec *ExecutionContext) setupPlugins() error {
return ec.PluginsConfig.Prepare()
}
func (ec *ExecutionContext) validateProPluginVersion() {
installedPlugins, err := ec.PluginsConfig.ListInstalledPlugins()
if err != nil {
return
}
proPluginVersion := installedPlugins["pro"]
cliVersion := ec.Version.GetCLIVersion()
proPluginSemVer, _ := semver.NewVersion(proPluginVersion)
cliSemVer := ec.Version.CLISemver
if proPluginSemVer == nil || cliSemVer == nil {
return
}
if cliSemVer.Major() != proPluginSemVer.Major() {
ec.Logger.Warnf("[cli: %s] [pro plugin: %s] incompatible version of cli and pro plugin.", cliVersion, proPluginVersion)
ec.Logger.Warn("Try running `hasura plugins upgrade pro` or `hasura plugins install pro --version <version>`")
}
}
func (ec *ExecutionContext) setupCodegenAssetsRepo() error {
base := filepath.Join(ec.GlobalConfigDir, util.ActionsCodegenDirName)
base, err := filepath.Abs(base)