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

feat(stage): stages fail independently when continue is set to true #318

Merged
merged 13 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ services:
VELA_ACCESS_TOKEN_DURATION: 60m
VELA_DISABLE_WEBHOOK_VALIDATION: 'true'
VELA_ENABLE_SECURE_COOKIE: 'false'
VELA_REPO_ALLOWLIST: '*'
env_file:
- .env
restart: always
Expand Down
25 changes: 25 additions & 0 deletions executor/linux/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"sync"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/internal/step"
)
Expand Down Expand Up @@ -118,8 +119,26 @@ 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

// 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
}

// 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
} else {
_step.Ruleset.If.Parallel = false
}

// check if the step should be skipped
//
// https://pkg.go.dev/github.com/go-vela/worker/internal/step#Skip
Expand All @@ -140,6 +159,12 @@ 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)
}

// 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
}
}

return nil
Expand Down
9 changes: 6 additions & 3 deletions executor/linux/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ func TestLinux_ExecStage(t *testing.T) {
name: "docker-basic stage",
failure: false,
stage: &pipeline.Stage{
Name: "echo",
Independent: true,
Name: "echo",
Steps: pipeline.ContainerSlice{
{
ID: "github_octocat_1_echo_echo",
Expand All @@ -335,7 +336,8 @@ func TestLinux_ExecStage(t *testing.T) {
name: "docker-stage with step container with image not found",
failure: true,
stage: &pipeline.Stage{
Name: "echo",
Name: "echo",
Independent: true,
Steps: pipeline.ContainerSlice{
{
ID: "github_octocat_1_echo_echo",
Expand All @@ -353,7 +355,8 @@ func TestLinux_ExecStage(t *testing.T) {
name: "docker-stage with step container with bad number",
failure: true,
stage: &pipeline.Stage{
Name: "echo",
Name: "echo",
Independent: true,
Steps: pipeline.ContainerSlice{
{
ID: "github_octocat_1_echo_echo",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/gin-gonic/gin v1.8.1
github.com/go-vela/sdk-go v0.16.2
github.com/go-vela/server v0.16.2
github.com/go-vela/types v0.16.2
github.com/go-vela/types v0.16.3-0.20221209200126-e2772715208d
github.com/google/go-cmp v0.5.9
github.com/joho/godotenv v1.4.0
github.com/opencontainers/image-spec v1.0.2
Expand All @@ -34,7 +34,7 @@ require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/alicebob/miniredis/v2 v2.23.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 // indirect
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8=
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3/go.mod h1:5hCug3EZaHXU3FdCA3gJm0YTNi+V+ooA2qNTiVpky4A=
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396 h1:qLN32md48xyTEqw6XEZMyNMre7njm0XXvDrea6NVwOM=
github.com/buildkite/yaml v0.0.0-20210326113714-4a3f40911396/go.mod h1:AV5wtJnn1/CRaRGlJ8xspkMWfKXV0/pkJVgGleTIrfk=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
Expand Down Expand Up @@ -157,8 +157,8 @@ github.com/go-vela/sdk-go v0.16.2 h1:M9+u89mGomJc2uwUPVGWp9UnUIFm0IhIIsFEfxROhZQ
github.com/go-vela/sdk-go v0.16.2/go.mod h1:BuTkw+MYWbAKJ6+ZtQ/nNmwIcjn/tysCPks4X+csBGE=
github.com/go-vela/server v0.16.2 h1:qovjGN9ZQazjV0JTXzP6o5UPSs1D+wyUMpbG4G6aXZI=
github.com/go-vela/server v0.16.2/go.mod h1:bf9dpkzhL2T6G6fxIwjmMjzoD+e5Xfmg3DcckP6lqHc=
github.com/go-vela/types v0.16.2 h1:c2Kkj7OKv4sjPrsOBbnPSQqfsNpOFM2La7LfP+81EF0=
github.com/go-vela/types v0.16.2/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo=
github.com/go-vela/types v0.16.3-0.20221209200126-e2772715208d h1:8RZaWRt/VMH69oW1EYSLHHQvf7yD899Ur235lhpAG68=
github.com/go-vela/types v0.16.3-0.20221209200126-e2772715208d/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
Expand Down
9 changes: 5 additions & 4 deletions internal/step/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ func Skip(c *pipeline.Container, b *library.Build, r *library.Repo) bool {
//
// https://pkg.go.dev/github.com/go-vela/types/pipeline#RuleData
ruledata := &pipeline.RuleData{
Branch: b.GetBranch(),
Event: event,
Repo: r.GetFullName(),
Status: b.GetStatus(),
Branch: b.GetBranch(),
Event: event,
Repo: r.GetFullName(),
Status: b.GetStatus(),
Parallel: c.Ruleset.If.Parallel,
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
}

// check if the build event is tag
Expand Down