Skip to content

Commit 71cd5eb

Browse files
author
ecrupper
committed
refactor(skip): use new skip logic for stages
1 parent 8a2f07a commit 71cd5eb

File tree

9 files changed

+42
-31
lines changed

9 files changed

+42
-31
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
worker:
1313
build:
1414
context: .
15-
dockerfile: Dockerfile
15+
dockerfile: ${VELA_WORKER_DOCKERFILE:-Dockerfile}
1616
container_name: worker
1717
image: worker:local
1818
networks:
@@ -51,7 +51,7 @@ services:
5151
# https://go-vela.github.io/docs/administration/server/
5252
server:
5353
container_name: server
54-
image: target/vela-server:latest
54+
image: server:local
5555
networks:
5656
- vela
5757
environment:

executor/linux/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
487487
// check if the step should be skipped
488488
//
489489
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
490-
skip, err := step.Skip(_step, c.build)
490+
skip, err := step.Skip(_step, c.build, c.build.GetStatus())
491491
if err != nil {
492492
return fmt.Errorf("unable to plan step: %w", c.err)
493493
}

executor/linux/stage.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,22 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)
116116

117117
logger.Debug("starting execution of stage")
118118

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

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

130-
// set parallel rule that determines whether the step should adhere to entire build
131-
// status check, which is determined by independent rule and stop value.
132-
if !stop && s.Independent {
133-
_step.Ruleset.If.Parallel = true
125+
if s.Independent {
126+
useStatus = stageStatus
134127
} else {
135-
_step.Ruleset.If.Parallel = false
128+
useStatus = c.build.GetStatus()
136129
}
137130

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

executor/local/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
278278
// check if the step should be skipped
279279
//
280280
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
281-
skip, err := step.Skip(_step, c.build)
281+
skip, err := step.Skip(_step, c.build, c.build.GetStatus())
282282
if err != nil {
283283
return fmt.Errorf("unable to plan step: %w", c.err)
284284
}

executor/local/stage.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111

1212
"github.com/go-vela/server/compiler/types/pipeline"
13+
"github.com/go-vela/server/constants"
1314
"github.com/go-vela/worker/internal/step"
1415
)
1516

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

92+
stageStatus := c.build.GetStatus()
93+
9194
// execute the steps for the stage
9295
for _, _step := range s.Steps {
96+
if !s.Independent && c.build.GetStatus() == constants.StatusFailure {
97+
continue
98+
}
99+
100+
var useStatus string
101+
102+
if s.Independent {
103+
useStatus = stageStatus
104+
} else {
105+
useStatus = c.build.GetStatus()
106+
}
107+
93108
// check if the step should be skipped
94109
//
95110
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
96-
skip, err := step.Skip(_step, c.build)
111+
skip, err := step.Skip(_step, c.build, useStatus)
97112
if err != nil {
98113
return fmt.Errorf("unable to plan step: %w", c.err)
99114
}
@@ -114,6 +129,10 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map)
114129
if err != nil {
115130
return fmt.Errorf("unable to exec step %s: %w", _step.Name, err)
116131
}
132+
133+
if _step.ExitCode != 0 && !_step.Ruleset.Continue {
134+
stageStatus = constants.StatusFailure
135+
}
117136
}
118137

119138
return nil

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/go-vela/worker
22

33
go 1.23.5
44

5+
replace github.com/go-vela/server => ../server
6+
57
require (
68
github.com/Masterminds/semver/v3 v3.3.1
79
github.com/distribution/reference v0.6.0
@@ -157,7 +159,7 @@ require (
157159
go.opentelemetry.io/otel v1.34.0 // indirect
158160
go.opentelemetry.io/otel/metric v1.34.0 // indirect
159161
go.opentelemetry.io/otel/trace v1.34.0 // indirect
160-
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f // indirect
162+
go.starlark.net v0.0.0-20250128212104-d908c3ead437 // indirect
161163
golang.org/x/arch v0.13.0 // indirect
162164
golang.org/x/crypto v0.32.0 // indirect
163165
golang.org/x/mod v0.21.0 // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
121121
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
122122
github.com/go-vela/sdk-go v0.26.0 h1:j5Q2LzHFt7BV34Eub4a1b3Nz1VVUVqSxgIAVhHgVtTU=
123123
github.com/go-vela/sdk-go v0.26.0/go.mod h1:+KoGEZNkqxsPOjgi7mEGdsBVA4Jj+vp1xr8oDJsaIGk=
124-
github.com/go-vela/server v0.26.0 h1:UPmPVZDAQcQGoU1X8XL9T7YgSAojU2+208THF8txwt4=
125-
github.com/go-vela/server v0.26.0/go.mod h1:xyOWQhjaGTpQuYlDD/pG63MmO+JTk5UBcCdoFPjHZGs=
126124
github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
127125
github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
128126
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
@@ -350,8 +348,8 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
350348
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
351349
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
352350
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
353-
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f h1:Zs/py28HDFATSDzPcfIzrBFjVsV7HzDEGNNVZIGsjm0=
354-
go.starlark.net v0.0.0-20241226192728-8dfa5b98479f/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8=
351+
go.starlark.net v0.0.0-20250128212104-d908c3ead437 h1:S+5NdaGkB7iQUrL3EFN5/yRs1YjGuRs8MRcafiRdhro=
352+
go.starlark.net v0.0.0-20250128212104-d908c3ead437/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8=
355353
golang.org/x/arch v0.13.0 h1:KCkqVVV1kGg0X87TFysjCJ8MxtZEIU4Ja/yXGeoECdA=
356354
golang.org/x/arch v0.13.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
357355
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

internal/step/skip.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// Skip creates the ruledata from the build and repository
1414
// information and returns true if the data does not match
1515
// the ruleset for the given container.
16-
func Skip(c *pipeline.Container, b *api.Build) (bool, error) {
16+
func Skip(c *pipeline.Container, b *api.Build, status string) (bool, error) {
1717
// check if the container provided is empty
1818
if c == nil {
1919
return true, nil
@@ -29,11 +29,10 @@ func Skip(c *pipeline.Container, b *api.Build) (bool, error) {
2929

3030
// create ruledata from build and repository information
3131
ruledata := &pipeline.RuleData{
32-
Branch: b.GetBranch(),
33-
Event: event,
34-
Repo: b.GetRepo().GetFullName(),
35-
Status: b.GetStatus(),
36-
Parallel: c.Ruleset.If.Parallel,
32+
Branch: b.GetBranch(),
33+
Event: event,
34+
Repo: b.GetRepo().GetFullName(),
35+
Status: status,
3736
}
3837

3938
// check if the build event is tag

internal/step/skip_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestStep_Skip(t *testing.T) {
265265
// run test
266266
for _, test := range tests {
267267
t.Run(test.name, func(t *testing.T) {
268-
got, err := Skip(test.container, test.build)
268+
got, err := Skip(test.container, test.build, test.build.GetStatus())
269269
if err != nil {
270270
t.Errorf("Skip returned error: %s", err)
271271
}

0 commit comments

Comments
 (0)