diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1cff5a7..d68566e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,6 +28,7 @@ jobs: - name: Build run: | + ./set_new_version ${{ github.ref_name }} go get ./... make build diff --git a/api/structs.go b/api/structs.go index 126e161..84b8a30 100644 --- a/api/structs.go +++ b/api/structs.go @@ -16,6 +16,7 @@ type Source struct { type Recipe struct { Name string Id string + Vibversion string Stages []Stage Path string ParentPath string diff --git a/cmd/root.go b/cmd/root.go index f19208c..fe272fc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,18 +10,18 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.7.4" +var Version = "0.0.0" var IsRoot = false var OrigUID = 1000 var OrigGID = 1000 var OrigUser = "user" var rootCmd = &cobra.Command{ - Use: "vib", - Short: "Vib is a tool to build container images from recipes using modules", - Long: "Vib is a tool to build container images from YAML recipes using modules to define the steps to build the image.", + Use: "vib", + Short: "Vib is a tool to build container images from recipes using modules", + Long: "Vib is a tool to build container images from YAML recipes using modules to define the steps to build the image.", SilenceUsage: true, - Version: Version, + Version: Version, } // Initialize the root command with build, test, and compile commands diff --git a/core/loader.go b/core/loader.go index dd6e464..be5fde1 100644 --- a/core/loader.go +++ b/core/loader.go @@ -6,12 +6,15 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "github.com/vanilla-os/vib/api" "gopkg.in/yaml.v3" ) +var Min_Recipe_Version = []uint8{1, 0, 0} + // LoadRecipe loads a recipe from a file and returns a Recipe // Does not validate the recipe but it will catch some errors // a proper validation will be done in the future @@ -44,6 +47,28 @@ func LoadRecipe(path string) (*api.Recipe, error) { return nil, err } + if len(strings.TrimSpace(recipe.Vibversion)) <= 0 { + return nil, fmt.Errorf("version key not found in recipe file, assuming outdated recipe") + } + + recipeVersionS := strings.Split(recipe.Vibversion, ".") + if len(recipeVersionS) != 3 { + return nil, fmt.Errorf("invalid version format, expected x.x.x, got %s", recipe.Vibversion) + } + + recipeVersion := []uint8{0, 0, 0} + for i := 0; i < len(recipeVersion); i++ { + versionInt, err := strconv.ParseUint(recipeVersionS[i], 10, 0) + if err != nil { + return nil, err + } + recipeVersion[i] = uint8(versionInt) + } + + if recipeVersion[0] < Min_Recipe_Version[0] || recipeVersion[1] < Min_Recipe_Version[1] || recipeVersion[2] < Min_Recipe_Version[2] { + return nil, fmt.Errorf("outdated recipe, this version of vib supports recipes starting at version %s", strings.Join(strings.Fields(fmt.Sprint(Min_Recipe_Version)), ".")) + } + // the recipe path is stored in the recipe itself // for convenience recipe.Path = recipePath