From 61250ea30f3b73a09cb3ffdc94726fdf31a406dd Mon Sep 17 00:00:00 2001 From: wsan3 Date: Tue, 9 Jul 2024 13:20:44 -0500 Subject: [PATCH 1/4] Add instance key to rule data for evaluation --- compiler/native/compile.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/native/compile.go b/compiler/native/compile.go index 0c739c310..89a5c9478 100644 --- a/compiler/native/compile.go +++ b/compiler/native/compile.go @@ -63,14 +63,15 @@ func (c *client) Compile(v interface{}) (*pipeline.Build, *library.Pipeline, err // create the ruledata to purge steps r := &pipeline.RuleData{ - Branch: c.build.GetBranch(), - Comment: c.comment, - Event: event, - Path: c.files, - Repo: c.repo.GetFullName(), - Tag: strings.TrimPrefix(c.build.GetRef(), "refs/tags/"), - Target: c.build.GetDeploy(), - Label: c.labels, + Branch: c.build.GetBranch(), + Comment: c.comment, + Event: event, + Path: c.files, + Repo: c.repo.GetFullName(), + Tag: strings.TrimPrefix(c.build.GetRef(), "refs/tags/"), + Target: c.build.GetDeploy(), + Label: c.labels, + Instance: c.metadata.Vela.Address, } switch { From d6af04ad8a52d6921bfb1100d304cf19944118a5 Mon Sep 17 00:00:00 2001 From: wsan3 Date: Thu, 1 Aug 2024 11:46:51 -0500 Subject: [PATCH 2/4] Upgrade types version --- go.mod | 4 +++- go.sum | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 86ba5e32d..917e6c9f5 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.22.0 toolchain go1.22.5 +replace github.com/go-vela/types => ../types + require ( github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb github.com/DATA-DOG/go-sqlmock v1.5.2 @@ -18,7 +20,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/gin-gonic/gin v1.10.0 github.com/go-playground/assert/v2 v2.2.0 - github.com/go-vela/types v0.24.0 + github.com/go-vela/types v0.24.1-0.20240726161255-75a480864eca github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 github.com/google/go-github/v63 v63.0.0 diff --git a/go.sum b/go.sum index f0ab32dd2..e8366e961 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,6 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/go-vela/types v0.24.0 h1:KkkiXxw3uHckh/foyadmLY1YnLw6vhZbz9XwqONCj6o= -github.com/go-vela/types v0.24.0/go.mod h1:YWj6BIapl9Kbj4yHq/fp8jltXdGiwD/gTy1ez32Rzag= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= From 3caf282990da45e7991f10dd888ef3a0595b588a Mon Sep 17 00:00:00 2001 From: wsan3 Date: Thu, 1 Aug 2024 11:53:20 -0500 Subject: [PATCH 3/4] Update types version --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 917e6c9f5..be3b818f3 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,6 @@ go 1.22.0 toolchain go1.22.5 -replace github.com/go-vela/types => ../types - require ( github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb github.com/DATA-DOG/go-sqlmock v1.5.2 @@ -20,7 +18,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/gin-gonic/gin v1.10.0 github.com/go-playground/assert/v2 v2.2.0 - github.com/go-vela/types v0.24.1-0.20240726161255-75a480864eca + github.com/go-vela/types v0.24.1-0.20240801155449-d47730bc9734 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 github.com/google/go-github/v63 v63.0.0 diff --git a/go.sum b/go.sum index e8366e961..47fd1a65a 100644 --- a/go.sum +++ b/go.sum @@ -91,6 +91,8 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/go-vela/types v0.24.1-0.20240801155449-d47730bc9734 h1:+eOrT2tPVqjXZRIAPcG0lyYyiCbGq45lQUlgjNpdv8g= +github.com/go-vela/types v0.24.1-0.20240801155449-d47730bc9734/go.mod h1:YWj6BIapl9Kbj4yHq/fp8jltXdGiwD/gTy1ez32Rzag= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= From 23101b2ae1ece89ea2415daaffa1d62e36934beb Mon Sep 17 00:00:00 2001 From: wsan3 Date: Wed, 7 Aug 2024 14:50:18 -0500 Subject: [PATCH 4/4] Update tests --- compiler/native/compile_test.go | 92 +++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/compiler/native/compile_test.go b/compiler/native/compile_test.go index 556d7c353..3ee7ddd4f 100644 --- a/compiler/native/compile_test.go +++ b/compiler/native/compile_test.go @@ -293,6 +293,26 @@ func TestNative_Compile_StagesPipeline_Modification(t *testing.T) { author := "author" number := 1 + m := &internal.Metadata{ + Database: &internal.Database{ + Driver: "foo", + Host: "foo", + }, + Queue: &internal.Queue{ + Channel: "foo", + Driver: "foo", + Host: "foo", + }, + Source: &internal.Source{ + Driver: "foo", + Host: "foo", + }, + Vela: &internal.Vela{ + Address: "foo", + WebAddress: "foo", + }, + } + // run test yaml, err := os.ReadFile("testdata/stages_pipeline.yml") if err != nil { @@ -329,8 +349,9 @@ func TestNative_Compile_StagesPipeline_Modification(t *testing.T) { Timeout: 1 * time.Second, Endpoint: tt.args.endpoint, }, - repo: &api.Repo{Name: &author}, - build: &api.Build{Author: &name, Number: &number}, + metadata: m, + repo: &api.Repo{Name: &author}, + build: &api.Build{Author: &name, Number: &number}, } _, _, err := compiler.Compile(yaml) if (err != nil) != tt.wantErr { @@ -361,6 +382,26 @@ func TestNative_Compile_StepsPipeline_Modification(t *testing.T) { author := "author" number := 1 + m := &internal.Metadata{ + Database: &internal.Database{ + Driver: "foo", + Host: "foo", + }, + Queue: &internal.Queue{ + Channel: "foo", + Driver: "foo", + Host: "foo", + }, + Source: &internal.Source{ + Driver: "foo", + Host: "foo", + }, + Vela: &internal.Vela{ + Address: "foo", + WebAddress: "foo", + }, + } + // run test yaml, err := os.ReadFile("testdata/steps_pipeline.yml") if err != nil { @@ -397,8 +438,9 @@ func TestNative_Compile_StepsPipeline_Modification(t *testing.T) { Timeout: 1 * time.Second, Endpoint: tt.args.endpoint, }, - repo: tt.args.repo, - build: tt.args.libraryBuild, + repo: tt.args.repo, + build: tt.args.libraryBuild, + metadata: m, } _, _, err := compiler.Compile(yaml) if (err != nil) != tt.wantErr { @@ -1835,6 +1877,26 @@ func TestNative_Compile_NoStepsorStages(t *testing.T) { author := "author" number := 1 + m := &internal.Metadata{ + Database: &internal.Database{ + Driver: "foo", + Host: "foo", + }, + Queue: &internal.Queue{ + Channel: "foo", + Driver: "foo", + Host: "foo", + }, + Source: &internal.Source{ + Driver: "foo", + Host: "foo", + }, + Vela: &internal.Vela{ + Address: "foo", + WebAddress: "foo", + }, + } + // run test yaml, err := os.ReadFile("testdata/metadata.yml") if err != nil { @@ -1849,6 +1911,7 @@ func TestNative_Compile_NoStepsorStages(t *testing.T) { // todo: this needs to be fixed in compiler validation // this is a dirty hack to make this test pass compiler.SetCloneImage("") + compiler.WithMetadata(m) compiler.repo = &api.Repo{Name: &author} compiler.build = &api.Build{Author: &name, Number: &number} @@ -1872,6 +1935,26 @@ func TestNative_Compile_StepsandStages(t *testing.T) { author := "author" number := 1 + m := &internal.Metadata{ + Database: &internal.Database{ + Driver: "foo", + Host: "foo", + }, + Queue: &internal.Queue{ + Channel: "foo", + Driver: "foo", + Host: "foo", + }, + Source: &internal.Source{ + Driver: "foo", + Host: "foo", + }, + Vela: &internal.Vela{ + Address: "foo", + WebAddress: "foo", + }, + } + // run test yaml, err := os.ReadFile("testdata/steps_and_stages.yml") if err != nil { @@ -1885,6 +1968,7 @@ func TestNative_Compile_StepsandStages(t *testing.T) { compiler.repo = &api.Repo{Name: &author} compiler.build = &api.Build{Author: &name, Number: &number} + compiler.WithMetadata(m) got, _, err := compiler.Compile(yaml) if err == nil {