Skip to content

Fix: fix compatibility for output #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
ARG BASE_IMAGE
# Build the manager binary
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22-alpine as builder
ARG GOPROXY
ENV GOPROXY=${GOPROXY:-https://goproxy.cn}
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
ARG BASE_IMAGE
# Build the manager binary
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22-alpine as builder
ARG GOPROXY
ENV GOPROXY=${GOPROXY:-https://goproxy.cn}
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand Down
8 changes: 8 additions & 0 deletions pkg/hooks/data_passing.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
SetAdditionalNameInStatus(stepStatus, step.Name, step.Properties, status)
for _, output := range step.Outputs {
v, err := value.LookupValueByScript(taskValue, output.ValueFrom)
if err != nil && strings.Contains(err.Error(), "not exist") && !strings.Contains(output.ValueFrom, "$returns.") {
parts := strings.Split(output.ValueFrom, ".")
if len(parts) > 1 {
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("%s.$returns.%s", parts[0], strings.Join(parts[1:], ".")))
} else {
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("%s.$returns", output.ValueFrom))

Check warning on line 72 in pkg/hooks/data_passing.go

View check run for this annotation

Codecov / codecov/patch

pkg/hooks/data_passing.go#L72

Added line #L72 was not covered by tests
}
}
// if the error is not nil and the step is not skipped, return the error
if err != nil && status.Phase != v1alpha1.WorkflowStepPhaseSkipped {
errMsg += fmt.Sprintf("failed to get output from %s: %s\n", output.ValueFrom, err.Error())
Expand Down
47 changes: 47 additions & 0 deletions pkg/hooks/data_passing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,53 @@ func TestOutput(t *testing.T) {
r.NoError(err)
r.Equal(int(resultInt), 99)
r.Equal(stepStatus["mystep"].Phase, v1alpha1.WorkflowStepPhaseSucceeded)

taskValue = cuectx.CompileString(`output: $returns: score: 99`)
stepStatus = make(map[string]v1alpha1.StepStatus)
err = Output(wfCtx, taskValue, v1alpha1.WorkflowStep{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Properties: &runtime.RawExtension{
Raw: []byte("{\"name\":\"mystep\"}"),
},
Outputs: v1alpha1.StepOutputs{{
ValueFrom: "output.$returns.score",
Name: "myscore2",
}},
},
}, v1alpha1.StepStatus{
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
}, stepStatus)
r.NoError(err)
result, err = wfCtx.GetVar("myscore2")
r.NoError(err)
resultInt, err = result.Int64()
r.NoError(err)
r.Equal(int(resultInt), 99)
r.Equal(stepStatus["mystep"].Phase, v1alpha1.WorkflowStepPhaseSucceeded)


taskValue = cuectx.CompileString(`output: $returns: score: 99`)
stepStatus = make(map[string]v1alpha1.StepStatus)
err = Output(wfCtx, taskValue, v1alpha1.WorkflowStep{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Properties: &runtime.RawExtension{
Raw: []byte("{\"name\":\"mystep\"}"),
},
Outputs: v1alpha1.StepOutputs{{
ValueFrom: "output.score",
Name: "myscore3",
}},
},
}, v1alpha1.StepStatus{
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
}, stepStatus)
r.NoError(err)
result, err = wfCtx.GetVar("myscore3")
r.NoError(err)
resultInt, err = result.Int64()
r.NoError(err)
r.Equal(int(resultInt), 99)
r.Equal(stepStatus["mystep"].Phase, v1alpha1.WorkflowStepPhaseSucceeded)
}

func mockContext(t *testing.T) wfContext.Context {
Expand Down
Loading