github.com/grafana/tanka@v0.26.1-0.20240506093700-c22cfc35c21a/pkg/tanka/tanka.go (about) 1 // Package tanka allows to use most of Tanka's features available on the 2 // command line programmatically as a Golang library. Keep in mind that the API 3 // is still experimental and may change without and signs of warnings while 4 // Tanka is still in alpha. Nevertheless, we try to avoid breaking changes. 5 package tanka 6 7 import ( 8 "fmt" 9 10 "github.com/Masterminds/semver" 11 12 "github.com/grafana/tanka/pkg/jsonnet" 13 "github.com/grafana/tanka/pkg/process" 14 ) 15 16 type JsonnetOpts = jsonnet.Opts 17 18 // Opts specify general, optional properties that apply to all actions 19 type Opts struct { 20 JsonnetOpts 21 JsonnetImplementation string 22 23 // Filters are used to optionally select a subset of the resources 24 Filters process.Matchers 25 26 // Name is used to extract a single environment from multiple environments 27 Name string 28 } 29 30 // defaultDevVersion is the placeholder version used when no actual semver is 31 // provided using ldflags 32 const defaultDevVersion = "dev" 33 34 // CurrentVersion is the current version of the running Tanka code 35 var CurrentVersion = defaultDevVersion 36 37 func checkVersion(constraint string) error { 38 if constraint == "" { 39 return nil 40 } 41 if CurrentVersion == defaultDevVersion { 42 return nil 43 } 44 45 c, err := semver.NewConstraint(constraint) 46 if err != nil { 47 return fmt.Errorf("parsing version constraint: '%w'. Please check 'spec.expectVersions.tanka'", err) 48 } 49 50 v, err := semver.NewVersion(CurrentVersion) 51 if err != nil { 52 return fmt.Errorf("'%s' is not a valid semantic version: '%w'.\nThis likely means your build of Tanka is broken, as this is a compile-time value. When in doubt, please raise an issue", CurrentVersion, err) 53 } 54 55 if !c.Check(v) { 56 return fmt.Errorf("current version '%s' does not satisfy the version required by the environment: '%s'. You likely need to use another version of Tanka", CurrentVersion, constraint) 57 } 58 59 return nil 60 }