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(rulesets): add instance key to ruleset #1157

Merged
merged 7 commits into from
Sep 12, 2024
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
17 changes: 9 additions & 8 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@

// 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 {
Expand Down Expand Up @@ -325,7 +326,7 @@

if c.ModificationService.Endpoint != "" {
// send config to external endpoint for modification
p, err = c.modifyConfig(p, c.build, c.repo)

Check failure on line 329 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L329

Function `modifyConfig` should pass the context parameter (contextcheck)
Raw output
compiler/native/compile.go:329:26: Function `modifyConfig` should pass the context parameter (contextcheck)
		p, err = c.modifyConfig(p, c.build, c.repo)
		                       ^
if err != nil {
return nil, _pipeline, err
}
Expand Down Expand Up @@ -420,7 +421,7 @@

if c.ModificationService.Endpoint != "" {
// send config to external endpoint for modification
p, err = c.modifyConfig(p, c.build, c.repo)

Check failure on line 424 in compiler/native/compile.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/compile.go#L424

Function `modifyConfig` should pass the context parameter (contextcheck)
Raw output
compiler/native/compile.go:424:26: Function `modifyConfig` should pass the context parameter (contextcheck)
		p, err = c.modifyConfig(p, c.build, c.repo)
		                       ^
if err != nil {
return nil, _pipeline, err
}
Expand Down
92 changes: 88 additions & 4 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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 {
Expand Down Expand Up @@ -330,8 +350,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(context.Background(), yaml)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -362,6 +383,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 {
Expand Down Expand Up @@ -398,8 +439,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(context.Background(), yaml)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -1836,6 +1878,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 {
Expand All @@ -1850,6 +1912,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}
Expand All @@ -1873,6 +1936,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 {
Expand All @@ -1886,6 +1969,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(context.Background(), yaml)
if err == nil {
Expand Down
Loading