Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let pipeline-compiler export step types #1958

Merged
merged 17 commits into from
Jul 11, 2023
Merged
20 changes: 20 additions & 0 deletions cmd/server/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pipeline/backend/types/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package types
type Step struct {
Name string `json:"name"`
UUID string `json:"uuid"`
Type StepType `json:"type,omitempty"`
Alias string `json:"alias,omitempty"`
Image string `json:"image,omitempty"`
Pull bool `json:"pull,omitempty"`
Expand Down Expand Up @@ -35,3 +36,14 @@ type Step struct {
Sysctls map[string]string `json:"sysctls,omitempty"`
BackendOptions BackendOptions `json:"backend_options,omitempty"`
}

// StepType identifies the type of step
type StepType string

const (
StepTypeClone StepType = "clone"
StepTypeService StepType = "service"
StepTypePlugin StepType = "plugin"
StepTypeCommands StepType = "commands"
StepTypeCache StepType = "cache"
)
17 changes: 10 additions & 7 deletions pipeline/frontend/yaml/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
defaultCloneName = "clone"

nameServices = "services"
namePipeline = "pipeline"
)

// Registry represents registry credentials
Expand Down Expand Up @@ -150,7 +149,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
Environment: c.cloneEnv,
}
name := fmt.Sprintf("%s_clone", c.prefix)
step := c.createProcess(name, container, defaultCloneName)
step := c.createProcess(name, container, backend_types.StepTypeClone)

stage := new(backend_types.Stage)
stage.Name = name
Expand All @@ -171,7 +170,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
stage.Alias = container.Name

name := fmt.Sprintf("%s_clone_%d", c.prefix, i)
step := c.createProcess(name, container, defaultCloneName)
step := c.createProcess(name, container, backend_types.StepTypeClone)

// only inject netrc if it's a trusted repo or a trusted plugin
if !c.netrcOnlyTrusted || c.trustedPipeline || (container.IsPlugin() && container.IsTrustedCloneImage()) {
Expand Down Expand Up @@ -202,7 +201,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
}

name := fmt.Sprintf("%s_%s_%d", c.prefix, nameServices, i)
step := c.createProcess(name, container, nameServices)
step := c.createProcess(name, container, backend_types.StepTypeService)
stage.Steps = append(stage.Steps, step)
}
config.Stages = append(config.Stages, stage)
Expand Down Expand Up @@ -233,7 +232,11 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
}

name := fmt.Sprintf("%s_step_%d", c.prefix, i)
step := c.createProcess(name, container, namePipeline)
stepType := backend_types.StepTypeCommands
if container.IsPlugin() {
stepType = backend_types.StepTypePlugin
}
step := c.createProcess(name, container, stepType)
stage.Steps = append(stage.Steps, step)
}

Expand All @@ -249,7 +252,7 @@ func (c *Compiler) setupCache(conf *yaml_types.Workflow, ir *backend_types.Confi

container := c.cacher.Restore(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)
name := fmt.Sprintf("%s_restore_cache", c.prefix)
step := c.createProcess(name, container, "cache")
step := c.createProcess(name, container, backend_types.StepTypeCache)

stage := new(backend_types.Stage)
stage.Name = name
Expand All @@ -266,7 +269,7 @@ func (c *Compiler) setupCacheRebuild(conf *yaml_types.Workflow, ir *backend_type
container := c.cacher.Rebuild(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)

name := fmt.Sprintf("%s_rebuild_cache", c.prefix)
step := c.createProcess(name, container, "cache")
step := c.createProcess(name, container, backend_types.StepTypeCache)

stage := new(backend_types.Stage)
stage.Name = name
Expand Down
5 changes: 3 additions & 2 deletions pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/utils"
)

func (c *Compiler) createProcess(name string, container *yaml_types.Container, section string) *backend_types.Step {
func (c *Compiler) createProcess(name string, container *yaml_types.Container, stepType backend_types.StepType) *backend_types.Step {
var (
uuid = uuid.New()

Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *Compiler) createProcess(name string, container *yaml_types.Container, s
environment["CI_WORKSPACE"] = path.Join(c.base, c.path)
environment["CI_STEP_NAME"] = name

if section == "services" || container.Detached {
if stepType == backend_types.StepTypeService || container.Detached {
detached = true
}

Expand Down Expand Up @@ -152,6 +152,7 @@ func (c *Compiler) createProcess(name string, container *yaml_types.Container, s
return &backend_types.Step{
Name: name,
UUID: uuid.String(),
Type: stepType,
Alias: container.Name,
Image: container.Image,
Pull: container.Pull,
Expand Down
2 changes: 1 addition & 1 deletion pipeline/rpc/proto/woodpecker.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pipeline/rpc/proto/woodpecker_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pipeline/stepBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func SetPipelineStepsOnPipeline(pipeline *model.Pipeline, pipelineItems []*Item)
PPID: item.Workflow.PID,
State: model.StatusPending,
Failure: step.Failure,
Type: model.StepType(step.Type),
}
if item.Workflow.State == model.StatusSkipped {
step.State = model.StatusSkipped
Expand Down
11 changes: 5 additions & 6 deletions server/forge/mocks/forge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions server/model/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Step struct {
ExitCode int `json:"exit_code" xorm:"step_exit_code"`
Started int64 `json:"start_time,omitempty" xorm:"step_started"`
Stopped int64 `json:"end_time,omitempty" xorm:"step_stopped"`
Type StepType `json:"type,omitempty" xorm:"step_type"`
} // @name Step

type UpdateStepStore interface {
Expand All @@ -67,3 +68,14 @@ func (p *Step) Running() bool {
func (p *Step) Failing() bool {
return p.Failure == FailureFail && (p.State == StatusError || p.State == StatusKilled || p.State == StatusFailure)
}

// StepType identifies the type of step
type StepType string // @name StepType

const (
anbraten marked this conversation as resolved.
Show resolved Hide resolved
StepTypeClone StepType = "clone"
StepTypeService StepType = "service"
StepTypePlugin StepType = "plugin"
StepTypeCommands StepType = "commands"
StepTypeCache StepType = "cache"
)
11 changes: 5 additions & 6 deletions server/store/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions web/src/lib/api/types/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export type PipelineStep = {
start_time?: number;
end_time?: number;
error?: string;
type?: StepType;
};

export type PipelineLog = {
Expand All @@ -140,3 +141,11 @@ export type PipelineLog = {
export type PipelineFeed = Pipeline & {
repo_id: number;
};

export enum StepType {
Clone = 1,
Service,
Plugin,
Commands,
Cache,
}
11 changes: 11 additions & 0 deletions woodpecker-go/woodpecker/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ const (
LogEntryMetadata
LogEntryProgress
)

// StepType identifies the type of step
type StepType string

const (
StepTypeClone StepType = "clone"
StepTypeService StepType = "service"
StepTypePlugin StepType = "plugin"
StepTypeCommands StepType = "commands"
StepTypeCache StepType = "cache"
)
19 changes: 10 additions & 9 deletions woodpecker-go/woodpecker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ type (

// Step represents a process in the pipeline.
Step struct {
ID int64 `json:"id"`
PID int `json:"pid"`
PPID int `json:"ppid"`
Name string `json:"name"`
State string `json:"state"`
Error string `json:"error,omitempty"`
ExitCode int `json:"exit_code"`
Started int64 `json:"start_time,omitempty"`
Stopped int64 `json:"end_time,omitempty"`
ID int64 `json:"id"`
PID int `json:"pid"`
PPID int `json:"ppid"`
Name string `json:"name"`
State string `json:"state"`
Error string `json:"error,omitempty"`
ExitCode int `json:"exit_code"`
Started int64 `json:"start_time,omitempty"`
Stopped int64 `json:"end_time,omitempty"`
Type StepType `json:"type,omitempty"`
}

// Registry represents a docker registry with credentials.
Expand Down