@@ -2,82 +2,12 @@ package main
22
33import (
44 "fmt"
5- "github.com/gsdevme/gitops-commit/internal/pkg/gitops"
6- "github.com/spf13/cobra"
7- "io/ioutil"
5+ "github.com/gsdevme/gitops-commit/internal/app/gitops-commit/cmd"
86 "os"
9- "strings"
107)
118
12- func NewRootCommand () * cobra.Command {
13- c := cobra.Command {
14- Use : "gitops-commit" ,
15- RunE : func (cmd * cobra.Command , args []string ) error {
16- key := cmd .Flag ("key" ).Value .String ()
17- email := cmd .Flag ("email" ).Value .String ()
18- newVersion := cmd .Flag ("version" ).Value .String ()
19- notation := cmd .Flag ("notation" ).Value .String ()
20- repo := strings .TrimRight (cmd .Flag ("repo" ).Value .String (), "/" )
21- file := strings .TrimLeft (cmd .Flag ("file" ).Value .String (), "/" )
22-
23- options , c , err := gitops .NewGitOptions (key )
24-
25- if len (email ) > 0 {
26- options .Email = email
27- }
28-
29- if err != nil {
30- return err
31- }
32-
33- defer c ()
34-
35- r , err := gitops .CloneRepository (options , repo )
36-
37- if err != nil {
38- return fmt .Errorf ("failed to clone repo %s: %w" , repo , err )
39- }
40-
41- filename := fmt .Sprintf ("%s/%s" , options .WorkingDirectory , file )
42-
43- f , err := ioutil .ReadFile (filename )
44-
45- if err != nil {
46- return fmt .Errorf ("cannot read file: %w" , err )
47- }
48-
49- version , err := gitops .ReadCurrentVersion (f , notation )
50- if err != nil {
51- return fmt .Errorf ("cannot read current version deployed: %w" , err )
52- }
53-
54- err = gitops .WriteVersion (f , version , newVersion , filename )
55- if err != nil {
56- return fmt .Errorf ("cannot write new version: %w" , err )
57- }
58-
59- gitops .PushVersion (r , options , file , fmt .Sprintf ("ci: update tag to %s" , newVersion ))
60-
61- return nil
62- },
63- }
64-
65- c .Flags ().String ("notation" , "" , "The yaml path in dot notation i.e. image.tag" )
66- c .Flags ().String ("email" , "" , "The email address of the commit" )
67- c .Flags ().String ("version" , "" , "The semver version you want to deploy i.e. v1.1.2" )
68- c .Flags ().String ("key" , fmt .Sprintf ("%s/.ssh/id_rsa" , os .Getenv ("HOME" )), "Absolute path to the private key" )
69- c .Flags ().String ("repo" , "gsdevme/test" , "The org/repo path" )
70- c .Flags ().String ("file" , "/deployments/values.yaml" , "The relative path in the repository to the file" )
71-
72- _ = c .MarkFlagRequired ("notation" )
73- _ = c .MarkFlagRequired ("tag" )
74- _ = c .MarkFlagRequired ("file" )
75-
76- return & c
77- }
78-
799func main () {
80- if err := NewRootCommand ().Execute (); err != nil {
10+ if err := cmd . NewRootCommand ().Execute (); err != nil {
8111 fmt .Println (err )
8212 os .Exit (1 )
8313 }
0 commit comments