-
Notifications
You must be signed in to change notification settings - Fork 27
/
push.go
103 lines (87 loc) · 2.63 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cmd
import (
"context"
"errors"
"fmt"
"os"
"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)
var pushCmd = &cobra.Command{
Use: "push",
Short: "Push things from your local to a remote",
}
var pushK3sCmd = &cobra.Command{
Use: "k3s [version]",
Short: "Push k3s artifacts",
}
var pushK3sTagsCmd = &cobra.Command{
Use: "tags [version]",
Short: "Push k3s-io/kubernetes tags to remote",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("expected at least one argument: [version]")
}
version := args[0]
k3sRelease, found := rootConfig.K3s.Versions[version]
if !found {
return errors.New("verify your config file, version not found: " + version)
}
ctx := context.Background()
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)
return k3s.PushTags(ghClient, &k3sRelease, rootConfig.User, rootConfig.Auth.SSHKeyPath)
},
}
var pushChartsCmd = &cobra.Command{
Use: "charts [branch-line] [debug (optional)]",
Short: "Push charts updates to remote upstream charts repository",
Example: "release push charts 2.9",
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if err := validateChartConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(args) == 0 {
return rootConfig.Charts.BranchLines, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveNoFileComp
},
Args: func(cmd *cobra.Command, args []string) error {
if err := validateChartConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(args) < 1 {
return errors.New("expected 1 argument: [branch-line]")
}
if found := charts.IsBranchAvailable(args[0], rootConfig.Charts.BranchLines); !found {
return errors.New("release branch not available: " + args[0])
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
// arguments
releaseBranch := charts.MountReleaseBranch(args[0])
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
token := rootConfig.Auth.GithubToken
ctx := context.Background()
ghc := repository.NewGithub(ctx, token)
prURL, err := charts.Push(ctx, rootConfig.Charts, rootConfig.User, ghc, releaseBranch, token, debug)
if err != nil {
return err
}
fmt.Println("Pull request created: " + prURL)
return nil
},
}
func init() {
rootCmd.AddCommand(pushCmd)
pushCmd.AddCommand(pushK3sCmd)
pushCmd.AddCommand(pushChartsCmd)
pushK3sCmd.AddCommand(pushK3sTagsCmd)
}