Best Testkube code snippet using commands.getNextVersion
main.go
Source:main.go
...66 var nextVersion int67 var err error68 switch len(args) {69 case 2:70 nextVersion, err = getNextVersion()71 case 3:72 nextVersion, err = strconv.Atoi(args[2])73 default:74 err = fmt.Errorf("Too many arguments!")75 }76 if err != nil {77 return err78 }79 migration, err := findNextMigration(nextVersion, migrationsDir)80 if err != nil {81 return err82 }83 if migration == nil {84 fmt.Println("Already up to date.")85 return nil86 }87 err = disableTerraformBackendOrSkip()88 if err != nil {89 return err90 }91 err = runMigrationFile(migration.file)92 if err != nil {93 return err94 }95 return nil96}97func apply() error {98 nextVersion, err := getNextVersion()99 if err != nil {100 return err101 }102 migration, err := findNextMigration(nextVersion, migrationsDir)103 if err != nil {104 return err105 }106 if migration == nil {107 fmt.Println("Already up to date.")108 return nil109 }110 err = lock()111 if err != nil {112 return err113 }114 err = setMigrationVersion(migration.version)115 if err != nil {116 return err117 }118 err = runMigrationFile(migration.file)119 if err != nil {120 return err121 }122 err = unlock()123 if err != nil {124 return err125 }126 return nil127}128type migration struct {129 version int130 file string131}132func getNextVersion() (int, error) {133 currentVersion, err := getCurrentVersion()134 if err != nil {135 return 0, err136 }137 return currentVersion + 1, nil138}139func findNextMigration(nextVersion int, migrationsDir string) (*migration, error) {140 file, err := findMigrationFile(migrationsDir, nextVersion)141 if err != nil {142 return nil, err143 }144 if file == "" {145 return nil, fmt.Errorf("No migration file")146 }...
release.go
Source:release.go
...23 } else {24 ui.Warn("Using production version mode")25 }26 currentAppVersion := getCurrentAppVersion()27 nextAppVersion := getNextVersion(dev, currentAppVersion, kind)28 pushVersionTag(nextAppVersion)29 // Let's checkout helm chart repo and put changes to particular app30 dir, err := git.PartialCheckout("https://github.com/kubeshop/helm-charts.git", appName, "main", "", "")31 ui.ExitOnError("checking out "+appName+" chart to "+dir, err)32 chart, path, err := helm.GetChart(dir)33 ui.ExitOnError("getting chart path", err)34 ui.Info("Current "+path+" version", helm.GetVersion(chart))35 valuesPath := strings.Replace(path, "Chart.yaml", "values.yaml", -1)36 // save version in Chart.yaml37 err = helm.SaveString(&chart, "version", nextAppVersion)38 ui.PrintOnError("Saving version string", err)39 err = helm.SaveString(&chart, "appVersion", nextAppVersion)40 ui.PrintOnError("Saving appVersion string", err)41 err = helm.UpdateValuesImageTag(valuesPath, nextAppVersion)42 ui.PrintOnError("Updating values image tag", err)43 err = helm.Write(path, chart)44 ui.ExitOnError("saving "+appName+" Chart.yaml file", err)45 gitAddCommitAndPush(dir, "updating "+appName+" chart version to "+nextAppVersion)46 // Checkout main testkube chart and bump main chart with next version47 dir, err = git.PartialCheckout("https://github.com/kubeshop/helm-charts.git", "testkube", "main", "", "")48 ui.ExitOnError("checking out testkube chart to "+dir, err)49 chart, path, err = helm.GetChart(dir)50 ui.ExitOnError("getting chart path", err)51 testkubeVersion := helm.GetVersion(chart)52 nextTestkubeVersion := getNextVersion(dev, testkubeVersion, version.Patch)53 ui.Info("Generated new testkube version", nextTestkubeVersion)54 // bump main testkube chart version55 err = helm.SaveString(&chart, "version", nextTestkubeVersion)56 ui.PrintOnError("Saving version string", err)57 err = helm.SaveString(&chart, "appVersion", nextTestkubeVersion)58 ui.PrintOnError("Saving appVersion string", err)59 // set app dependency version60 _, err = helm.UpdateDependencyVersion(chart, appName, nextAppVersion)61 ui.PrintOnError("Updating dependency version", err)62 err = helm.Write(path, chart)63 ui.ExitOnError("saving testkube Chart.yaml file", err)64 gitAddCommitAndPush(dir, "updating testkube to "+nextTestkubeVersion+" and "+appName+" to "+nextAppVersion)65 tab := ui.NewArrayTable([][]string{66 {appName + " previous version", currentAppVersion},67 {"testkube previous version", testkubeVersion},68 {appName + " next version", nextAppVersion},69 {"testkube next version", nextTestkubeVersion},70 })71 ui.NL()72 ui.Table(tab, os.Stdout)73 ui.Completed("Release completed - Helm charts: ", "testkube:"+nextTestkubeVersion, appName+":"+nextAppVersion)74 ui.NL()75 },76 }77 cmd.Flags().StringVarP(&appName, "app", "a", "testkube-api", "app name chart")78 cmd.Flags().StringVarP(&kind, "kind", "k", "patch", "version kind one of (patch|minor|major")79 cmd.Flags().BoolVarP(&verbose, "verbose", "", false, "verbosity level")80 cmd.Flags().BoolVarP(&dev, "dev", "d", false, "generate beta increment")81 return cmd82}83func pushVersionTag(nextAppVersion string) {84 // set new tag and push85 // add "v" for go compatibility (Semver don't have it as prefix)86 _, err := process.Execute("git", "tag", "v"+nextAppVersion)87 ui.ExitOnError("tagging new version", err)88 _, err = process.Execute("git", "push", "--tags")89 ui.ExitOnError("pushing new version to repository", err)90}91func getCurrentAppVersion() string {92 // get current app version based on tags93 out, err := process.Execute("git", "tag")94 ui.ExitOnError("getting tags", err)95 versions := strings.Split(string(out), "\n")96 currentAppVersion := version.GetNewest(versions)97 ui.Info("Current version based on tags", currentAppVersion)98 return currentAppVersion99}100func getNextVersion(dev bool, currentVersion string, kind string) (nextVersion string) {101 var err error102 switch true {103 case dev && version.IsPrerelease(currentVersion):104 nextVersion, err = version.NextPrerelease(currentVersion)105 case dev && !version.IsPrerelease(currentVersion):106 nextVersion, err = version.Next(currentVersion, version.Patch)107 // semver sorting prerelease parts as strings108 nextVersion = nextVersion + "-beta001"109 default:110 nextVersion, err = version.Next(currentVersion, kind)111 }112 ui.ExitOnError("getting next version for "+kind, err)113 return114}...
hooks.go
Source:hooks.go
1package commands2import (3 "github.com/Nightapes/go-semantic-release/internal/hooks"4 "github.com/Nightapes/go-semantic-release/pkg/semanticrelease"5 "github.com/spf13/cobra"6)7func init() {8 hooksCmd.Flags().Bool("checks", false, "Check for missing values and envs")9 rootCmd.AddCommand(hooksCmd)10}11var hooksCmd = &cobra.Command{12 Use: "hooks",13 Short: "Run all hooks",14 RunE: func(cmd *cobra.Command, args []string) error {15 config, err := cmd.Flags().GetString("config")16 if err != nil {17 return err18 }19 repository, err := cmd.Flags().GetString("repository")20 if err != nil {21 return err22 }23 force, err := cmd.Flags().GetBool("no-cache")24 if err != nil {25 return err26 }27 configChecks, err := cmd.Flags().GetBool("checks")28 if err != nil {29 return err30 }31 releaseConfig := readConfig(config)32 s, err := semanticrelease.New(releaseConfig, repository, configChecks)33 if err != nil {34 return err35 }36 provider, err := s.GetCIProvider()37 if err != nil {38 return err39 }40 releaseVersion, err := s.GetNextVersion(provider, force, "")41 if err != nil {42 return err43 }44 hook := hooks.New(releaseConfig, releaseVersion)45 err = hook.PreRelease()46 if err != nil {47 return err48 }49 return hook.PostRelease()50 },51}...
getNextVersion
Using AI Code Generation
1import (2func main() {3 clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: "config"}, &clientcmd.ConfigOverrides{})4 cmd := cmd.NewCmdRollout(clientConfig)5 cmd.Flags().Set("output", "json")6 cmd.Flags().Set("filename", "config")7 cmd.Flags().Set("to-revision", "1")8 cmd.Flags().Set("watch", "true")9 cmd.Flags().Set("dry-run", "true")10 cmd.Run(cmd, []string{})11}12import (13func main() {14 clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: "config"}, &clientcmd.ConfigOverrides{})15 cmd := cmd.NewCmdRollback(clientConfig)16 cmd.Flags().Set("output", "json")17 cmd.Flags().Set("filename", "config")18 cmd.Flags().Set("to-revision", "1")19 cmd.Flags().Set("watch", "true")20 cmd.Flags().Set("dry-run", "true")21 cmd.Run(cmd, []string{})22}23import (24func main() {
getNextVersion
Using AI Code Generation
1import (2func main() {3 fmt.Println("Version: ", mycommands.GetNextVersion())4}5import (6func main() {7 fmt.Println("Version: ", mycommands.GetNextVersion())8}9import (10func main() {11 fmt.Println("Version: ", mycommands.GetNextVersion())12}13import (14func main() {15 fmt.Println("Version: ", mycommands.GetNextVersion())16}17import (18func main() {19 fmt.Println("Version: ", mycommands.GetNextVersion())20}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!