wujian_develop_tool/ci.go

58 lines
1.3 KiB
Go

package main
import (
"context"
"git.icechen.cn/pkg/wujian_develop_tool/config"
"os"
"strings"
"github.com/fatih/color"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli/v2"
"golang.org/x/oauth2"
)
var (
ciHost = "https://ci.icechen.cn"
ciToken = "b3e73c2e2f405e65de484d37ea48bb26"
)
// ActionBuildCI ci创建新构建
func ActionBuildCI(c *cli.Context) error {
if err := config.Init(c); err != nil {
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]
color.Red("创建构建的仓库: %s/%s@master", config.Config.Name, name)
if len(app) > 0 {
color.Red("强制构建的应用(除了最后一次提交或指定的commit提交本应构建的应用): %+v\n\n", app)
}
b, err := client.BuildCreate(config.Config.Name, name, commit, "master", map[string]string{"app": app})
if err != nil {
return err
}
color.Green("构建成功!\n构建ID: %d\n去看看: %s/%s/%s/%d", b.Number, ciHost, config.Config.Name, name, b.Number)
return nil
}