Merge pull request #1196 from TomChv/feat/check-universe-version
Add universe check version in europa up
This commit is contained in:
commit
bbc938ddd6
@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/mod"
|
||||
"go.dagger.io/dagger/plan"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/solver"
|
||||
@ -74,6 +76,11 @@ var upCmd = &cobra.Command{
|
||||
Str("environment", st.Name).
|
||||
Logger()
|
||||
|
||||
universeUpdateCh := make(chan bool)
|
||||
go func() {
|
||||
universeUpdateCh <- checkUniverseVersion(ctx, project.Path)
|
||||
}()
|
||||
|
||||
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
||||
|
||||
env, err := environment.New(st)
|
||||
@ -109,9 +116,29 @@ var upCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to up environment")
|
||||
}
|
||||
|
||||
// Warn universe version if out of date
|
||||
if update := <-universeUpdateCh; update {
|
||||
fmt.Println("A new version of universe is available, please run 'dagger mod get alpha.dagger.io'")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func checkUniverseVersion(ctx context.Context, projectPath string) bool {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
isLatest, err := mod.IsUniverseLatest(ctx, projectPath)
|
||||
if err != nil {
|
||||
lg.Debug().Err(err).Msg("failed to check universe version")
|
||||
return false
|
||||
}
|
||||
if !isLatest {
|
||||
return true
|
||||
}
|
||||
lg.Debug().Msg("universe is up to date")
|
||||
return false
|
||||
}
|
||||
|
||||
func europaUp(ctx context.Context, cl *client.Client, args ...string) error {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
|
45
mod/mod.go
45
mod/mod.go
@ -2,6 +2,7 @@ package mod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@ -19,6 +20,50 @@ func isUniverse(repoName string) bool {
|
||||
return strings.HasPrefix(strings.ToLower(repoName), stdlib.ModuleName)
|
||||
}
|
||||
|
||||
// IsUniverseLatest check that current universe is up-to-date or no
|
||||
// It returns true if universe is up-to-date, otherwise false
|
||||
// If universe was not installed from `dagger mod get`, it will
|
||||
// not compare anything.
|
||||
//
|
||||
// The latest tag is fetch from universe repo itself.
|
||||
func IsUniverseLatest(ctx context.Context, workspace string) (bool, error) {
|
||||
modfile, err := readPath(workspace)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
req, err := newRequire("alpha.dagger.io", UniverseVersionConstraint)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Get current universe version
|
||||
universe := modfile.searchInstalledRequire(req)
|
||||
if universe == nil {
|
||||
return false, fmt.Errorf("universe not installed")
|
||||
}
|
||||
|
||||
tmpPath := path.Join(modfile.workspacePath, tmpBasePath, req.fullPath())
|
||||
defer os.RemoveAll(tmpPath)
|
||||
|
||||
repo, err := clone(ctx, req, tmpPath, "", "")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Get latest tag
|
||||
latestTag, err := repo.latestTag(ctx, req.versionConstraint)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
c, err := compareVersions(latestTag, universe.version)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return !(c == 1), nil
|
||||
}
|
||||
|
||||
func Install(ctx context.Context, workspace, repoName, versionConstraint string) (*Require, error) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
|
Reference in New Issue
Block a user