move schema update on step to runnner go logic

pull/16/head
Eoin McAfee 3 years ago
parent 1658440152
commit 386295f94d

@ -25,4 +25,5 @@ func MergeStep(src, dst *drone.Step) {
dst.Started = src.Started
dst.Stopped = src.Stopped
dst.Version = src.Version
dst.Schema = src.Schema
}

@ -254,10 +254,9 @@ func (e *Execer) exec(ctx context.Context, state *pipeline.State, spec Spec, ste
}
// stream card data to server if exists
file, _ := e.engine.StreamFile(ctx, copy, "/tmp/card.json")
file, _ := e.engine.StreamFile(ctx, spec, copy, "/tmp/card.json")
if file != nil {
s := state.Find(step.GetName())
err = e.uploader.UploadCard(ctx, file, s.ID)
err = e.uploader.UploadCard(ctx, file, state, step.GetName())
if err != nil {
return nil
}

@ -86,7 +86,7 @@ type (
Run(context.Context, Spec, Step, io.Writer) (*State, error)
// StreamFile copies a file to the server
StreamFile(context.Context, Step, string) (io.ReadCloser, error)
StreamFile(context.Context, Spec, Step, string) (io.ReadCloser, error)
}
// Spec is an interface that must be implemented by all

@ -6,7 +6,7 @@ import (
)
type Uploader interface {
UploadCard(ctx context.Context, r io.ReadCloser, step int64) error
UploadCard(context.Context, io.ReadCloser, *State, string) error
}
func NopUploader() Uploader {
@ -15,4 +15,4 @@ func NopUploader() Uploader {
type nopUploader struct{}
func (*nopUploader) UploadCard(ctx context.Context, r io.ReadCloser, step int64) error { return nil }
func (*nopUploader) UploadCard(context.Context, io.ReadCloser, *State, string) error { return nil }

@ -7,6 +7,7 @@ import (
"github.com/drone/drone-go/drone"
"github.com/drone/runner-go/client"
"github.com/drone/runner-go/internal"
"github.com/drone/runner-go/pipeline"
)
@ -22,7 +23,8 @@ func New(client client.Client) *Upload {
}
}
func (s *Upload) UploadCard(ctx context.Context, r io.ReadCloser, step int64) error {
func (s *Upload) UploadCard(ctx context.Context, r io.ReadCloser, state *pipeline.State, stepName string) error {
src := state.Find(stepName)
bytes, err := io.ReadAll(r)
if err != nil {
return err
@ -32,9 +34,20 @@ func (s *Upload) UploadCard(ctx context.Context, r io.ReadCloser, step int64) er
if err != nil {
return err
}
err = s.client.UploadCard(ctx, step, &card)
err = s.client.UploadCard(ctx, src.ID, &card)
if err != nil {
return err
}
// update step schema
state.Lock()
src.Schema = card.Schema
cpy := internal.CloneStep(src)
state.Unlock()
err = s.client.UpdateStep(ctx, cpy)
if err == nil {
state.Lock()
internal.MergeStep(cpy, src)
state.Unlock()
}
return nil
}

Loading…
Cancel
Save