From 71cd5eb9e8fc4504e68f3e9a7f969657680b1616 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 21 Feb 2025 15:28:41 -0600 Subject: [PATCH 1/3] refactor(skip): use new skip logic for stages --- docker-compose.yml | 4 ++-- executor/linux/build.go | 2 +- executor/linux/stage.go | 21 +++++++-------------- executor/local/build.go | 2 +- executor/local/stage.go | 21 ++++++++++++++++++++- go.mod | 4 +++- go.sum | 6 ++---- internal/step/skip.go | 11 +++++------ internal/step/skip_test.go | 2 +- 9 files changed, 42 insertions(+), 31 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1f74b915..079646da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: worker: build: context: . - dockerfile: Dockerfile + dockerfile: ${VELA_WORKER_DOCKERFILE:-Dockerfile} container_name: worker image: worker:local networks: @@ -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: diff --git a/executor/linux/build.go b/executor/linux/build.go index d19ba495..dc4db2b9 100644 --- a/executor/linux/build.go +++ b/executor/linux/build.go @@ -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) } diff --git a/executor/linux/stage.go b/executor/linux/stage.go index cfeff50b..0b0cc412 100644 --- a/executor/linux/stage.go +++ b/executor/linux/stage.go @@ -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) } @@ -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 } } diff --git a/executor/local/build.go b/executor/local/build.go index 62be5b3f..6e2c6710 100644 --- a/executor/local/build.go +++ b/executor/local/build.go @@ -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) } diff --git a/executor/local/stage.go b/executor/local/stage.go index 611c385d..60e21ceb 100644 --- a/executor/local/stage.go +++ b/executor/local/stage.go @@ -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" ) @@ -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) } @@ -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 diff --git a/go.mod b/go.mod index fe4ced8e..0f8ba5ae 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index bed50e8c..5f240e96 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/step/skip.go b/internal/step/skip.go index ca08740b..4536ac67 100644 --- a/internal/step/skip.go +++ b/internal/step/skip.go @@ -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 @@ -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 diff --git a/internal/step/skip_test.go b/internal/step/skip_test.go index f422c057..a7df45da 100644 --- a/internal/step/skip_test.go +++ b/internal/step/skip_test.go @@ -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) } From 42fd95673ddbe0d9de6c53d13557ba48014b4b14 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 2 May 2025 17:20:28 -0500 Subject: [PATCH 2/3] use remote mod for server and sdk --- go.mod | 9 ++------- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index afe4a75d..471f9c5a 100644 --- a/go.mod +++ b/go.mod @@ -2,19 +2,14 @@ module github.com/go-vela/worker go 1.24.2 -replace ( - github.com/go-vela/sdk-go => ../sdk-go - github.com/go-vela/server => ../server -) - require ( github.com/Masterminds/semver/v3 v3.3.1 github.com/distribution/reference v0.6.0 github.com/docker/docker v27.5.1+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.10.0 - github.com/go-vela/sdk-go v0.26.3-0.20250409022751-0f27f9202249 - github.com/go-vela/server v0.26.5-0.20250423182142-006676428923 + github.com/go-vela/sdk-go v0.26.3-0.20250502215856-0f39456b80b7 + github.com/go-vela/server v0.26.5-0.20250502193529-35e61d83d2d5 github.com/golang-jwt/jwt/v5 v5.2.2 github.com/google/go-cmp v0.7.0 github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum index f22ad75b..598a71ee 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,10 @@ github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0 github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/go-vela/sdk-go v0.26.3-0.20250502215856-0f39456b80b7 h1:A9I70UzKq4N6go7xD+uIkxXuBis37HR6stYP34dGd0A= +github.com/go-vela/sdk-go v0.26.3-0.20250502215856-0f39456b80b7/go.mod h1:tarc4/70a6ZJYfvrB59RJ7NeeP4u3ZCruwWQiiNOMR8= +github.com/go-vela/server v0.26.5-0.20250502193529-35e61d83d2d5 h1:lqjXIZn70hIbZIf+CQYEmnn00q9kT7l3zDrw4/GxgX0= +github.com/go-vela/server v0.26.5-0.20250502193529-35e61d83d2d5/go.mod h1:mIuATibKsGYq0c/XUKq46xx3ohKIqyoyB8PTyoE2c5E= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= From f29e9385bbe1c269c383f37ebed8e307c7866713 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 2 May 2025 17:21:08 -0500 Subject: [PATCH 3/3] fix docker compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 079646da..17722ff6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,7 +51,7 @@ services: # https://go-vela.github.io/docs/administration/server/ server: container_name: server - image: server:local + image: target/vela-server:latest networks: - vela environment: