2022-01-06 20:27:18 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-06 23:34:37 +08:00
|
|
|
"git.icechen.cn/pkg/wujian_develop_tool/config"
|
2022-01-06 20:27:18 +08:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
|
|
|
|
"github.com/drone/drone-go/drone"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-06 23:34:37 +08:00
|
|
|
ciHost = "https://ci.icechen.cn"
|
|
|
|
ciToken = "b3e73c2e2f405e65de484d37ea48bb26"
|
2022-01-06 20:27:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// ActionBuildCI ci创建新构建
|
|
|
|
func ActionBuildCI(c *cli.Context) error {
|
2022-01-06 23:34:37 +08:00
|
|
|
if err := config.Init(c); err != nil {
|
2022-01-06 20:27:18 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
commit := c.String("commit")
|
|
|
|
app := strings.Join(c.Args().Slice(), ",")
|
|
|
|
|
|
|
|
oauth2Config := new(oauth2.Config)
|
|
|
|
auth := oauth2Config.Client(
|
|
|
|
context.Background(),
|
|
|
|
&oauth2.Token{
|
|
|
|
AccessToken: ciToken,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
client := drone.NewClient(ciHost, auth)
|
|
|
|
|
|
|
|
fInfo, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
temp := strings.Split(fInfo, string(os.PathSeparator))
|
|
|
|
name := temp[len(temp)-1]
|
|
|
|
|
2022-01-06 23:34:37 +08:00
|
|
|
color.Red("创建构建的仓库: %s/%s@master", config.Config.Name, name)
|
2022-01-06 20:27:18 +08:00
|
|
|
if len(app) > 0 {
|
|
|
|
color.Red("强制构建的应用(除了最后一次提交或指定的commit提交本应构建的应用): %+v\n\n", app)
|
|
|
|
}
|
2022-01-06 23:34:37 +08:00
|
|
|
b, err := client.BuildCreate(config.Config.Name, name, commit, "master", map[string]string{"app": app})
|
2022-01-06 20:27:18 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-06 23:34:37 +08:00
|
|
|
color.Green("构建成功!\n构建ID: %d\n去看看: %s/%s/%s/%d", b.Number, ciHost, config.Config.Name, name, b.Number)
|
2022-01-06 20:27:18 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|