From 3d4399807a4bc5060649a47f710837fcca8cd01f Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:25:15 -0400 Subject: [PATCH] refactor(build): update library build to API build and remove repo from executor (#576) * init commit * fix mock, add new server and sdk, revert compose --- api/executor.go | 20 ----- api/repo.go | 6 +- cmd/vela-worker/exec.go | 15 ++-- cmd/vela-worker/run.go | 4 +- cmd/vela-worker/worker.go | 4 +- executor/context_test.go | 4 - executor/engine.go | 8 +- executor/executor_test.go | 67 +++++++--------- executor/linux/api.go | 14 +--- executor/linux/api_test.go | 53 ------------- executor/linux/build.go | 26 +++--- executor/linux/build_test.go | 40 ++++------ executor/linux/driver_test.go | 1 - executor/linux/linux.go | 4 +- executor/linux/linux_test.go | 16 ++-- executor/linux/opts.go | 20 +---- executor/linux/opts_test.go | 51 +----------- executor/linux/secret.go | 12 +-- executor/linux/secret_test.go | 15 +--- executor/linux/service.go | 20 ++--- executor/linux/service_test.go | 10 --- executor/linux/stage.go | 2 +- executor/linux/stage_test.go | 12 +-- executor/linux/step.go | 24 +++--- executor/linux/step_test.go | 10 --- executor/local/api.go | 14 +--- executor/local/api_test.go | 53 ------------- executor/local/build.go | 14 ++-- executor/local/build_test.go | 36 +++------ executor/local/local.go | 5 +- executor/local/local_test.go | 14 ++-- executor/local/opts.go | 15 +--- executor/local/opts_test.go | 36 +-------- executor/local/service.go | 8 +- executor/local/service_test.go | 10 --- executor/local/stage.go | 2 +- executor/local/stage_test.go | 12 +-- executor/local/step.go | 6 +- executor/local/step_test.go | 10 --- executor/setup.go | 11 +-- executor/setup_test.go | 25 ++---- go.mod | 4 +- go.sum | 8 +- internal/build/snapshot.go | 5 +- internal/build/snapshot_test.go | 52 ++++++------ internal/build/upload.go | 5 +- internal/build/upload_test.go | 55 ++++++------- internal/service/environment.go | 19 ++--- internal/service/environment_test.go | 41 +++++----- internal/service/snapshot.go | 4 +- internal/service/snapshot_test.go | 42 +++++----- internal/service/upload.go | 4 +- internal/service/upload_test.go | 45 +++++------ internal/step/environment.go | 19 ++--- internal/step/environment_test.go | 41 +++++----- internal/step/skip.go | 5 +- internal/step/skip_test.go | 63 +++++++-------- internal/step/snapshot.go | 10 +-- internal/step/snapshot_test.go | 88 ++++++++++----------- internal/step/upload.go | 4 +- internal/step/upload_test.go | 47 +++++------ mock/worker/build.go | 61 ++++++++++++-- router/middleware/executor/executor_test.go | 17 ++-- 63 files changed, 490 insertions(+), 878 deletions(-) diff --git a/api/executor.go b/api/executor.go index 50ca3aeb..a51cd033 100644 --- a/api/executor.go +++ b/api/executor.go @@ -72,16 +72,6 @@ func GetExecutor(c *gin.Context) { return } - // get repo on executor - executor.Repo, err = e.GetRepo() - if err != nil { - msg := fmt.Errorf("unable to retrieve repo: %w", err).Error() - - c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg}) - - return - } - c.JSON(http.StatusOK, executor) } @@ -161,16 +151,6 @@ func GetExecutors(c *gin.Context) { return } - // get repo on executor - tmp.Repo, err = executor.GetRepo() - if err != nil { - msg := fmt.Errorf("unable to retrieve repo: %w", err).Error() - - c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg}) - - return - } - executors = append(executors, tmp) } diff --git a/api/repo.go b/api/repo.go index a1ee9283..ed4ab318 100644 --- a/api/repo.go +++ b/api/repo.go @@ -42,14 +42,14 @@ import ( func GetRepo(c *gin.Context) { e := executor.Retrieve(c) - repo, err := e.GetRepo() + build, err := e.GetBuild() if err != nil { - msg := fmt.Errorf("unable to read repo: %w", err).Error() + msg := fmt.Errorf("unable to read build: %w", err).Error() c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg}) return } - c.JSON(http.StatusOK, repo) + c.JSON(http.StatusOK, build.GetRepo()) } diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go index a96b7cf5..a2b234e5 100644 --- a/cmd/vela-worker/exec.go +++ b/cmd/vela-worker/exec.go @@ -58,7 +58,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { } // retrieve a build token from the server to setup the execBuildClient - bt, resp, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber()) + bt, resp, err := w.VelaClient.Build.GetBuildToken(item.Build.GetRepo().GetOrg(), item.Build.GetRepo().GetName(), item.Build.GetNumber()) if err != nil { logrus.Errorf("unable to retrieve build token: %s", err) @@ -78,7 +78,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { } // request build executable containing pipeline.Build data using exec client - execBuildExecutable, _, err := execBuildClient.Build.GetBuildExecutable(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber()) + execBuildExecutable, _, err := execBuildClient.Build.GetBuildExecutable(item.Build.GetRepo().GetOrg(), item.Build.GetRepo().GetName(), item.Build.GetNumber()) if err != nil { return err } @@ -98,9 +98,9 @@ func (w *Worker) exec(index int, config *api.Worker) error { "build": item.Build.GetNumber(), "executor": w.Config.Executor.Driver, "host": w.Config.API.Address.Hostname(), - "repo": item.Repo.GetFullName(), + "repo": item.Build.GetRepo().GetFullName(), "runtime": w.Config.Runtime.Driver, - "user": item.Repo.GetOwner().GetName(), + "user": item.Build.GetRepo().GetOwner().GetName(), "version": v.Semantic(), }) @@ -137,7 +137,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { build.SetStatus(constants.StatusError) build.SetFinished(time.Now().UTC().Unix()) - _, _, err := execBuildClient.Build.Update(item.Repo.GetOrg(), item.Repo.GetName(), build) + _, _, err := execBuildClient.Build.Update(build) if err != nil { logrus.Errorf("Unable to set build status to %s: %s", constants.StatusFailure, err) return err @@ -181,7 +181,6 @@ func (w *Worker) exec(index int, config *api.Worker) error { Runtime: w.Runtime, Build: item.Build, Pipeline: pipeline.Sanitize(w.Config.Runtime.Driver), - Repo: item.Repo, Version: v.Semantic(), }) @@ -237,9 +236,9 @@ func (w *Worker) exec(index int, config *api.Worker) error { // capture the configured build timeout t := w.Config.Build.Timeout // check if the repository has a custom timeout - if item.Repo.GetTimeout() > 0 { + if item.Build.GetRepo().GetTimeout() > 0 { // update timeout variable to repository custom timeout - t = time.Duration(item.Repo.GetTimeout()) * time.Minute + t = time.Duration(item.Build.GetRepo().GetTimeout()) * time.Minute } // create a build context (from a background context diff --git a/cmd/vela-worker/run.go b/cmd/vela-worker/run.go index bdc358da..20ba16a4 100644 --- a/cmd/vela-worker/run.go +++ b/cmd/vela-worker/run.go @@ -12,8 +12,8 @@ import ( _ "github.com/joho/godotenv/autoload" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/queue" - "github.com/go-vela/types/library" "github.com/go-vela/worker/executor" "github.com/go-vela/worker/runtime" ) @@ -136,7 +136,7 @@ func run(c *cli.Context) error { RegisterToken: make(chan string, 1), - RunningBuilds: make([]*library.Build, 0), + RunningBuilds: make([]*api.Build, 0), } // set the worker address if no flag was provided diff --git a/cmd/vela-worker/worker.go b/cmd/vela-worker/worker.go index a0a86f2b..834a88b0 100644 --- a/cmd/vela-worker/worker.go +++ b/cmd/vela-worker/worker.go @@ -8,8 +8,8 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/queue" - "github.com/go-vela/types/library" "github.com/go-vela/worker/executor" "github.com/go-vela/worker/runtime" ) @@ -69,7 +69,7 @@ type ( VelaClient *vela.Client RegisterToken chan string CheckedIn bool - RunningBuilds []*library.Build + RunningBuilds []*api.Build QueueCheckedIn bool RunningBuildsMutex sync.Mutex } diff --git a/executor/context_test.go b/executor/context_test.go index e39efc43..a2aef53f 100644 --- a/executor/context_test.go +++ b/executor/context_test.go @@ -35,7 +35,6 @@ func TestExecutor_FromContext(t *testing.T) { _engine, err := linux.New( linux.WithBuild(_build), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), ) @@ -99,7 +98,6 @@ func TestExecutor_FromGinContext(t *testing.T) { _engine, err := linux.New( linux.WithBuild(_build), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), ) @@ -169,7 +167,6 @@ func TestExecutor_WithContext(t *testing.T) { _engine, err := linux.New( linux.WithBuild(_build), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), ) @@ -207,7 +204,6 @@ func TestExecutor_WithGinContext(t *testing.T) { _engine, err := linux.New( linux.WithBuild(_build), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), ) diff --git a/executor/engine.go b/executor/engine.go index d427b4a0..d9cdcb50 100644 --- a/executor/engine.go +++ b/executor/engine.go @@ -7,7 +7,6 @@ import ( "sync" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" ) @@ -25,16 +24,13 @@ type Engine interface { // GetBuild defines a function for the API // that gets the current build in execution. - GetBuild() (*library.Build, error) + GetBuild() (*api.Build, error) // GetPipeline defines a function for the API // that gets the current pipeline in execution. GetPipeline() (*pipeline.Build, error) - // GetRepo defines a function for the API - // that gets the current repo in execution. - GetRepo() (*api.Repo, error) // CancelBuild defines a function for the API // that Cancels the current build in execution. - CancelBuild() (*library.Build, error) + CancelBuild() (*api.Build, error) // Build Engine interface functions diff --git a/executor/executor_test.go b/executor/executor_test.go index 1fc9c643..48d8d778 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -15,7 +15,6 @@ import ( "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/executor/linux" "github.com/go-vela/worker/executor/local" @@ -43,7 +42,6 @@ func TestExecutor_New(t *testing.T) { linux.WithHostname("localhost"), linux.WithMaxLogSize(2097152), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), linux.WithVersion("v1.0.0"), @@ -56,7 +54,6 @@ func TestExecutor_New(t *testing.T) { local.WithBuild(_build), local.WithHostname("localhost"), local.WithPipeline(_pipeline), - local.WithRepo(_repo), local.WithRuntime(_runtime), local.WithVelaClient(_client), local.WithVersion("v1.0.0"), @@ -81,7 +78,6 @@ func TestExecutor_New(t *testing.T) { Client: _client, Driver: constants.DriverDarwin, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -97,7 +93,6 @@ func TestExecutor_New(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -112,7 +107,6 @@ func TestExecutor_New(t *testing.T) { Client: _client, Driver: "local", Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -127,7 +121,6 @@ func TestExecutor_New(t *testing.T) { Client: _client, Driver: constants.DriverWindows, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -142,7 +135,6 @@ func TestExecutor_New(t *testing.T) { Client: _client, Driver: "invalid", Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -157,7 +149,6 @@ func TestExecutor_New(t *testing.T) { Client: _client, Driver: "", Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", }, @@ -198,33 +189,6 @@ func TestExecutor_New(t *testing.T) { // setup global variables used for testing. var ( - _build = &library.Build{ - ID: vela.Int64(1), - Number: vela.Int(1), - Parent: vela.Int(1), - Event: vela.String("push"), - Status: vela.String("success"), - Error: vela.String(""), - Enqueued: vela.Int64(1563474077), - Created: vela.Int64(1563474076), - Started: vela.Int64(1563474077), - Finished: vela.Int64(0), - Deploy: vela.String(""), - Clone: vela.String("https://github.com/github/octocat.git"), - Source: vela.String("https://github.com/github/octocat/abcdefghi123456789"), - Title: vela.String("push received from https://github.com/github/octocat"), - Message: vela.String("First commit..."), - Commit: vela.String("48afb5bdc41ad69bf22588491333f7cf71135163"), - Sender: vela.String("OctoKitty"), - Author: vela.String("OctoKitty"), - Branch: vela.String("main"), - Ref: vela.String("refs/heads/main"), - BaseRef: vela.String(""), - Host: vela.String("example.company.com"), - Runtime: vela.String("docker"), - Distribution: vela.String("linux"), - } - _pipeline = &pipeline.Build{ Version: "1", ID: "github_octocat_1", @@ -257,11 +221,10 @@ var ( }, } - _user = &library.User{ + _user = &api.User{ ID: vela.Int64(1), Name: vela.String("octocat"), Token: vela.String("superSecretToken"), - Hash: vela.String("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy"), Favorites: vela.Strings([]string{"github/octocat"}), Active: vela.Bool(true), Admin: vela.Bool(false), @@ -305,4 +268,32 @@ var ( AllowEvents: _allowEvents, Owner: _user, } + + _build = &api.Build{ + ID: vela.Int64(1), + Number: vela.Int(1), + Repo: _repo, + Parent: vela.Int(1), + Event: vela.String("push"), + Status: vela.String("success"), + Error: vela.String(""), + Enqueued: vela.Int64(1563474077), + Created: vela.Int64(1563474076), + Started: vela.Int64(1563474077), + Finished: vela.Int64(0), + Deploy: vela.String(""), + Clone: vela.String("https://github.com/github/octocat.git"), + Source: vela.String("https://github.com/github/octocat/abcdefghi123456789"), + Title: vela.String("push received from https://github.com/github/octocat"), + Message: vela.String("First commit..."), + Commit: vela.String("48afb5bdc41ad69bf22588491333f7cf71135163"), + Sender: vela.String("OctoKitty"), + Author: vela.String("OctoKitty"), + Branch: vela.String("main"), + Ref: vela.String("refs/heads/main"), + BaseRef: vela.String(""), + Host: vela.String("example.company.com"), + Runtime: vela.String("docker"), + Distribution: vela.String("linux"), + } ) diff --git a/executor/linux/api.go b/executor/linux/api.go index a4aa33fa..0654000c 100644 --- a/executor/linux/api.go +++ b/executor/linux/api.go @@ -16,7 +16,7 @@ import ( ) // GetBuild gets the current build in execution. -func (c *client) GetBuild() (*library.Build, error) { +func (c *client) GetBuild() (*api.Build, error) { // check if the build resource is available if c.build == nil { return nil, fmt.Errorf("build resource not found") @@ -35,20 +35,10 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { return c.pipeline, nil } -// GetRepo gets the current repo in execution. -func (c *client) GetRepo() (*api.Repo, error) { - // check if the repo resource is available - if c.repo == nil { - return nil, fmt.Errorf("repo resource not found") - } - - return c.repo, nil -} - // CancelBuild cancels the current build in execution. // //nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized -func (c *client) CancelBuild() (*library.Build, error) { +func (c *client) CancelBuild() (*api.Build, error) { // get the current build from the client b, err := c.GetBuild() if err != nil { diff --git a/executor/linux/api_test.go b/executor/linux/api_test.go index 705f485b..23dfd654 100644 --- a/executor/linux/api_test.go +++ b/executor/linux/api_test.go @@ -114,56 +114,3 @@ func TestLinux_GetPipeline(t *testing.T) { }) } } - -func TestLinux_GetRepo(t *testing.T) { - // setup types - _repo := testRepo() - - _engine, err := New( - WithRepo(_repo), - ) - if err != nil { - t.Errorf("unable to create executor engine: %v", err) - } - - // setup tests - tests := []struct { - name string - failure bool - engine *client - }{ - { - name: "with repo", - failure: false, - engine: _engine, - }, - { - name: "missing repo", - failure: true, - engine: new(client), - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got, err := test.engine.GetRepo() - - if test.failure { - if err == nil { - t.Errorf("GetRepo should have returned err") - } - - return // continue to next test - } - - if err != nil { - t.Errorf("GetRepo returned err: %v", err) - } - - if !reflect.DeepEqual(got, _repo) { - t.Errorf("GetRepo is %v, want %v", got, _repo) - } - }) - } -} diff --git a/executor/linux/build.go b/executor/linux/build.go index f6adee4c..51f1a56a 100644 --- a/executor/linux/build.go +++ b/executor/linux/build.go @@ -26,7 +26,7 @@ func (c *client) CreateBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger, c.repo) }() + defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger) }() // update the build fields c.build.SetStatus(constants.StatusRunning) @@ -39,7 +39,7 @@ func (c *client) CreateBuild(ctx context.Context) error { // send API call to update the build // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#BuildService.Update - c.build, _, c.err = c.Vela.Build.Update(c.repo.GetOrg(), c.repo.GetName(), c.build) + c.build, _, c.err = c.Vela.Build.Update(c.build) if c.err != nil { return fmt.Errorf("unable to upload build state: %w", c.err) } @@ -80,7 +80,7 @@ func (c *client) PlanBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger, c.repo) }() + defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger) }() // load the init step from the client // @@ -109,7 +109,7 @@ func (c *client) PlanBuild(ctx context.Context) error { _init.SetStatus(constants.StatusFailure) } - step.SnapshotInit(c.init, c.build, c.Vela, c.Logger, c.repo, _init, _log) + step.SnapshotInit(c.init, c.build, c.Vela, c.Logger, _init, _log) }() c.Logger.Info("creating network") @@ -220,7 +220,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger, c.repo) }() + defer func() { build.Snapshot(c.build, c.Vela, c.err, c.Logger) }() // load the init step from the client // @@ -246,7 +246,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { _init.SetStatus(constants.StatusFailure) } - step.Upload(c.init, c.build, c.Vela, c.Logger, c.repo, _init) + step.Upload(c.init, c.build, c.Vela, c.Logger, _init) }() defer func() { @@ -254,7 +254,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // send API call to update the logs for the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateStep - _, err = c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), c.init.Number, _log) + _, err = c.Vela.Log.UpdateStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), c.init.Number, _log) if err != nil { c.Logger.Errorf("unable to upload %s logs: %v", c.init.Name, err) } @@ -450,8 +450,10 @@ func (c *client) AssembleBuild(ctx context.Context) error { _log.AppendData([]byte(fmt.Sprintf("Privileges verified for image %s\n", container.Image))) } + localBool := c.build.GetRepo().GetTrusted() + // ensure pipelines containing privileged images are only permitted to run by trusted repos - if (containsPrivilegedImages) && !(c.repo != nil && c.repo.GetTrusted()) { + if (containsPrivilegedImages) && !localBool { // update error including privileged image c.err = fmt.Errorf("unable to assemble build. pipeline contains privileged images and repo is not trusted. privileged image: %v", privImages) @@ -505,7 +507,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // defer an upload of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Upload - build.Upload(c.build, c.Vela, c.err, c.Logger, c.repo) + build.Upload(c.build, c.Vela, c.err, c.Logger) }() c.Logger.Info("executing secret images") @@ -542,7 +544,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, c.repo) + skip, err := step.Skip(_step, c.build) if err != nil { return fmt.Errorf("unable to plan step: %w", c.err) } @@ -769,7 +771,7 @@ func loadLazySecrets(c *client, _step *pipeline.Container) error { _log.AppendData([]byte( fmt.Sprintf("unable to pull secret %s: lazy loading secrets not available with Kubernetes runtime\n", s.Source))) - _, err := c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step.Number, _log) + _, err := c.Vela.Log.UpdateStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _step.Number, _log) if err != nil { return err } @@ -797,7 +799,7 @@ func loadLazySecrets(c *client, _step *pipeline.Container) error { _log.AppendData(append(sRaw, "\n"...)) - _, err = c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step.Number, _log) + _, err = c.Vela.Log.UpdateStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _step.Number, _log) if err != nil { return err } diff --git a/executor/linux/build_test.go b/executor/linux/build_test.go index bf3b1a2a..8ec6e4c8 100644 --- a/executor/linux/build_test.go +++ b/executor/linux/build_test.go @@ -21,7 +21,6 @@ import ( "github.com/go-vela/server/compiler/native" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -36,7 +35,6 @@ func TestLinux_CreateBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -55,7 +53,7 @@ func TestLinux_CreateBuild(t *testing.T) { failure bool logError bool runtime string - build *library.Build + build *api.Build pipeline string }{ { @@ -127,7 +125,7 @@ func TestLinux_CreateBuild(t *testing.T) { failure: true, logError: false, runtime: constants.DriverDocker, - build: new(library.Build), + build: new(api.Build), pipeline: "testdata/build/steps/basic.yml", }, { @@ -135,7 +133,7 @@ func TestLinux_CreateBuild(t *testing.T) { failure: true, logError: false, runtime: constants.DriverKubernetes, - build: new(library.Build), + build: new(api.Build), pipeline: "testdata/build/steps/basic.yml", }, } @@ -149,7 +147,7 @@ func TestLinux_CreateBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -178,7 +176,6 @@ func TestLinux_CreateBuild(t *testing.T) { WithLogger(logger), WithBuild(test.build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), @@ -257,7 +254,7 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { name string failure bool runtime string - build *library.Build + build *api.Build repo *api.Repo pipeline string privilegedImages []string @@ -988,9 +985,12 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { // run test for _, test := range tests { t.Run(test.name, func(t *testing.T) { + // ensure custom test repos are in the executor engine + test.build.SetRepo(test.repo) + _pipeline, _, err := compiler. Duplicate(). - WithBuild(_build). + WithBuild(test.build). WithRepo(test.repo). Compile(test.pipeline) if err != nil { @@ -1010,7 +1010,6 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { _engine, err := New( WithBuild(test.build), WithPipeline(_pipeline), - WithRepo(test.repo), WithRuntime(_runtime), WithVelaClient(_client), WithPrivilegedImages(test.privilegedImages), @@ -1028,6 +1027,7 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { // override mock handler PUT build update // used for dynamic substitute testing _engine.build.SetMessage(test.build.GetMessage()) + _engine.build.SetRepo(test.repo) err = _engine.AssembleBuild(context.Background()) @@ -1053,7 +1053,6 @@ func TestLinux_PlanBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1155,7 +1154,7 @@ func TestLinux_PlanBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1184,7 +1183,6 @@ func TestLinux_PlanBuild(t *testing.T) { WithLogger(logger), WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -1237,7 +1235,6 @@ func TestLinux_AssembleBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1440,7 +1437,7 @@ func TestLinux_AssembleBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1468,7 +1465,6 @@ func TestLinux_AssembleBuild(t *testing.T) { WithLogger(logger), WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -1546,7 +1542,6 @@ func TestLinux_ExecBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1676,7 +1671,7 @@ func TestLinux_ExecBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1711,7 +1706,6 @@ func TestLinux_ExecBuild(t *testing.T) { WithLogger(logger), WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -1837,7 +1831,6 @@ func TestLinux_StreamBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -2320,7 +2313,7 @@ func TestLinux_StreamBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -2349,7 +2342,6 @@ func TestLinux_StreamBuild(t *testing.T) { WithLogger(logger), WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithLogStreamingTimeout(1*time.Second), WithVelaClient(_client), @@ -2452,7 +2444,6 @@ func TestLinux_DestroyBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -2596,7 +2587,7 @@ func TestLinux_DestroyBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -2625,7 +2616,6 @@ func TestLinux_DestroyBuild(t *testing.T) { WithLogger(logger), WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), ) diff --git a/executor/linux/driver_test.go b/executor/linux/driver_test.go index ffc3a917..bc12ed30 100644 --- a/executor/linux/driver_test.go +++ b/executor/linux/driver_test.go @@ -37,7 +37,6 @@ func TestLinux_Driver(t *testing.T) { WithBuild(testBuild()), WithHostname("localhost"), WithPipeline(testSteps(constants.DriverDocker)), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) diff --git a/executor/linux/linux.go b/executor/linux/linux.go index a6f695c3..6bd422af 100644 --- a/executor/linux/linux.go +++ b/executor/linux/linux.go @@ -39,9 +39,8 @@ type ( logStreamingTimeout time.Duration privilegedImages []string enforceTrustedRepos bool - build *library.Build + build *api.Build pipeline *pipeline.Build - repo *api.Repo secrets sync.Map services sync.Map serviceLogs sync.Map @@ -78,7 +77,6 @@ func Equal(a, b *client) bool { a.enforceTrustedRepos == b.enforceTrustedRepos && reflect.DeepEqual(a.build, b.build) && reflect.DeepEqual(a.pipeline, b.pipeline) && - reflect.DeepEqual(a.repo, b.repo) && reflect.DeepEqual(&a.secrets, &b.secrets) && reflect.DeepEqual(&a.services, &b.services) && reflect.DeepEqual(&a.serviceLogs, &b.serviceLogs) && diff --git a/executor/linux/linux_test.go b/executor/linux/linux_test.go index daacee41..4f7f7cfa 100644 --- a/executor/linux/linux_test.go +++ b/executor/linux/linux_test.go @@ -15,7 +15,6 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/runtime/docker" ) @@ -40,7 +39,6 @@ func TestEqual(t *testing.T) { WithBuild(testBuild()), WithHostname("localhost"), WithPipeline(testSteps(constants.DriverDocker)), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -52,7 +50,6 @@ func TestEqual(t *testing.T) { WithBuild(testBuild()), WithHostname("a.different.host"), WithPipeline(testSteps(constants.DriverDocker)), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -126,7 +123,7 @@ func TestLinux_New(t *testing.T) { tests := []struct { name string failure bool - build *library.Build + build *api.Build }{ { name: "with build", @@ -147,7 +144,6 @@ func TestLinux_New(t *testing.T) { WithBuild(test.build), WithHostname("localhost"), WithPipeline(testSteps(constants.DriverDocker)), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -169,10 +165,11 @@ func TestLinux_New(t *testing.T) { // testBuild is a test helper function to create a Build // type with all fields set to a fake value. -func testBuild() *library.Build { - return &library.Build{ +func testBuild() *api.Build { + return &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: testRepo(), Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -220,12 +217,11 @@ func testRepo() *api.Repo { // testUser is a test helper function to create a User // type with all fields set to a fake value. -func testUser() *library.User { - return &library.User{ +func testUser() *api.User { + return &api.User{ ID: vela.Int64(1), Name: vela.String("octocat"), Token: vela.String("superSecretToken"), - Hash: vela.String("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy"), Favorites: vela.Strings([]string{"github/octocat"}), Active: vela.Bool(true), Admin: vela.Bool(false), diff --git a/executor/linux/opts.go b/executor/linux/opts.go index d7dbd943..ea130992 100644 --- a/executor/linux/opts.go +++ b/executor/linux/opts.go @@ -10,7 +10,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -20,7 +19,7 @@ import ( type Opt func(*client) error // WithBuild sets the library build in the executor client for Linux. -func WithBuild(b *library.Build) Opt { +func WithBuild(b *api.Build) Opt { return func(c *client) error { c.Logger.Trace("configuring build in linux executor client") @@ -134,23 +133,6 @@ func WithPipeline(p *pipeline.Build) Opt { } } -// WithRepo sets the library repo in the executor client for Linux. -func WithRepo(r *api.Repo) Opt { - return func(c *client) error { - c.Logger.Trace("configuring repository in linux executor client") - - // check if the repo provided is empty - if r == nil { - return fmt.Errorf("empty repo provided") - } - - // set the repo in the client - c.repo = r - - return nil - } -} - // WithRuntime sets the runtime engine in the executor client for Linux. func WithRuntime(r runtime.Engine) Opt { return func(c *client) error { diff --git a/executor/linux/opts_test.go b/executor/linux/opts_test.go index 540ec2ac..ade2dd21 100644 --- a/executor/linux/opts_test.go +++ b/executor/linux/opts_test.go @@ -15,7 +15,6 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/runtime" "github.com/go-vela/worker/runtime/docker" @@ -30,7 +29,7 @@ func TestLinux_Opt_WithBuild(t *testing.T) { tests := []struct { name string failure bool - build *library.Build + build *api.Build }{ { name: "build", @@ -378,54 +377,6 @@ func TestLinux_Opt_WithPipeline(t *testing.T) { } } -func TestLinux_Opt_WithRepo(t *testing.T) { - // setup types - _repo := testRepo() - - // setup tests - tests := []struct { - name string - failure bool - repo *api.Repo - }{ - { - name: "repo", - failure: false, - repo: _repo, - }, - { - name: "nil repo", - failure: true, - repo: nil, - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - _engine, err := New( - WithRepo(test.repo), - ) - - if test.failure { - if err == nil { - t.Errorf("WithRepo should have returned err") - } - - return // continue to next test - } - - if err != nil { - t.Errorf("WithRepo returned err: %v", err) - } - - if !reflect.DeepEqual(_engine.repo, _repo) { - t.Errorf("WithRepo is %v, want %v", _engine.repo, _repo) - } - }) - } -} - func TestLinux_Opt_WithRuntime(t *testing.T) { // setup types _docker, err := docker.NewMock() diff --git a/executor/linux/secret.go b/executor/linux/secret.go index bcd74ecc..e87c1883 100644 --- a/executor/linux/secret.go +++ b/executor/linux/secret.go @@ -116,7 +116,7 @@ func (s *secretSvc) exec(ctx context.Context, p *pipeline.SecretSlice) error { // send API call to update the build // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _, _, err = s.client.Vela.Step.Update(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), _init) + _, _, err = s.client.Vela.Step.Update(s.client.build.GetRepo().GetOrg(), s.client.build.GetRepo().GetName(), s.client.build.GetNumber(), _init) if err != nil { s.client.Logger.Errorf("unable to upload init state: %v", err) } @@ -180,7 +180,7 @@ func (s *secretSvc) exec(ctx context.Context, p *pipeline.SecretSlice) error { // send API call to update the build // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _, _, err = s.client.Vela.Step.Update(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), _init) + _, _, err = s.client.Vela.Step.Update(s.client.build.GetRepo().GetOrg(), s.client.build.GetRepo().GetName(), s.client.build.GetNumber(), _init) if err != nil { s.client.Logger.Errorf("unable to upload init state: %v", err) } @@ -196,7 +196,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*library.Secret, error) { switch secret.Type { // handle repo secrets case constants.SecretOrg: - org, key, err := secret.ParseOrg(s.client.repo.GetOrg()) + org, key, err := secret.ParseOrg(s.client.build.GetRepo().GetOrg()) if err != nil { return nil, err } @@ -213,7 +213,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*library.Secret, error) { // handle repo secrets case constants.SecretRepo: - org, repo, key, err := secret.ParseRepo(s.client.repo.GetOrg(), s.client.repo.GetName()) + org, repo, key, err := secret.ParseRepo(s.client.build.GetRepo().GetOrg(), s.client.build.GetRepo().GetName()) if err != nil { return nil, err } @@ -283,7 +283,7 @@ func (s *secretSvc) stream(ctx context.Context, ctn *pipeline.Container) error { // send API call to update the logs for the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateService - _, err = s.client.Vela.Log.UpdateStep(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), ctn.Number, _log) + _, err = s.client.Vela.Log.UpdateStep(s.client.build.GetRepo().GetOrg(), s.client.build.GetRepo().GetName(), s.client.build.GetNumber(), ctn.Number, _log) if err != nil { logger.Errorf("unable to upload container logs: %v", err) } @@ -318,7 +318,7 @@ func (s *secretSvc) stream(ctx context.Context, ctn *pipeline.Container) error { // send API call to append the logs for the init step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateStep - _, err = s.client.Vela.Log.UpdateStep(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), s.client.init.Number, _log) + _, err = s.client.Vela.Log.UpdateStep(s.client.build.GetRepo().GetOrg(), s.client.build.GetRepo().GetName(), s.client.build.GetNumber(), s.client.init.Number, _log) if err != nil { return err } diff --git a/executor/linux/secret_test.go b/executor/linux/secret_test.go index 9630ceda..8c09c38a 100644 --- a/executor/linux/secret_test.go +++ b/executor/linux/secret_test.go @@ -29,7 +29,6 @@ import ( func TestLinux_Secret_create(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _steps := testSteps(constants.DriverDocker) gin.SetMode(gin.TestMode) @@ -122,7 +121,6 @@ func TestLinux_Secret_create(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_steps), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -150,7 +148,6 @@ func TestLinux_Secret_create(t *testing.T) { func TestLinux_Secret_delete(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _dockerSteps := testSteps(constants.DriverDocker) _kubernetesSteps := testSteps(constants.DriverKubernetes) @@ -323,7 +320,6 @@ func TestLinux_Secret_delete(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(test.steps), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -368,8 +364,6 @@ func TestLinux_Secret_exec(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, set, nil)) _build := testBuild() - _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -424,8 +418,8 @@ func TestLinux_Secret_exec(t *testing.T) { p, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). - WithUser(_user). + WithRepo(_build.GetRepo()). + WithUser(_build.GetRepo().GetOwner()). Compile(file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -453,7 +447,6 @@ func TestLinux_Secret_exec(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(p), - WithRepo(_repo), WithRuntime(_runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -497,7 +490,6 @@ func TestLinux_Secret_exec(t *testing.T) { func TestLinux_Secret_pull(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -767,7 +759,6 @@ func TestLinux_Secret_pull(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(testSteps(constants.DriverDocker)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -795,7 +786,6 @@ func TestLinux_Secret_pull(t *testing.T) { func TestLinux_Secret_stream(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _steps := testSteps(constants.DriverDocker) gin.SetMode(gin.TestMode) @@ -893,7 +883,6 @@ func TestLinux_Secret_stream(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_steps), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) diff --git a/executor/linux/service.go b/executor/linux/service.go index 7ba82466..504a9fda 100644 --- a/executor/linux/service.go +++ b/executor/linux/service.go @@ -34,7 +34,7 @@ func (c *client) CreateService(ctx context.Context, ctn *pipeline.Container) err // update the service container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Environment - err = service.Environment(ctn, c.build, c.repo, nil, c.Version) + err = service.Environment(ctn, c.build, nil, c.Version) if err != nil { return err } @@ -89,7 +89,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error // send API call to update the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SvcService.Update - _service, _, err = c.Vela.Svc.Update(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _service) + _service, _, err = c.Vela.Svc.Update(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _service) if err != nil { return err } @@ -97,7 +97,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error // update the service container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Environment - err = service.Environment(ctn, c.build, c.repo, _service, c.Version) + err = service.Environment(ctn, c.build, _service, c.Version) if err != nil { return err } @@ -110,7 +110,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error // send API call to capture the service log // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.GetService - _log, _, err := c.Vela.Log.GetService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _service.GetNumber()) + _log, _, err := c.Vela.Log.GetService(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _service.GetNumber()) if err != nil { return err } @@ -139,7 +139,7 @@ func (c *client) ExecService(ctx context.Context, ctn *pipeline.Container) error // defer taking a snapshot of the service // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Snapshot - defer func() { service.Snapshot(ctn, c.build, c.Vela, c.Logger, c.repo, _service) }() + defer func() { service.Snapshot(ctn, c.build, c.Vela, c.Logger, _service) }() logger.Debug("running container") // run the runtime container @@ -207,7 +207,7 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err // send API call to update the logs for the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateService - _, err = c.Vela.Log.UpdateService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log) + _, err = c.Vela.Log.UpdateService(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), ctn.Number, _log) if err != nil { logger.Errorf("unable to upload container logs: %v", err) } @@ -241,8 +241,8 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err // after repo timeout of idle (no response) end the stream // // this is a safety mechanism - case <-time.After(time.Duration(c.repo.GetTimeout()) * time.Minute): - logger.Tracef("repo timeout of %d exceeded", c.repo.GetTimeout()) + case <-time.After(time.Duration(c.build.GetRepo().GetTimeout()) * time.Minute): + logger.Tracef("repo timeout of %d exceeded", c.build.GetRepo().GetTimeout()) return // channel is closed @@ -266,7 +266,7 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err // send API call to append the logs for the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateService - _, err = c.Vela.Log.UpdateService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log) + _, err = c.Vela.Log.UpdateService(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), ctn.Number, _log) if err != nil { logger.Error(err) } @@ -323,7 +323,7 @@ func (c *client) DestroyService(ctx context.Context, ctn *pipeline.Container) er // defer an upload of the service // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#LoaUploadd - defer func() { service.Upload(ctn, c.build, c.Vela, logger, c.repo, _service) }() + defer func() { service.Upload(ctn, c.build, c.Vela, logger, _service) }() logger.Debug("inspecting container") // inspect the runtime container diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index b3df9bc7..6787c391 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -22,7 +22,6 @@ import ( func TestLinux_CreateService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -134,7 +133,6 @@ func TestLinux_CreateService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -162,7 +160,6 @@ func TestLinux_CreateService(t *testing.T) { func TestLinux_PlanService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -274,7 +271,6 @@ func TestLinux_PlanService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -302,7 +298,6 @@ func TestLinux_PlanService(t *testing.T) { func TestLinux_ExecService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -417,7 +412,6 @@ func TestLinux_ExecService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -451,7 +445,6 @@ func TestLinux_ExecService(t *testing.T) { func TestLinux_StreamService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -563,7 +556,6 @@ func TestLinux_StreamService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -596,7 +588,6 @@ func TestLinux_StreamService(t *testing.T) { func TestLinux_DestroyService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -696,7 +687,6 @@ func TestLinux_DestroyService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) diff --git a/executor/linux/stage.go b/executor/linux/stage.go index 550d7f86..044c5c2d 100644 --- a/executor/linux/stage.go +++ b/executor/linux/stage.go @@ -140,7 +140,7 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map) // 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, c.repo) + skip, err := step.Skip(_step, c.build) if err != nil { return fmt.Errorf("unable to plan step: %w", c.err) } diff --git a/executor/linux/stage_test.go b/executor/linux/stage_test.go index 9b2e0717..ce418d83 100644 --- a/executor/linux/stage_test.go +++ b/executor/linux/stage_test.go @@ -27,7 +27,6 @@ func TestLinux_CreateStage(t *testing.T) { // setup types _file := "testdata/build/stages/basic.yml" _build := testBuild() - _repo := testRepo() set := flag.NewFlagSet("test", 0) set.String("clone-image", "target/vela-git:latest", "doc") @@ -36,8 +35,8 @@ func TestLinux_CreateStage(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). - WithUser(_repo.GetOwner()). + WithRepo(_build.GetRepo()). + WithUser(_build.GetRepo().GetOwner()). Compile(_file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", _file, err) @@ -165,7 +164,6 @@ func TestLinux_CreateStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -201,7 +199,6 @@ func TestLinux_CreateStage(t *testing.T) { func TestLinux_PlanStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -390,7 +387,6 @@ func TestLinux_PlanStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -418,7 +414,6 @@ func TestLinux_PlanStage(t *testing.T) { func TestLinux_ExecStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -579,7 +574,6 @@ func TestLinux_ExecStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -608,7 +602,6 @@ func TestLinux_ExecStage(t *testing.T) { func TestLinux_DestroyStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -682,7 +675,6 @@ func TestLinux_DestroyStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) diff --git a/executor/linux/step.go b/executor/linux/step.go index a2727849..99020c8d 100644 --- a/executor/linux/step.go +++ b/executor/linux/step.go @@ -39,12 +39,12 @@ func (c *client) CreateStep(ctx context.Context, ctn *pipeline.Container) error // create a library step object to facilitate injecting environment as early as possible // (PlanStep is too late to inject environment vars for the kubernetes runtime). - _step := library.StepFromBuildContainer(c.build, ctn) + _step := library.StepFromBuildContainer(c.build.ToLibrary(), ctn) // update the step container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Environment - err = step.Environment(ctn, c.build, c.repo, _step, c.Version) + err = step.Environment(ctn, c.build, _step, c.Version) if err != nil { return err } @@ -85,7 +85,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { logger := c.Logger.WithField("step", ctn.Name) // create the library step object - _step := library.StepFromBuildContainer(c.build, ctn) + _step := library.StepFromBuildContainer(c.build.ToLibrary(), ctn) _step.SetStatus(constants.StatusRunning) _step.SetStarted(time.Now().UTC().Unix()) @@ -93,7 +93,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { // send API call to update the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _step, _, err = c.Vela.Step.Update(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step) + _step, _, err = c.Vela.Step.Update(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _step) if err != nil { return err } @@ -101,7 +101,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { // update the step container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Environment - err = step.Environment(ctn, c.build, c.repo, _step, c.Version) + err = step.Environment(ctn, c.build, _step, c.Version) if err != nil { return err } @@ -114,7 +114,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { // send API call to capture the step log // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.GetStep - _log, _, err := c.Vela.Log.GetStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step.GetNumber()) + _log, _, err := c.Vela.Log.GetStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), _step.GetNumber()) if err != nil { return err } @@ -148,7 +148,7 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // defer taking a snapshot of the step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Snapshot - defer func() { step.Snapshot(ctn, c.build, c.Vela, c.Logger, c.repo, _step) }() + defer func() { step.Snapshot(ctn, c.build, c.Vela, c.Logger, _step) }() logger.Debug("running container") // run the runtime container @@ -253,7 +253,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error // send API call to update the logs for the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateStep - _, err = c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log) + _, err = c.Vela.Log.UpdateStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), ctn.Number, _log) if err != nil { logger.Errorf("unable to upload container logs: %v", err) } @@ -287,8 +287,8 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error // after repo timeout of idle (no response) end the stream // // this is a safety mechanism - case <-time.After(time.Duration(c.repo.GetTimeout()) * time.Minute): - logger.Tracef("repo timeout of %d exceeded", c.repo.GetTimeout()) + case <-time.After(time.Duration(c.build.GetRepo().GetTimeout()) * time.Minute): + logger.Tracef("repo timeout of %d exceeded", c.build.GetRepo().GetTimeout()) return // channel is closed @@ -316,7 +316,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error // send API call to append the logs for the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogStep.UpdateStep - _, err := c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log) + _, err := c.Vela.Log.UpdateStep(c.build.GetRepo().GetOrg(), c.build.GetRepo().GetName(), c.build.GetNumber(), ctn.Number, _log) if err != nil { logger.Error(err) } @@ -378,7 +378,7 @@ func (c *client) DestroyStep(ctx context.Context, ctn *pipeline.Container) error // defer an upload of the step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Upload - defer func() { step.Upload(ctn, c.build, c.Vela, logger, c.repo, _step) }() + defer func() { step.Upload(ctn, c.build, c.Vela, logger, _step) }() logger.Debug("inspecting container") // inspect the runtime container diff --git a/executor/linux/step_test.go b/executor/linux/step_test.go index 51a55af0..96c936e6 100644 --- a/executor/linux/step_test.go +++ b/executor/linux/step_test.go @@ -24,7 +24,6 @@ import ( func TestLinux_CreateStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -156,7 +155,6 @@ func TestLinux_CreateStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -184,7 +182,6 @@ func TestLinux_CreateStep(t *testing.T) { func TestLinux_PlanStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -288,7 +285,6 @@ func TestLinux_PlanStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -316,7 +312,6 @@ func TestLinux_PlanStep(t *testing.T) { func TestLinux_ExecStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -483,7 +478,6 @@ func TestLinux_ExecStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), withStreamRequests(streamRequests), @@ -517,7 +511,6 @@ func TestLinux_ExecStep(t *testing.T) { func TestLinux_StreamStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _logs := new(library.Log) // fill log with bytes @@ -663,7 +656,6 @@ func TestLinux_StreamStep(t *testing.T) { WithBuild(_build), WithPipeline(new(pipeline.Build)), WithMaxLogSize(10), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) @@ -696,7 +688,6 @@ func TestLinux_StreamStep(t *testing.T) { func TestLinux_DestroyStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() gin.SetMode(gin.TestMode) @@ -816,7 +807,6 @@ func TestLinux_DestroyStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(test.runtime), WithVelaClient(_client), ) diff --git a/executor/local/api.go b/executor/local/api.go index 6312f711..b95743ee 100644 --- a/executor/local/api.go +++ b/executor/local/api.go @@ -16,7 +16,7 @@ import ( ) // GetBuild gets the current build in execution. -func (c *client) GetBuild() (*library.Build, error) { +func (c *client) GetBuild() (*api.Build, error) { // check if the build resource is available if c.build == nil { return nil, fmt.Errorf("build resource not found") @@ -35,20 +35,10 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { return c.pipeline, nil } -// GetRepo gets the current repo in execution. -func (c *client) GetRepo() (*api.Repo, error) { - // check if the repo resource is available - if c.repo == nil { - return nil, fmt.Errorf("repo resource not found") - } - - return c.repo, nil -} - // CancelBuild cancels the current build in execution. // //nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized -func (c *client) CancelBuild() (*library.Build, error) { +func (c *client) CancelBuild() (*api.Build, error) { // get the current build from the client b, err := c.GetBuild() if err != nil { diff --git a/executor/local/api_test.go b/executor/local/api_test.go index 6fc5ea52..e37b0c71 100644 --- a/executor/local/api_test.go +++ b/executor/local/api_test.go @@ -112,56 +112,3 @@ func TestLocal_GetPipeline(t *testing.T) { }) } } - -func TestLocal_GetRepo(t *testing.T) { - // setup types - _repo := testRepo() - - _engine, err := New( - WithRepo(_repo), - ) - if err != nil { - t.Errorf("unable to create executor engine: %v", err) - } - - // setup tests - tests := []struct { - name string - failure bool - engine *client - }{ - { - name: "with repo", - failure: false, - engine: _engine, - }, - { - name: "missing repo", - failure: true, - engine: new(client), - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got, err := test.engine.GetRepo() - - if test.failure { - if err == nil { - t.Errorf("GetRepo should have returned err") - } - - return // continue to next test - } - - if err != nil { - t.Errorf("GetRepo returned err: %v", err) - } - - if !reflect.DeepEqual(got, _repo) { - t.Errorf("GetRepo is %v, want %v", got, _repo) - } - }) - } -} diff --git a/executor/local/build.go b/executor/local/build.go index dba1340c..9eb13db2 100644 --- a/executor/local/build.go +++ b/executor/local/build.go @@ -21,7 +21,7 @@ func (c *client) CreateBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, nil, c.err, nil, nil) }() + defer func() { build.Snapshot(c.build, nil, c.err, nil) }() // update the build fields c.build.SetStatus(constants.StatusRunning) @@ -64,7 +64,7 @@ func (c *client) PlanBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, nil, c.err, nil, nil) }() + defer func() { build.Snapshot(c.build, nil, c.err, nil) }() // load the init step from the client // @@ -77,7 +77,7 @@ func (c *client) PlanBuild(ctx context.Context) error { // defer taking a snapshot of the init step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#SnapshotInit - defer func() { step.SnapshotInit(c.init, c.build, nil, nil, nil, _init, nil) }() + defer func() { step.SnapshotInit(c.init, c.build, nil, nil, _init, nil) }() // create a step pattern for log output _pattern := fmt.Sprintf(stepPattern, c.init.Name) @@ -135,7 +135,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // defer taking a snapshot of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Snapshot - defer func() { build.Snapshot(c.build, nil, c.err, nil, nil) }() + defer func() { build.Snapshot(c.build, nil, c.err, nil) }() // load the init step from the client // @@ -148,7 +148,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // defer an upload of the init step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Upload - defer func() { step.Upload(c.init, c.build, nil, nil, nil, _init) }() + defer func() { step.Upload(c.init, c.build, nil, nil, _init) }() // create a step pattern for log output _pattern := fmt.Sprintf(stepPattern, c.init.Name) @@ -247,7 +247,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // defer an upload of the build // // https://pkg.go.dev/github.com/go-vela/worker/internal/build#Upload - defer func() { build.Upload(c.build, nil, c.err, nil, nil) }() + defer func() { build.Upload(c.build, nil, c.err, nil) }() // execute the services for the pipeline for _, _service := range c.pipeline.Services { @@ -274,7 +274,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, c.repo) + skip, err := step.Skip(_step, c.build) if err != nil { return fmt.Errorf("unable to plan step: %w", c.err) } diff --git a/executor/local/build_test.go b/executor/local/build_test.go index 64d62778..ac4141e4 100644 --- a/executor/local/build_test.go +++ b/executor/local/build_test.go @@ -21,7 +21,6 @@ func TestLocal_CreateBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -56,9 +55,9 @@ func TestLocal_CreateBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -67,7 +66,6 @@ func TestLocal_CreateBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -96,7 +94,6 @@ func TestLocal_PlanBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -131,9 +128,9 @@ func TestLocal_PlanBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -142,7 +139,6 @@ func TestLocal_PlanBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -177,7 +173,6 @@ func TestLocal_AssembleBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -245,9 +240,9 @@ func TestLocal_AssembleBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -256,7 +251,6 @@ func TestLocal_AssembleBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -292,7 +286,6 @@ func TestLocal_ExecBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -345,9 +338,9 @@ func TestLocal_ExecBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -356,7 +349,6 @@ func TestLocal_ExecBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -392,7 +384,6 @@ func TestLocal_StreamBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -537,9 +528,9 @@ func TestLocal_StreamBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -548,7 +539,6 @@ func TestLocal_StreamBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -604,7 +594,6 @@ func TestLocal_DestroyBuild(t *testing.T) { compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -654,9 +643,9 @@ func TestLocal_DestroyBuild(t *testing.T) { _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -665,7 +654,6 @@ func TestLocal_DestroyBuild(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { diff --git a/executor/local/local.go b/executor/local/local.go index 930f1ebd..64bab8c5 100644 --- a/executor/local/local.go +++ b/executor/local/local.go @@ -9,7 +9,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -25,9 +24,8 @@ type ( // private fields init *pipeline.Container - build *library.Build + build *api.Build pipeline *pipeline.Build - repo *api.Repo services sync.Map steps sync.Map err error @@ -64,7 +62,6 @@ func Equal(a, b *client) bool { reflect.DeepEqual(a.init, b.init) && reflect.DeepEqual(a.build, b.build) && reflect.DeepEqual(a.pipeline, b.pipeline) && - reflect.DeepEqual(a.repo, b.repo) && reflect.DeepEqual(&a.services, &b.services) && reflect.DeepEqual(&a.steps, &b.steps) && reflect.DeepEqual(a.err, b.err) diff --git a/executor/local/local_test.go b/executor/local/local_test.go index a1f447da..25c50c4c 100644 --- a/executor/local/local_test.go +++ b/executor/local/local_test.go @@ -11,7 +11,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/runtime/docker" ) @@ -36,7 +35,6 @@ func TestEqual(t *testing.T) { WithBuild(testBuild()), WithHostname("localhost"), WithPipeline(testSteps()), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -48,7 +46,6 @@ func TestEqual(t *testing.T) { WithBuild(testBuild()), WithHostname("a.different.host"), WithPipeline(testSteps()), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -143,7 +140,6 @@ func TestLocal_New(t *testing.T) { WithBuild(testBuild()), WithHostname("localhost"), WithPipeline(test.pipeline), - WithRepo(testRepo()), WithRuntime(_runtime), WithVelaClient(_client), ) @@ -165,10 +161,11 @@ func TestLocal_New(t *testing.T) { // testBuild is a test helper function to create a Build // type with all fields set to a fake value. -func testBuild() *library.Build { - return &library.Build{ +func testBuild() *api.Build { + return &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: testRepo(), Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -216,12 +213,11 @@ func testRepo() *api.Repo { // testUser is a test helper function to create a User // type with all fields set to a fake value. -func testUser() *library.User { - return &library.User{ +func testUser() *api.User { + return &api.User{ ID: vela.Int64(1), Name: vela.String("octocat"), Token: vela.String("superSecretToken"), - Hash: vela.String("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy"), Favorites: vela.Strings([]string{"github/octocat"}), Active: vela.Bool(true), Admin: vela.Bool(false), diff --git a/executor/local/opts.go b/executor/local/opts.go index a265630c..60d40096 100644 --- a/executor/local/opts.go +++ b/executor/local/opts.go @@ -8,7 +8,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -17,8 +16,8 @@ import ( // Opt represents a configuration option to initialize the executor client for Local. type Opt func(*client) error -// WithBuild sets the library build in the executor client for Local. -func WithBuild(b *library.Build) Opt { +// WithBuild sets the API build in the executor client for Local. +func WithBuild(b *api.Build) Opt { return func(c *client) error { // set the build in the client c.build = b @@ -58,16 +57,6 @@ func WithPipeline(p *pipeline.Build) Opt { } } -// WithRepo sets the library repo in the executor client for Local. -func WithRepo(r *api.Repo) Opt { - return func(c *client) error { - // set the repo in the client - c.repo = r - - return nil - } -} - // WithRuntime sets the runtime engine in the executor client for Local. func WithRuntime(r runtime.Engine) Opt { return func(c *client) error { diff --git a/executor/local/opts_test.go b/executor/local/opts_test.go index 1082651c..c063c4fb 100644 --- a/executor/local/opts_test.go +++ b/executor/local/opts_test.go @@ -12,7 +12,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/runtime" "github.com/go-vela/worker/runtime/docker" @@ -25,7 +24,7 @@ func TestLocal_Opt_WithBuild(t *testing.T) { // setup tests tests := []struct { name string - build *library.Build + build *api.Build }{ { name: "build", @@ -135,39 +134,6 @@ func TestLocal_Opt_WithPipeline(t *testing.T) { } } -func TestLocal_Opt_WithRepo(t *testing.T) { - // setup types - _repo := testRepo() - - // setup tests - tests := []struct { - name string - repo *api.Repo - }{ - { - name: "repo", - repo: _repo, - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - _engine, err := New( - WithRepo(test.repo), - ) - - if err != nil { - t.Errorf("WithRepo returned err: %v", err) - } - - if !reflect.DeepEqual(_engine.repo, _repo) { - t.Errorf("WithRepo is %v, want %v", _engine.repo, _repo) - } - }) - } -} - func TestLocal_Opt_WithRuntime(t *testing.T) { // setup types _runtime, err := docker.NewMock() diff --git a/executor/local/service.go b/executor/local/service.go index 2cd2f9a8..a222f7e0 100644 --- a/executor/local/service.go +++ b/executor/local/service.go @@ -29,7 +29,7 @@ func (c *client) CreateService(ctx context.Context, ctn *pipeline.Container) err // update the service container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Environment - err = service.Environment(ctn, c.build, c.repo, nil, c.Version) + err = service.Environment(ctn, c.build, nil, c.Version) if err != nil { return err } @@ -61,7 +61,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error // update the service container environment // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Environment - err := service.Environment(ctn, c.build, c.repo, _service, c.Version) + err := service.Environment(ctn, c.build, _service, c.Version) if err != nil { return err } @@ -85,7 +85,7 @@ func (c *client) ExecService(ctx context.Context, ctn *pipeline.Container) error // defer taking a snapshot of the service // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Snapshot - defer func() { service.Snapshot(ctn, c.build, nil, nil, nil, _service) }() + defer func() { service.Snapshot(ctn, c.build, nil, nil, _service) }() // run the runtime container err = c.Runtime.RunContainer(ctx, ctn, c.pipeline) @@ -143,7 +143,7 @@ func (c *client) DestroyService(ctx context.Context, ctn *pipeline.Container) er // defer an upload of the service // // https://pkg.go.dev/github.com/go-vela/worker/internal/service#Upload - defer func() { service.Upload(ctn, c.build, nil, nil, nil, _service) }() + defer func() { service.Upload(ctn, c.build, nil, nil, _service) }() // inspect the runtime container err = c.Runtime.InspectContainer(ctx, ctn) diff --git a/executor/local/service_test.go b/executor/local/service_test.go index ad766c51..40e8e319 100644 --- a/executor/local/service_test.go +++ b/executor/local/service_test.go @@ -15,7 +15,6 @@ import ( func TestLocal_CreateService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -71,7 +70,6 @@ func TestLocal_CreateService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -98,7 +96,6 @@ func TestLocal_CreateService(t *testing.T) { func TestLocal_PlanService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -139,7 +136,6 @@ func TestLocal_PlanService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -166,7 +162,6 @@ func TestLocal_PlanService(t *testing.T) { func TestLocal_ExecService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -225,7 +220,6 @@ func TestLocal_ExecService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -257,7 +251,6 @@ func TestLocal_ExecService(t *testing.T) { func TestLocal_StreamService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -298,7 +291,6 @@ func TestLocal_StreamService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -325,7 +317,6 @@ func TestLocal_StreamService(t *testing.T) { func TestLocal_DestroyService(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -361,7 +352,6 @@ func TestLocal_DestroyService(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { diff --git a/executor/local/stage.go b/executor/local/stage.go index be708732..c8edfdce 100644 --- a/executor/local/stage.go +++ b/executor/local/stage.go @@ -91,7 +91,7 @@ func (c *client) ExecStage(ctx context.Context, s *pipeline.Stage, m *sync.Map) // 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, c.repo) + skip, err := step.Skip(_step, c.build) if err != nil { return fmt.Errorf("unable to plan step: %w", c.err) } diff --git a/executor/local/stage_test.go b/executor/local/stage_test.go index 22cca31b..2de10202 100644 --- a/executor/local/stage_test.go +++ b/executor/local/stage_test.go @@ -21,16 +21,15 @@ func TestLocal_CreateStage(t *testing.T) { // setup types _file := "testdata/build/stages/basic.yml" _build := testBuild() - _repo := testRepo() compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) _pipeline, _, err := compiler. Duplicate(). WithBuild(_build). - WithRepo(_repo). + WithRepo(_build.GetRepo()). WithLocal(true). - WithUser(_repo.GetOwner()). + WithUser(_build.GetRepo().GetOwner()). Compile(_file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", _file, err) @@ -91,7 +90,6 @@ func TestLocal_CreateStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(_pipeline), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -124,7 +122,6 @@ func TestLocal_CreateStage(t *testing.T) { func TestLocal_PlanStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -219,7 +216,6 @@ func TestLocal_PlanStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -246,7 +242,6 @@ func TestLocal_PlanStage(t *testing.T) { func TestLocal_ExecStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -309,7 +304,6 @@ func TestLocal_ExecStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -337,7 +331,6 @@ func TestLocal_ExecStage(t *testing.T) { func TestLocal_DestroyStage(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -376,7 +369,6 @@ func TestLocal_DestroyStage(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { diff --git a/executor/local/step.go b/executor/local/step.go index 36f7e726..23ffb2ef 100644 --- a/executor/local/step.go +++ b/executor/local/step.go @@ -50,7 +50,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error { } // create the library step object - _step := library.StepFromBuildContainer(c.build, ctn) + _step := library.StepFromBuildContainer(c.build.ToLibrary(), ctn) _step.SetStatus(constants.StatusRunning) _step.SetStarted(time.Now().UTC().Unix()) @@ -78,7 +78,7 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // defer taking a snapshot of the step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Snapshot - defer func() { step.Snapshot(ctn, c.build, nil, nil, nil, _step) }() + defer func() { step.Snapshot(ctn, c.build, nil, nil, _step) }() // run the runtime container err = c.Runtime.RunContainer(ctx, ctn, c.pipeline) @@ -177,7 +177,7 @@ func (c *client) DestroyStep(ctx context.Context, ctn *pipeline.Container) error // defer an upload of the step // // https://pkg.go.dev/github.com/go-vela/worker/internal/step#Upload - defer func() { step.Upload(ctn, c.build, nil, nil, nil, _step) }() + defer func() { step.Upload(ctn, c.build, nil, nil, _step) }() // inspect the runtime container err = c.Runtime.InspectContainer(ctx, ctn) diff --git a/executor/local/step_test.go b/executor/local/step_test.go index 0dafd57c..6c215df5 100644 --- a/executor/local/step_test.go +++ b/executor/local/step_test.go @@ -15,7 +15,6 @@ import ( func TestLocal_CreateStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -80,7 +79,6 @@ func TestLocal_CreateStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -107,7 +105,6 @@ func TestLocal_CreateStep(t *testing.T) { func TestLocal_PlanStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -146,7 +143,6 @@ func TestLocal_PlanStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -173,7 +169,6 @@ func TestLocal_PlanStep(t *testing.T) { func TestLocal_ExecStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -255,7 +250,6 @@ func TestLocal_ExecStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), withStreamRequests(streamRequests), ) @@ -287,7 +281,6 @@ func TestLocal_ExecStep(t *testing.T) { func TestLocal_StreamStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -352,7 +345,6 @@ func TestLocal_StreamStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { @@ -379,7 +371,6 @@ func TestLocal_StreamStep(t *testing.T) { func TestLocal_DestroyStep(t *testing.T) { // setup types _build := testBuild() - _repo := testRepo() _runtime, err := docker.NewMock() if err != nil { @@ -426,7 +417,6 @@ func TestLocal_DestroyStep(t *testing.T) { _engine, err := New( WithBuild(_build), WithPipeline(new(pipeline.Build)), - WithRepo(_repo), WithRuntime(_runtime), ) if err != nil { diff --git a/executor/setup.go b/executor/setup.go index 85065914..873f9bd3 100644 --- a/executor/setup.go +++ b/executor/setup.go @@ -12,7 +12,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/executor/linux" "github.com/go-vela/worker/executor/local" @@ -54,11 +53,9 @@ type Setup struct { // Vela Resource Configuration // resource for storing build information in Vela - Build *library.Build + Build *api.Build // resource for storing pipeline information in Vela Pipeline *pipeline.Build - // resource for storing repo information in Vela - Repo *api.Repo } // Darwin creates and returns a Vela engine capable of @@ -85,7 +82,6 @@ func (s *Setup) Linux() (Engine, error) { linux.WithEnforceTrustedRepos(s.EnforceTrustedRepos), linux.WithHostname(s.Hostname), linux.WithPipeline(s.Pipeline), - linux.WithRepo(s.Repo), linux.WithRuntime(s.Runtime), linux.WithVelaClient(s.Client), linux.WithVersion(s.Version), @@ -105,7 +101,6 @@ func (s *Setup) Local() (Engine, error) { local.WithBuild(s.Build), local.WithHostname(s.Hostname), local.WithPipeline(s.Pipeline), - local.WithRepo(s.Repo), local.WithRuntime(s.Runtime), local.WithVelaClient(s.Client), local.WithVersion(s.Version), @@ -159,12 +154,12 @@ func (s *Setup) Validate() error { } // check if a Vela repo was provided - if s.Repo == nil { + if s.Build.Repo == nil { return fmt.Errorf("no Vela repo provided in setup") } // check if a Vela user was provided - if s.Repo.Owner == nil { + if s.Build.Repo.Owner == nil { return fmt.Errorf("no Vela user provided in setup") } diff --git a/executor/setup_test.go b/executor/setup_test.go index 638582c7..48193850 100644 --- a/executor/setup_test.go +++ b/executor/setup_test.go @@ -11,6 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" "github.com/go-vela/worker/executor/linux" @@ -39,7 +40,6 @@ func TestExecutor_Setup_Darwin(t *testing.T) { Client: _client, Driver: constants.DriverDarwin, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, } @@ -75,7 +75,6 @@ func TestExecutor_Setup_Linux(t *testing.T) { linux.WithLogStreamingTimeout(1*time.Second), linux.WithHostname("localhost"), linux.WithPipeline(_pipeline), - linux.WithRepo(_repo), linux.WithRuntime(_runtime), linux.WithVelaClient(_client), linux.WithVersion("v1.0.0"), @@ -91,7 +90,6 @@ func TestExecutor_Setup_Linux(t *testing.T) { MaxLogSize: 2097152, Hostname: "localhost", Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", } @@ -129,7 +127,6 @@ func TestExecutor_Setup_Local(t *testing.T) { local.WithBuild(_build), local.WithHostname("localhost"), local.WithPipeline(_pipeline), - local.WithRepo(_repo), local.WithRuntime(_runtime), local.WithVelaClient(_client), local.WithVersion("v1.0.0"), @@ -144,7 +141,6 @@ func TestExecutor_Setup_Local(t *testing.T) { Driver: "local", Hostname: "localhost", Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, Version: "v1.0.0", } @@ -183,7 +179,6 @@ func TestExecutor_Setup_Windows(t *testing.T) { Client: _client, Driver: constants.DriverWindows, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, } @@ -213,8 +208,10 @@ func TestExecutor_Setup_Validate(t *testing.T) { t.Errorf("unable to create runtime engine: %v", err) } - _emptyOwnerRepo := *_repo - _emptyOwnerRepo.Owner = nil + _emptyOwnerBuild := new(api.Build) + _emptyOwnerBuild.SetRepo(new(api.Repo)) + + _emptyRepoBuild := new(api.Build) // setup tests tests := []struct { @@ -230,7 +227,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, }, failure: false, @@ -243,7 +239,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, }, failure: true, @@ -256,7 +251,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, }, failure: true, @@ -269,7 +263,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: "", MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: _runtime, }, failure: true, @@ -282,7 +275,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: nil, - Repo: _repo, Runtime: _runtime, }, failure: true, @@ -290,12 +282,11 @@ func TestExecutor_Setup_Validate(t *testing.T) { { name: "nil repo", setup: &Setup{ - Build: _build, + Build: _emptyRepoBuild, Client: _client, Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: nil, Runtime: _runtime, }, failure: true, @@ -308,7 +299,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, Runtime: nil, }, failure: true, @@ -316,12 +306,11 @@ func TestExecutor_Setup_Validate(t *testing.T) { { name: "nil user", setup: &Setup{ - Build: _build, + Build: _emptyOwnerBuild, Client: _client, Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: &_emptyOwnerRepo, Runtime: _runtime, }, failure: true, diff --git a/go.mod b/go.mod index da69f4f1..e64df233 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,8 @@ require ( github.com/docker/docker v26.0.0+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.9.1 - github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625 - github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7 + github.com/go-vela/sdk-go v0.23.3-0.20240424150003-64f8eb0ebcc0 + github.com/go-vela/server v0.23.4-0.20240424144436-b55aa2bb3684 github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 diff --git a/go.sum b/go.sum index a04c251a..32e63673 100644 --- a/go.sum +++ b/go.sum @@ -100,10 +100,10 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625 h1:mVdVHlhXeSMNDOCLK8RFTfuw3m+kLsevdIK21/xRfu4= -github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625/go.mod h1:qByLq0AvL9yFLfn3xhtSiXTXSHkZVZyr7C91NHU8XnQ= -github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7 h1:G8h44XJ3+gaxiWBV2uAZ82abMXhWRkrNq9sNo2cOaZU= -github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7/go.mod h1:QV9JFv+LdpAgkRJhHE92dh4vVdh0kNv8OJnyOLt++84= +github.com/go-vela/sdk-go v0.23.3-0.20240424150003-64f8eb0ebcc0 h1:AYltea00KRHeIqVW0A1BDNH10Kb6Djfl69rCtztAqM0= +github.com/go-vela/sdk-go v0.23.3-0.20240424150003-64f8eb0ebcc0/go.mod h1:WB3MAFpnwvuvSGJLrGGbt6VO8aS1URiWa5kqjngO8mU= +github.com/go-vela/server v0.23.4-0.20240424144436-b55aa2bb3684 h1:O0gfupNx7aYPCCrXwVuisrbbqbVkvrRqRBAkSg1bIww= +github.com/go-vela/server v0.23.4-0.20240424144436-b55aa2bb3684/go.mod h1:QV9JFv+LdpAgkRJhHE92dh4vVdh0kNv8OJnyOLt++84= github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7 h1:3mN7ej69dMH3Vis3G/tPLzLL0Rfp8nR5qd0gpj5ejRM= github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= diff --git a/internal/build/snapshot.go b/internal/build/snapshot.go index 6d6678f0..e2864882 100644 --- a/internal/build/snapshot.go +++ b/internal/build/snapshot.go @@ -11,12 +11,11 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // Snapshot creates a moment in time record of the build // and attempts to upload it to the server. -func Snapshot(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api.Repo) { +func Snapshot(b *api.Build, c *vela.Client, e error, l *logrus.Entry) { // check if the build is not in a canceled status if !strings.EqualFold(b.GetStatus(), constants.StatusCanceled) { // check if the error provided is empty @@ -43,7 +42,7 @@ func Snapshot(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api // send API call to update the build // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#BuildService.Update - _, _, err := c.Build.Update(r.GetOrg(), r.GetName(), b) + _, _, err := c.Build.Update(b) if err != nil { l.Errorf("unable to upload build snapshot: %v", err) } diff --git a/internal/build/snapshot_test.go b/internal/build/snapshot_test.go index a736c100..3baafcba 100644 --- a/internal/build/snapshot_test.go +++ b/internal/build/snapshot_test.go @@ -13,13 +13,33 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types/library" ) func TestBuild_Snapshot(t *testing.T) { // setup types - b := &library.Build{ + r := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: &api.Events{ + Push: &actions.Push{ + Branch: vela.Bool(true), + }, + }, + } + + b := &api.Build{ ID: vela.Int64(1), + Repo: r, Number: vela.Int(1), Parent: vela.Int(1), Event: vela.String("push"), @@ -45,26 +65,6 @@ func TestBuild_Snapshot(t *testing.T) { Distribution: vela.String("linux"), } - r := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: &api.Events{ - Push: &actions.Push{ - Branch: vela.Bool(true), - }, - }, - } - gin.SetMode(gin.TestMode) s := httptest.NewServer(server.FakeHandler()) @@ -76,38 +76,34 @@ func TestBuild_Snapshot(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client err error - repo *api.Repo }{ { name: "build with error", build: b, client: _client, err: errors.New("unable to create network"), - repo: r, }, { name: "nil build with error", build: nil, client: _client, err: errors.New("unable to create network"), - repo: r, }, { name: "nil everything", build: nil, client: nil, err: nil, - repo: nil, }, } // run test for _, test := range tests { t.Run(test.name, func(_ *testing.T) { - Snapshot(test.build, test.client, test.err, nil, test.repo) + Snapshot(test.build, test.client, test.err, nil) }) } } diff --git a/internal/build/upload.go b/internal/build/upload.go index d6650c29..f3994e7d 100644 --- a/internal/build/upload.go +++ b/internal/build/upload.go @@ -11,12 +11,11 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // Upload tracks the final state of the build // and attempts to upload it to the server. -func Upload(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api.Repo) { +func Upload(b *api.Build, c *vela.Client, e error, l *logrus.Entry) { // handle the build based off the status provided switch b.GetStatus() { // build is in a canceled state @@ -71,7 +70,7 @@ func Upload(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api.R // send API call to update the build // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#BuildService.Update - _, _, err := c.Build.Update(r.GetOrg(), r.GetName(), b) + _, _, err := c.Build.Update(b) if err != nil { l.Errorf("unable to upload final build state: %v", err) } diff --git a/internal/build/upload_test.go b/internal/build/upload_test.go index 6a210520..89485e62 100644 --- a/internal/build/upload_test.go +++ b/internal/build/upload_test.go @@ -13,14 +13,34 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types/library" ) func TestBuild_Upload(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: &api.Events{ + Push: &actions.Push{ + Branch: vela.Bool(true), + }, + }, + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -54,26 +74,6 @@ func TestBuild_Upload(t *testing.T) { _pending := *_build _pending.SetStatus("pending") - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: &api.Events{ - Push: &actions.Push{ - Branch: vela.Bool(true), - }, - }, - } - gin.SetMode(gin.TestMode) s := httptest.NewServer(server.FakeHandler()) @@ -85,59 +85,52 @@ func TestBuild_Upload(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client err error - repo *api.Repo }{ { name: "build with error", build: _build, client: _client, err: errors.New("unable to create network"), - repo: _repo, }, { name: "canceled build with error", build: &_canceled, client: _client, err: errors.New("unable to create network"), - repo: _repo, }, { name: "errored build with error", build: &_error, client: _client, err: errors.New("unable to create network"), - repo: _repo, }, { name: "pending build with error", build: &_pending, client: _client, err: errors.New("unable to create network"), - repo: _repo, }, { name: "nil build with error", build: nil, client: _client, err: errors.New("unable to create network"), - repo: _repo, }, { name: "everything nil", build: nil, client: nil, err: nil, - repo: nil, }, } // run test for _, test := range tests { t.Run(test.name, func(_ *testing.T) { - Upload(test.build, test.client, test.err, nil, test.repo) + Upload(test.build, test.client, test.err, nil) }) } } diff --git a/internal/service/environment.go b/internal/service/environment.go index 189279f9..4b7d92a5 100644 --- a/internal/service/environment.go +++ b/internal/service/environment.go @@ -13,7 +13,7 @@ import ( // Environment attempts to update the environment variables // for the container based off the library resources. -func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *library.Service, version string) error { +func Environment(c *pipeline.Container, b *api.Build, s *library.Service, version string) error { // check if container or container environment are empty if c == nil || c.Environment == nil { return fmt.Errorf("empty container provided for environment") @@ -52,17 +52,12 @@ func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *librar } } - // check if the repo provided is empty - if r != nil { - // populate environment variables from repo library - // - // https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.MergeEnv - // -> - // https://pkg.go.dev/github.com/go-vela/types/library#Repo.Environment - err := c.MergeEnv(r.Environment()) - if err != nil { - return err - } + // populate environment variables from repo library + // + // https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.MergeEnv + err := c.MergeEnv(b.GetRepo().Environment()) + if err != nil { + return err } // check if the service provided is empty diff --git a/internal/service/environment_test.go b/internal/service/environment_test.go index bac7bbe7..d5581ae3 100644 --- a/internal/service/environment_test.go +++ b/internal/service/environment_test.go @@ -13,9 +13,24 @@ import ( func TestService_Environment(t *testing.T) { // setup types - b := new(library.Build) + r := new(api.Repo) + r.SetID(1) + r.SetOrg("github") + r.SetName("octocat") + r.SetFullName("github/octocat") + r.SetLink("https://github.com/github/octocat") + r.SetClone("https://github.com/github/octocat.git") + r.SetBranch("main") + r.SetTimeout(30) + r.SetVisibility("public") + r.SetPrivate(false) + r.SetTrusted(false) + r.SetActive(true) + r.SetAllowEvents(api.NewEventsFromMask(1)) + + b := new(api.Build) b.SetID(1) - b.SetRepoID(1) + b.SetRepo(r) b.SetNumber(1) b.SetParent(1) b.SetEvent("push") @@ -55,21 +70,6 @@ func TestService_Environment(t *testing.T) { Pull: "not_present", } - r := new(api.Repo) - r.SetID(1) - r.SetOrg("github") - r.SetName("octocat") - r.SetFullName("github/octocat") - r.SetLink("https://github.com/github/octocat") - r.SetClone("https://github.com/github/octocat.git") - r.SetBranch("main") - r.SetTimeout(30) - r.SetVisibility("public") - r.SetPrivate(false) - r.SetTrusted(false) - r.SetActive(true) - r.SetAllowEvents(api.NewEventsFromMask(1)) - s := new(library.Service) s.SetID(1) s.SetBuildID(1) @@ -90,9 +90,8 @@ func TestService_Environment(t *testing.T) { tests := []struct { name string failure bool - build *library.Build + build *api.Build container *pipeline.Container - repo *api.Repo service *library.Service }{ { @@ -100,7 +99,6 @@ func TestService_Environment(t *testing.T) { failure: false, build: b, container: c, - repo: r, service: s, }, { @@ -108,7 +106,6 @@ func TestService_Environment(t *testing.T) { failure: true, build: nil, container: nil, - repo: nil, service: nil, }, } @@ -116,7 +113,7 @@ func TestService_Environment(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err := Environment(test.container, test.build, test.repo, test.service, "v0.0.0") + err := Environment(test.container, test.build, test.service, "v0.0.0") if test.failure { if err == nil { diff --git a/internal/service/snapshot.go b/internal/service/snapshot.go index 499c4d86..f1e04232 100644 --- a/internal/service/snapshot.go +++ b/internal/service/snapshot.go @@ -17,7 +17,7 @@ import ( // Snapshot creates a moment in time record of the // service and attempts to upload it to the server. -func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Service) { +func Snapshot(ctn *pipeline.Container, b *api.Build, c *vela.Client, l *logrus.Entry, s *library.Service) { // check if the build is not in a canceled status if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) { // check if the container is running in headless mode @@ -56,7 +56,7 @@ func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logr // send API call to update the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SvcService.Update - _, _, err := c.Svc.Update(r.GetOrg(), r.GetName(), b.GetNumber(), s) + _, _, err := c.Svc.Update(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s) if err != nil { l.Errorf("unable to upload service snapshot: %v", err) } diff --git a/internal/service/snapshot_test.go b/internal/service/snapshot_test.go index 0eb81fed..f3f03eca 100644 --- a/internal/service/snapshot_test.go +++ b/internal/service/snapshot_test.go @@ -17,9 +17,26 @@ import ( func TestService_Snapshot(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -67,22 +84,6 @@ func TestService_Snapshot(t *testing.T) { Pull: "not_present", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - _service := &library.Service{ ID: vela.Int64(1), BuildID: vela.Int64(1), @@ -111,10 +112,9 @@ func TestService_Snapshot(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client container *pipeline.Container - repo *api.Repo service *library.Service }{ { @@ -122,7 +122,6 @@ func TestService_Snapshot(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, service: _service, }, { @@ -130,7 +129,6 @@ func TestService_Snapshot(t *testing.T) { build: _build, client: _client, container: _exitCode, - repo: _repo, service: nil, }, } @@ -138,7 +136,7 @@ func TestService_Snapshot(t *testing.T) { // run test for _, test := range tests { t.Run(test.name, func(t *testing.T) { - Snapshot(test.container, test.build, test.client, nil, test.repo, test.service) + Snapshot(test.container, test.build, test.client, nil, test.service) }) } } diff --git a/internal/service/upload.go b/internal/service/upload.go index 94e4df49..45fe5b22 100644 --- a/internal/service/upload.go +++ b/internal/service/upload.go @@ -16,7 +16,7 @@ import ( // Upload tracks the final state of the service // and attempts to upload it to the server. -func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Service) { +func Upload(ctn *pipeline.Container, b *api.Build, c *vela.Client, l *logrus.Entry, s *library.Service) { // handle the service based off the status provided switch s.GetStatus() { // service is in a canceled state @@ -81,7 +81,7 @@ func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus // send API call to update the service // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#SvcService.Update - _, _, err := c.Svc.Update(r.GetOrg(), r.GetName(), b.GetNumber(), s) + _, _, err := c.Svc.Update(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s) if err != nil { l.Errorf("unable to upload service snapshot: %v", err) } diff --git a/internal/service/upload_test.go b/internal/service/upload_test.go index eb82eb70..313c9f8d 100644 --- a/internal/service/upload_test.go +++ b/internal/service/upload_test.go @@ -17,9 +17,26 @@ import ( func TestService_Upload(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -65,22 +82,6 @@ func TestService_Upload(t *testing.T) { Pull: "always", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - _service := &library.Service{ ID: vela.Int64(1), BuildID: vela.Int64(1), @@ -118,10 +119,9 @@ func TestService_Upload(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client container *pipeline.Container - repo *api.Repo service *library.Service }{ { @@ -129,7 +129,6 @@ func TestService_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, service: _service, }, { @@ -137,7 +136,6 @@ func TestService_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, service: &_canceled, }, { @@ -145,7 +143,6 @@ func TestService_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, service: &_error, }, { @@ -153,7 +150,6 @@ func TestService_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, service: &_pending, }, { @@ -161,7 +157,6 @@ func TestService_Upload(t *testing.T) { build: _build, client: _client, container: _exitCode, - repo: _repo, service: nil, }, } @@ -169,7 +164,7 @@ func TestService_Upload(t *testing.T) { // run test for _, test := range tests { t.Run(test.name, func(t *testing.T) { - Upload(test.container, test.build, test.client, nil, test.repo, test.service) + Upload(test.container, test.build, test.client, nil, test.service) }) } } diff --git a/internal/step/environment.go b/internal/step/environment.go index 72a391b8..bfa3c756 100644 --- a/internal/step/environment.go +++ b/internal/step/environment.go @@ -13,7 +13,7 @@ import ( // Environment attempts to update the environment variables // for the container based off the library resources. -func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *library.Step, version string) error { +func Environment(c *pipeline.Container, b *api.Build, s *library.Step, version string) error { // check if container or container environment are empty if c == nil || c.Environment == nil { return fmt.Errorf("empty container provided for environment") @@ -52,17 +52,12 @@ func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *librar } } - // check if the repo provided is empty - if r != nil { - // populate environment variables from build library - // - // https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.MergeEnv - // -> - // https://pkg.go.dev/github.com/go-vela/types/library#Repo.Environment - err := c.MergeEnv(r.Environment()) - if err != nil { - return err - } + // populate environment variables from build library + // + // https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.MergeEnv + err := c.MergeEnv(b.GetRepo().Environment()) + if err != nil { + return err } // check if the step provided is empty diff --git a/internal/step/environment_test.go b/internal/step/environment_test.go index 77c029fe..21c274f4 100644 --- a/internal/step/environment_test.go +++ b/internal/step/environment_test.go @@ -13,9 +13,24 @@ import ( func TestStep_Environment(t *testing.T) { // setup types - b := new(library.Build) + r := new(api.Repo) + r.SetID(1) + r.SetOrg("github") + r.SetName("octocat") + r.SetFullName("github/octocat") + r.SetLink("https://github.com/github/octocat") + r.SetClone("https://github.com/github/octocat.git") + r.SetBranch("main") + r.SetTimeout(30) + r.SetVisibility("public") + r.SetPrivate(false) + r.SetTrusted(false) + r.SetActive(true) + r.SetAllowEvents(api.NewEventsFromMask(1)) + + b := new(api.Build) b.SetID(1) - b.SetRepoID(1) + b.SetRepo(r) b.SetNumber(1) b.SetParent(1) b.SetEvent("push") @@ -54,21 +69,6 @@ func TestStep_Environment(t *testing.T) { Pull: "always", } - r := new(api.Repo) - r.SetID(1) - r.SetOrg("github") - r.SetName("octocat") - r.SetFullName("github/octocat") - r.SetLink("https://github.com/github/octocat") - r.SetClone("https://github.com/github/octocat.git") - r.SetBranch("main") - r.SetTimeout(30) - r.SetVisibility("public") - r.SetPrivate(false) - r.SetTrusted(false) - r.SetActive(true) - r.SetAllowEvents(api.NewEventsFromMask(1)) - s := new(library.Step) s.SetID(1) s.SetBuildID(1) @@ -89,9 +89,8 @@ func TestStep_Environment(t *testing.T) { tests := []struct { name string failure bool - build *library.Build + build *api.Build container *pipeline.Container - repo *api.Repo step *library.Step }{ { @@ -99,7 +98,6 @@ func TestStep_Environment(t *testing.T) { failure: false, build: b, container: c, - repo: r, step: s, }, { @@ -107,7 +105,6 @@ func TestStep_Environment(t *testing.T) { failure: true, build: nil, container: nil, - repo: nil, step: nil, }, } @@ -115,7 +112,7 @@ func TestStep_Environment(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err := Environment(test.container, test.build, test.repo, test.step, "v0.0.0") + err := Environment(test.container, test.build, test.step, "v0.0.0") if test.failure { if err == nil { diff --git a/internal/step/skip.go b/internal/step/skip.go index 71bfd207..3d122e70 100644 --- a/internal/step/skip.go +++ b/internal/step/skip.go @@ -7,14 +7,13 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" ) // 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 *library.Build, r *api.Repo) (bool, error) { +func Skip(c *pipeline.Container, b *api.Build) (bool, error) { // check if the container provided is empty if c == nil { return true, nil @@ -34,7 +33,7 @@ func Skip(c *pipeline.Container, b *library.Build, r *api.Repo) (bool, error) { ruledata := &pipeline.RuleData{ Branch: b.GetBranch(), Event: event, - Repo: r.GetFullName(), + Repo: b.GetRepo().GetFullName(), Status: b.GetStatus(), Parallel: c.Ruleset.If.Parallel, } diff --git a/internal/step/skip_test.go b/internal/step/skip_test.go index 1b314709..e4677d7d 100644 --- a/internal/step/skip_test.go +++ b/internal/step/skip_test.go @@ -7,15 +7,31 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" ) func TestStep_Skip(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), EventAction: vela.String(""), @@ -41,9 +57,10 @@ func TestStep_Skip(t *testing.T) { Distribution: vela.String("linux"), } - _comment := &library.Build{ + _comment := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("comment"), EventAction: vela.String("created"), @@ -69,9 +86,10 @@ func TestStep_Skip(t *testing.T) { Distribution: vela.String("linux"), } - _deploy := &library.Build{ + _deploy := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("deployment"), EventAction: vela.String(""), @@ -97,9 +115,10 @@ func TestStep_Skip(t *testing.T) { Distribution: vela.String("linux"), } - _deployFromTag := &library.Build{ + _deployFromTag := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("deployment"), EventAction: vela.String(""), @@ -125,9 +144,10 @@ func TestStep_Skip(t *testing.T) { Distribution: vela.String("linux"), } - _schedule := &library.Build{ + _schedule := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("schedule"), EventAction: vela.String(""), @@ -153,9 +173,10 @@ func TestStep_Skip(t *testing.T) { Distribution: vela.String("linux"), } - _tag := &library.Build{ + _tag := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("tag"), EventAction: vela.String(""), @@ -191,76 +212,52 @@ func TestStep_Skip(t *testing.T) { Pull: "always", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - tests := []struct { name string - build *library.Build + build *api.Build container *pipeline.Container - repo *api.Repo want bool }{ { name: "build", build: _build, container: _container, - repo: _repo, want: false, }, { name: "comment", build: _comment, container: _container, - repo: _repo, want: false, }, { name: "deploy", build: _deploy, container: _container, - repo: _repo, want: false, }, { name: "deployFromTag", build: _deployFromTag, container: _container, - repo: _repo, want: false, }, { name: "schedule", build: _schedule, container: _container, - repo: _repo, want: false, }, { name: "tag", build: _tag, container: _container, - repo: _repo, want: false, }, { name: "skip nil", build: nil, container: nil, - repo: nil, want: true, }, } @@ -268,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, test.repo) + got, err := Skip(test.container, test.build) if err != nil { t.Errorf("Skip returned error: %s", err) } diff --git a/internal/step/snapshot.go b/internal/step/snapshot.go index 537fb3c4..b47bf0ce 100644 --- a/internal/step/snapshot.go +++ b/internal/step/snapshot.go @@ -17,7 +17,7 @@ import ( // Snapshot creates a moment in time record of the // step and attempts to upload it to the server. -func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step) { +func Snapshot(ctn *pipeline.Container, b *api.Build, c *vela.Client, l *logrus.Entry, s *library.Step) { // check if the build is not in a canceled status or error status logrus.Debugf("Snapshot s: %s %s", s.GetName(), s.GetStatus()) @@ -59,7 +59,7 @@ func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logr // send API call to update the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _, _, err := c.Step.Update(r.GetOrg(), r.GetName(), b.GetNumber(), s) + _, _, err := c.Step.Update(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s) if err != nil { l.Errorf("unable to upload step snapshot: %v", err) } @@ -68,7 +68,7 @@ func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logr // SnapshotInit creates a moment in time record of the // init step and attempts to upload it to the server. -func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step, lg *library.Log) { +func SnapshotInit(ctn *pipeline.Container, b *api.Build, c *vela.Client, l *logrus.Entry, s *library.Step, lg *library.Log) { // check if the build is not in a canceled status if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) { // check if the container has an unsuccessful exit code @@ -100,7 +100,7 @@ func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l * // send API call to update the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _, _, err := c.Step.Update(r.GetOrg(), r.GetName(), b.GetNumber(), s) + _, _, err := c.Step.Update(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s) if err != nil { l.Errorf("unable to upload step snapshot: %v", err) } @@ -110,7 +110,7 @@ func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l * // send API call to update the logs for the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#LogService.UpdateStep - _, err = c.Log.UpdateStep(r.GetOrg(), r.GetName(), b.GetNumber(), s.GetNumber(), lg) + _, err = c.Log.UpdateStep(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s.GetNumber(), lg) if err != nil { l.Errorf("unable to upload step logs: %v", err) } diff --git a/internal/step/snapshot_test.go b/internal/step/snapshot_test.go index 0f95915d..da112d16 100644 --- a/internal/step/snapshot_test.go +++ b/internal/step/snapshot_test.go @@ -17,9 +17,26 @@ import ( func TestStep_Snapshot(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -65,22 +82,6 @@ func TestStep_Snapshot(t *testing.T) { Pull: "always", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - _step := &library.Step{ ID: vela.Int64(1), BuildID: vela.Int64(1), @@ -109,10 +110,9 @@ func TestStep_Snapshot(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client container *pipeline.Container - repo *api.Repo step *library.Step }{ { @@ -120,7 +120,6 @@ func TestStep_Snapshot(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, step: _step, }, { @@ -128,24 +127,40 @@ func TestStep_Snapshot(t *testing.T) { build: _build, client: _client, container: _exitCode, - repo: _repo, step: nil, }, } // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - Snapshot(test.container, test.build, test.client, nil, test.repo, test.step) + t.Run(test.name, func(_ *testing.T) { + Snapshot(test.container, test.build, test.client, nil, test.step) }) } } func TestStep_SnapshotInit(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -191,22 +206,6 @@ func TestStep_SnapshotInit(t *testing.T) { Pull: "always", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - _step := &library.Step{ ID: vela.Int64(1), BuildID: vela.Int64(1), @@ -235,11 +234,10 @@ func TestStep_SnapshotInit(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client container *pipeline.Container log *library.Log - repo *api.Repo step *library.Step }{ { @@ -248,7 +246,6 @@ func TestStep_SnapshotInit(t *testing.T) { client: _client, container: _container, log: new(library.Log), - repo: _repo, step: _step, }, { @@ -257,15 +254,14 @@ func TestStep_SnapshotInit(t *testing.T) { client: _client, container: _exitCode, log: new(library.Log), - repo: _repo, step: nil, }, } // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - SnapshotInit(test.container, test.build, test.client, nil, test.repo, test.step, test.log) + t.Run(test.name, func(_ *testing.T) { + SnapshotInit(test.container, test.build, test.client, nil, test.step, test.log) }) } } diff --git a/internal/step/upload.go b/internal/step/upload.go index 32c5a23e..836f2bbf 100644 --- a/internal/step/upload.go +++ b/internal/step/upload.go @@ -16,7 +16,7 @@ import ( // Upload tracks the final state of the step // and attempts to upload it to the server. -func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step) { +func Upload(ctn *pipeline.Container, b *api.Build, c *vela.Client, l *logrus.Entry, s *library.Step) { // handle the step based off the status provided switch s.GetStatus() { // step is in a canceled state @@ -81,7 +81,7 @@ func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus // send API call to update the step // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela#StepService.Update - _, _, err := c.Step.Update(r.GetOrg(), r.GetName(), b.GetNumber(), s) + _, _, err := c.Step.Update(b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber(), s) if err != nil { l.Errorf("unable to upload final step state: %v", err) } diff --git a/internal/step/upload_test.go b/internal/step/upload_test.go index 944b0f7d..85977b8d 100644 --- a/internal/step/upload_test.go +++ b/internal/step/upload_test.go @@ -17,9 +17,26 @@ import ( func TestStep_Upload(t *testing.T) { // setup types - _build := &library.Build{ + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: api.NewEventsFromMask(1), + } + + _build := &api.Build{ ID: vela.Int64(1), Number: vela.Int(1), + Repo: _repo, Parent: vela.Int(1), Event: vela.String("push"), Status: vela.String("success"), @@ -65,22 +82,6 @@ func TestStep_Upload(t *testing.T) { Pull: "always", } - _repo := &api.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowEvents: api.NewEventsFromMask(1), - } - _step := &library.Step{ ID: vela.Int64(1), BuildID: vela.Int64(1), @@ -118,10 +119,9 @@ func TestStep_Upload(t *testing.T) { tests := []struct { name string - build *library.Build + build *api.Build client *vela.Client container *pipeline.Container - repo *api.Repo step *library.Step }{ { @@ -129,7 +129,6 @@ func TestStep_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, step: _step, }, { @@ -137,7 +136,6 @@ func TestStep_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, step: &_canceled, }, { @@ -145,7 +143,6 @@ func TestStep_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, step: &_error, }, { @@ -153,7 +150,6 @@ func TestStep_Upload(t *testing.T) { build: _build, client: _client, container: _container, - repo: _repo, step: &_pending, }, { @@ -161,15 +157,14 @@ func TestStep_Upload(t *testing.T) { build: _build, client: _client, container: _exitCode, - repo: _repo, step: nil, }, } // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - Upload(test.container, test.build, test.client, nil, test.repo, test.step) + t.Run(test.name, func(_ *testing.T) { + Upload(test.container, test.build, test.client, nil, test.step) }) } } diff --git a/mock/worker/build.go b/mock/worker/build.go index 7db1e7a8..a9558c43 100644 --- a/mock/worker/build.go +++ b/mock/worker/build.go @@ -10,18 +10,64 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types" - "github.com/go-vela/types/library" ) const ( - // BuildResp represents a JSON return for a single build. BuildResp = `{ "id": 1, - "repo_id": 1, + "repo": { + "id": 1, + "owner": { + "id": 1, + "name": "octocat", + "favorites": [], + "active": true, + "admin": false + }, + "org": "github", + "counter": 10, + "name": "octocat", + "full_name": "github/octocat", + "link": "https://github.com/github/octocat", + "clone": "https://github.com/github/octocat", + "branch": "main", + "build_limit": 10, + "timeout": 60, + "visibility": "public", + "private": false, + "trusted": true, + "pipeline_type": "yaml", + "topics": [], + "active": true, + "allow_events": { + "push": { + "branch": true, + "tag": true + }, + "pull_request": { + "opened": true, + "synchronize": true, + "reopened": true, + "edited": false + }, + "deployment": { + "created": true + }, + "comment": { + "created": false, + "edited": false + } + }, + "approve_build": "fork-always", + "previous_name": "" + }, + "pipeline_id": 1, "number": 1, "parent": 1, "event": "push", + "event_action": "", "status": "created", "error": "", "enqueued": 1563474077, @@ -29,6 +75,8 @@ const ( "started": 1563474077, "finished": 0, "deploy": "", + "deploy_number": 1, + "deploy_payload": {}, "clone": "https://github.com/github/octocat.git", "source": "https://github.com/github/octocat/commit/48afb5bdc41ad69bf22588491333f7cf71135163", "title": "push received from https://github.com/github/octocat", @@ -40,10 +88,13 @@ const ( "link": "https://vela.example.company.com/github/octocat/1", "branch": "main", "ref": "refs/heads/main", + "head_ref": "", "base_ref": "", "host": "example.company.com", "runtime": "docker", - "distribution": "linux" + "distribution": "linux", + "approved_at": 0, + "approved_by": "" }` ) @@ -61,7 +112,7 @@ func getBuild(c *gin.Context) { data := []byte(BuildResp) - var body library.Build + var body api.Build _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/router/middleware/executor/executor_test.go b/router/middleware/executor/executor_test.go index 06b57dcb..612a54b5 100644 --- a/router/middleware/executor/executor_test.go +++ b/router/middleware/executor/executor_test.go @@ -13,7 +13,6 @@ import ( "github.com/go-vela/sdk-go/vela" api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/executor" "github.com/go-vela/worker/runtime/docker" @@ -29,16 +28,18 @@ func TestExecutor_Retrieve(t *testing.T) { } _repo := new(api.Repo) - _repo.SetOwner(new(library.User)) + _repo.SetOwner(new(api.User)) + + _build := new(api.Build) + _build.SetRepo(_repo) want, err := executor.New(&executor.Setup{ Driver: constants.DriverLinux, MaxLogSize: 2097152, Client: new(vela.Client), Runtime: _runtime, - Build: new(library.Build), + Build: _build, Pipeline: new(pipeline.Build), - Repo: _repo, }) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -66,16 +67,18 @@ func TestExecutor_Establish(t *testing.T) { } _repo := new(api.Repo) - _repo.SetOwner(new(library.User)) + _repo.SetOwner(new(api.User)) + + _build := new(api.Build) + _build.SetRepo(_repo) want, err := executor.New(&executor.Setup{ Driver: constants.DriverLinux, MaxLogSize: 2097152, Client: new(vela.Client), Runtime: _runtime, - Build: new(library.Build), + Build: _build, Pipeline: new(pipeline.Build), - Repo: _repo, }) if err != nil { t.Errorf("unable to create executor engine: %v", err)