Skip to content

Commit

Permalink
refactor(skip): use new skip logic for stages
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Feb 21, 2025
1 parent 8a2f07a commit 71cd5eb
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
worker:
build:
context: .
dockerfile: Dockerfile
dockerfile: ${VELA_WORKER_DOCKERFILE:-Dockerfile}
container_name: worker
image: worker:local
networks:
Expand Down Expand Up @@ -51,7 +51,7 @@ services:
# https://go-vela.github.io/docs/administration/server/
server:
container_name: server
image: target/vela-server:latest
image: server:local
networks:
- vela
environment:
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
// check if the step should be skipped
//
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
skip, err := step.Skip(_step, c.build)
skip, err := step.Skip(_step, c.build, c.build.GetStatus())
if err != nil {
return fmt.Errorf("unable to plan step: %w", c.err)
}
Expand Down
21 changes: 7 additions & 14 deletions executor/linux/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,22 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)

logger.Debug("starting execution of stage")

// stop value determines when a stage's step series should stop executing
stop := false
stageStatus := constants.StatusRunning

// execute the steps for the stage
for _, _step := range s.Steps {
// first check to see if we need to stop the stage before it even starts.
// this happens when using 'needs' block
if !s.Independent && c.build.GetStatus() == constants.StatusFailure {
stop = true
}
var useStatus string

// set parallel rule that determines whether the step should adhere to entire build
// status check, which is determined by independent rule and stop value.
if !stop && s.Independent {
_step.Ruleset.If.Parallel = true
if s.Independent {
useStatus = stageStatus
} else {
_step.Ruleset.If.Parallel = false
useStatus = c.build.GetStatus()
}

// check if the step should be skipped
//
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
skip, err := step.Skip(_step, c.build)
skip, err := step.Skip(_step, c.build, useStatus)
if err != nil {
return fmt.Errorf("unable to plan step: %w", c.err)
}
Expand Down Expand Up @@ -213,7 +206,7 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)
// failed steps within the stage should set the stop value to true unless
// the continue rule is set to true.
if _step.ExitCode != 0 && !_step.Ruleset.Continue {
stop = true
stageStatus = constants.StatusFailure
}
}

Expand Down
2 changes: 1 addition & 1 deletion executor/local/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
// check if the step should be skipped
//
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
skip, err := step.Skip(_step, c.build)
skip, err := step.Skip(_step, c.build, c.build.GetStatus())
if err != nil {
return fmt.Errorf("unable to plan step: %w", c.err)
}
Expand Down
21 changes: 20 additions & 1 deletion executor/local/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/constants"
"github.com/go-vela/worker/internal/step"
)

Expand Down Expand Up @@ -88,12 +89,26 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)
close(errChan.(chan error))
}()

stageStatus := c.build.GetStatus()

// execute the steps for the stage
for _, _step := range s.Steps {
if !s.Independent && c.build.GetStatus() == constants.StatusFailure {
continue
}

var useStatus string

if s.Independent {
useStatus = stageStatus
} else {
useStatus = c.build.GetStatus()
}

// check if the step should be skipped
//
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
skip, err := step.Skip(_step, c.build)
skip, err := step.Skip(_step, c.build, useStatus)
if err != nil {
return fmt.Errorf("unable to plan step: %w", c.err)
}
Expand All @@ -114,6 +129,10 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)
if err != nil {
return fmt.Errorf("unable to exec step %s: %w", _step.Name, err)
}

if _step.ExitCode != 0 && !_step.Ruleset.Continue {
stageStatus = constants.StatusFailure
}
}

return nil
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/go-vela/worker

go 1.23.5

replace github.com/go-vela/server => ../server

require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/distribution/reference v0.6.0
Expand Down Expand Up @@ -157,7 +159,7 @@ require (
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f // indirect
go.starlark.net v0.0.0-20250128212104-d908c3ead437 // indirect
golang.org/x/arch v0.13.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/mod v0.21.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-vela/sdk-go v0.26.0 h1:j5Q2LzHFt7BV34Eub4a1b3Nz1VVUVqSxgIAVhHgVtTU=
github.com/go-vela/sdk-go v0.26.0/go.mod h1:+KoGEZNkqxsPOjgi7mEGdsBVA4Jj+vp1xr8oDJsaIGk=
github.com/go-vela/server v0.26.0 h1:UPmPVZDAQcQGoU1X8XL9T7YgSAojU2+208THF8txwt4=
github.com/go-vela/server v0.26.0/go.mod h1:xyOWQhjaGTpQuYlDD/pG63MmO+JTk5UBcCdoFPjHZGs=
github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down Expand Up @@ -350,8 +348,8 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f h1:Zs/py28HDFATSDzPcfIzrBFjVsV7HzDEGNNVZIGsjm0=
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8=
go.starlark.net v0.0.0-20250128212104-d908c3ead437 h1:S+5NdaGkB7iQUrL3EFN5/yRs1YjGuRs8MRcafiRdhro=
go.starlark.net v0.0.0-20250128212104-d908c3ead437/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8=
golang.org/x/arch v0.13.0 h1:KCkqVVV1kGg0X87TFysjCJ8MxtZEIU4Ja/yXGeoECdA=
golang.org/x/arch v0.13.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
11 changes: 5 additions & 6 deletions internal/step/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Skip creates the ruledata from the build and repository
// information and returns true if the data does not match
// the ruleset for the given container.
func Skip(c *pipeline.Container, b *api.Build) (bool, error) {
func Skip(c *pipeline.Container, b *api.Build, status string) (bool, error) {
// check if the container provided is empty
if c == nil {
return true, nil
Expand All @@ -29,11 +29,10 @@ func Skip(c *pipeline.Container, b *api.Build) (bool, error) {

// create ruledata from build and repository information
ruledata := &pipeline.RuleData{
Branch: b.GetBranch(),
Event: event,
Repo: b.GetRepo().GetFullName(),
Status: b.GetStatus(),
Parallel: c.Ruleset.If.Parallel,
Branch: b.GetBranch(),
Event: event,
Repo: b.GetRepo().GetFullName(),
Status: status,
}

// check if the build event is tag
Expand Down
2 changes: 1 addition & 1 deletion internal/step/skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestStep_Skip(t *testing.T) {
// run test
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := Skip(test.container, test.build)
got, err := Skip(test.container, test.build, test.build.GetStatus())
if err != nil {
t.Errorf("Skip returned error: %s", err)
}
Expand Down

0 comments on commit 71cd5eb

Please sign in to comment.