@@ -23,7 +23,6 @@ func main() {
23
23
defer cancel ()
24
24
25
25
config := flag .String ("config" , filepath .Join ("config" , "konflux" , "repository.yaml" ), "specify the repository configuration" )
26
- branch := flag .String ("branch" , "main" , "specify the repository configuration" )
27
26
flag .Parse ()
28
27
29
28
in , err := os .ReadFile (* config )
@@ -35,28 +34,30 @@ func main() {
35
34
log .Fatalln ("Unmarshal config" , err )
36
35
}
37
36
38
- var versions []string
39
37
for _ , b := range c .Branches {
40
- if b .Name == * branch {
38
+ var versions []string
39
+ if len (b .Versions ) == 0 {
40
+ versions = []string {b .Name }
41
+ } else {
41
42
for _ , v := range b .Versions {
42
43
versions = append (versions , v .Version )
43
44
}
44
45
}
45
- }
46
46
47
- // Create temporary folder
48
- dir , err := os .MkdirTemp ("" , "konflux-apply" )
49
- if err != nil {
50
- log .Fatalln (err )
51
- }
47
+ // Create temporary folder
48
+ dir , err := os .MkdirTemp ("" , "konflux-apply" )
49
+ if err != nil {
50
+ log .Fatalln (err )
51
+ }
52
52
53
- // Clone repository
54
- if err := gitClone (ctx , dir , c .Repository ); err != nil {
55
- log .Fatalln (err )
56
- }
57
- //Kubectl apply
58
- if err := apply (ctx , dir , versions ); err != nil {
59
- log .Fatalln (err )
53
+ // Clone repository
54
+ if err := gitClone (ctx , dir , c .Repository , b .Name ); err != nil {
55
+ log .Fatalln (err )
56
+ }
57
+ //Kubectl apply
58
+ if err := apply (ctx , dir , versions ); err != nil {
59
+ log .Fatalln (err )
60
+ }
60
61
}
61
62
}
62
63
@@ -70,16 +71,16 @@ func apply(ctx context.Context, dir string, versions []string) error {
70
71
71
72
log .Printf ("Final CMD : %s\n " , cmd .String ())
72
73
73
- // if err := cmd.Run(); err != nil {
74
- // return err
75
- // }
74
+ if err := cmd .Run (); err != nil {
75
+ return err
76
+ }
76
77
}
77
78
return nil
78
79
}
79
80
80
- func gitClone (ctx context.Context , dir , repository string ) error {
81
+ func gitClone (ctx context.Context , dir , repository string , branch string ) error {
81
82
log .Printf ("Cloning %s in %s\n " , osp + repository , dir )
82
- cmd := exec .CommandContext (ctx , "git" , "clone" , osp + repository , "." )
83
+ cmd := exec .CommandContext (ctx , "git" , "clone" , "-b" , branch , osp + repository , "." )
83
84
cmd .Dir = dir
84
85
cmd .Stdout = os .Stdout
85
86
cmd .Stderr = os .Stderr
0 commit comments