feat: add [app] deploy
continuous-integration/drone/push Build is passing Details

master
icechen 2022-01-04 20:32:45 +08:00
parent 8a218d07cb
commit 3e0ef078c9
2 changed files with 45 additions and 4 deletions

View File

@ -1,2 +1,4 @@
# drone_plugin
## TODO
- new build with deploy app

View File

@ -61,7 +61,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
// 4. 根据文件树以及原始配置文件的信息组装需要构建的服务的ci信息
// 4.1 api
modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList)
modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList, req.Build.Message)
destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
if err != nil {
logrus.Error(err)
@ -69,7 +69,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
}
// 4.2 service
modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList)
modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList, req.Build.Message)
destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv())
if err != nil {
logrus.Error(err)
@ -109,7 +109,7 @@ func getDeployEnv(req *config.Request) consts.Env {
return consts.EnvNone
}
func getModifiedApi(api ApiList, modifiedFileList []string) ApiList {
func getModifiedApi(api ApiList, modifiedFileList []string, message string) ApiList {
ret := make(ApiList, 0)
tempIndex := NewSet()
for i, a := range api {
@ -123,10 +123,24 @@ func getModifiedApi(api ApiList, modifiedFileList []string) ApiList {
for _, i := range tempIndex.ToSlice() {
ret = append(ret, api[i])
}
ret = append(ret, getDeployApiByCommitMessage(api, message)...)
return ret
}
func getModifiedService(service ServiceList, modifiedFileList []string) ServiceList {
func getDeployApiByCommitMessage(api ApiList, message string) ApiList {
ret := make(ApiList, 0)
foundApp := foundAppByMessage(message)
for _, app := range foundApp {
for _, a := range api {
if a.Name == app {
ret = append(ret, a)
}
}
}
return ret
}
func getModifiedService(service ServiceList, modifiedFileList []string, message string) ServiceList {
ret := make(ServiceList, 0)
tempIndex := NewSet()
for i, s := range service {
@ -140,5 +154,30 @@ func getModifiedService(service ServiceList, modifiedFileList []string) ServiceL
for _, i := range tempIndex.ToSlice() {
ret = append(ret, service[i])
}
ret = append(ret, getDeployServiceByCommitMessage(service, message)...)
return ret
}
func getDeployServiceByCommitMessage(service ServiceList, message string) ServiceList {
ret := make(ServiceList, 0)
foundApp := foundAppByMessage(message)
for _, app := range foundApp {
for _, s := range service {
if s.Name == app {
ret = append(ret, s)
}
}
}
return ret
}
func foundAppByMessage(message string) []string {
i := strings.Index(message, "[")
if i >= 0 {
j := strings.Index(message[i:], "]")
if j >= 0 {
return append([]string{message[i+1 : j+i]}, foundAppByMessage(message[j+i:])...)
}
}
return []string{}
}