diff --git a/pkg/microservice/aslan/core/common/repository/models/workflow_v4.go b/pkg/microservice/aslan/core/common/repository/models/workflow_v4.go index 146167a31a..82286ac99e 100644 --- a/pkg/microservice/aslan/core/common/repository/models/workflow_v4.go +++ b/pkg/microservice/aslan/core/common/repository/models/workflow_v4.go @@ -508,7 +508,7 @@ type DeployHelmChart struct { type DeployBasicInfo struct { ServiceName string `bson:"service_name" yaml:"service_name" json:"service_name"` Modules []*DeployModuleInfo `bson:"modules" yaml:"modules" json:"modules"` - Deployed bool `bson:"-" yaml:"deployed" json:"deployed"` + Deployed bool `bson:"deployed" yaml:"deployed" json:"deployed"` AutoSync bool `bson:"-" yaml:"auto_sync" json:"auto_sync"` UpdateConfig bool `bson:"update_config" yaml:"update_config" json:"update_config"` Updatable bool `bson:"-" yaml:"updatable" json:"updatable"` diff --git a/pkg/microservice/aslan/core/release_plan/service/execute.go b/pkg/microservice/aslan/core/release_plan/service/execute.go index 947a2f4e65..841854233c 100644 --- a/pkg/microservice/aslan/core/release_plan/service/execute.go +++ b/pkg/microservice/aslan/core/release_plan/service/execute.go @@ -18,7 +18,6 @@ package service import ( "fmt" - "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller" "time" "github.com/pkg/errors" @@ -26,6 +25,7 @@ import ( "github.com/koderover/zadig/v2/pkg/microservice/aslan/config" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow" + "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller" "github.com/koderover/zadig/v2/pkg/shared/client/user" "github.com/koderover/zadig/v2/pkg/tool/log" ) diff --git a/pkg/microservice/aslan/core/release_plan/service/release_plan.go b/pkg/microservice/aslan/core/release_plan/service/release_plan.go index e3ab0d3734..f7562ab840 100644 --- a/pkg/microservice/aslan/core/release_plan/service/release_plan.go +++ b/pkg/microservice/aslan/core/release_plan/service/release_plan.go @@ -778,7 +778,7 @@ func SkipReleaseJob(c *handler.Context, planID string, args *SkipReleaseJobArgs, return nil } -func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystemAdmin bool) error { +func UpdateReleasePlanStatus(c *handler.Context, planID, targetStatus string, isSystemAdmin bool) error { approveLock := getLock(planID) approveLock.Lock() defer approveLock.Unlock() @@ -790,12 +790,16 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem return errors.Wrap(err, "get plan") } + if plan.Status == config.ReleasePlanStatus(targetStatus) { + return fmt.Errorf("current status can not equal to target status %s", targetStatus) + } + if c.UserID != plan.ManagerID && !isSystemAdmin { return errors.Errorf("only manager can update plan status") } - if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(status)) { - return errors.Errorf("can't convert plan status %s to %s", plan.Status, status) + if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(targetStatus)) { + return errors.Errorf("can't convert plan status %s to %s", plan.Status, targetStatus) } userInfo, err := user.New().GetUserByID(c.UserID) @@ -821,11 +825,20 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem return errors.Errorf("plan must not have no jobs") } plan.PlanningTime = time.Now().Unix() + case config.ReleasePlanStatusWaitForApproveExternalCheck, + config.ReleasePlanStatusWaitForApproveExternalCheckFailed, + config.ReleasePlanStatusWaitForExecuteExternalCheck, + config.ReleasePlanStatusWaitForExecuteExternalCheckFailed, + config.ReleasePlanStatusWaitForAllDoneExternalCheck, + config.ReleasePlanStatusWaitForAllDoneExternalCheckFailed: + if config.ReleasePlanStatus(targetStatus) != config.ReleasePlanStatusPlanning { + return fmt.Errorf("can't update status, current status: %s", plan.Status) + } } - plan.Status = config.ReleasePlanStatus(status) + plan.Status = config.ReleasePlanStatus(targetStatus) // target status check and update - switch config.ReleasePlanStatus(status) { + switch config.ReleasePlanStatus(targetStatus) { case config.ReleasePlanStatusPlanning: for _, job := range plan.Jobs { job.LastStatus = job.Status @@ -836,6 +849,9 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem plan.HookSettings = hookSetting.ToHookSettings() plan.PlanningTime = time.Now().Unix() + plan.ApprovalTime = 0 + plan.ExecutingTime = 0 + plan.SuccessTime = 0 plan.WaitForApproveExternalCheckTime = 0 plan.WaitForExecuteExternalCheckTime = 0 plan.WaitForAllDoneExternalCheckTime = 0 @@ -899,7 +915,7 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem TargetType: TargetTypeReleasePlanStatus, Detail: detail, Before: plan.Status, - After: status, + After: targetStatus, CreatedAt: time.Now().Unix(), }); err != nil { log.Errorf("create release plan log error: %v", err) @@ -1574,6 +1590,10 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w hookSpec := interface{}(nil) for _, job := range stage.Jobs { + if job.Skipped { + continue + } + switch job.JobType { case config.JobZadigBuild: spec := new(commonmodels.ZadigBuildJobSpec) @@ -1909,7 +1929,9 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w }) } - hookStages = append(hookStages, hookStage) + if len(hookStage.Jobs) != 0 { + hookStages = append(hookStages, hookStage) + } } return &webhooknotify.OpenAPIWorkflowV4{