Skip to content

Commit

Permalink
Merge pull request #2774 from ActiveState/mitchell/dx-1961
Browse files Browse the repository at this point in the history
Build scripts should use buildexpression types.
  • Loading branch information
mitchell-as authored Oct 3, 2023
2 parents 30a336c + 1fca303 commit 7b0308d
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 286 deletions.
7 changes: 1 addition & 6 deletions internal/runbits/buildscript/buildscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ func Sync(proj *project.Project, commitID *strfmt.UUID, out output.Outputer, aut
return false, nil // nothing to do
}
logging.Debug("Merging changes")
expr, err = script.ToBuildExpression()
if err != nil {
return false, errs.Wrap(err, "Unable to translate local build script to build expression")
}

out.Notice(locale.Tl("buildscript_update", "Updating project to reflect build script changes..."))

localCommitID, err := localcommit.Get(proj.Dir())
Expand All @@ -74,7 +69,7 @@ func Sync(proj *project.Project, commitID *strfmt.UUID, out output.Outputer, aut
Owner: proj.Owner(),
Project: proj.Name(),
ParentCommit: localCommitID.String(),
Expression: expr,
Expression: script.Expr,
})
if err != nil {
return false, errs.Wrap(err, "Could not update project to reflect build script changes.")
Expand Down
11 changes: 9 additions & 2 deletions internal/runbits/buildscript/buildscript_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package buildscript

import (
"encoding/json"
"testing"

"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/pkg/platform/runtime/buildexpression"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -29,11 +31,16 @@ in:
runtime`))
require.NoError(t, err)

expr, err := script.ToBuildExpression()
// Make a copy of the original expression.
bytes, err := json.Marshal(script.Expr)
require.NoError(t, err)
expr, err := buildexpression.New(bytes)
require.NoError(t, err)

(*script.Let.Assignments[0].Value.FuncCall.Arguments[0].Assignment.Value.List)[0].Str = ptr.To(`"77777"`)
// Modify the build script.
(*script.Expr.Let.Assignments[0].Value.Ap.Arguments[0].Assignment.Value.List)[0].Str = ptr.To(`77777`)

// Generate the difference between the modified script and the original expression.
result, err := generateDiff(script, expr)
require.NoError(t, err)
assert.Equal(t, `let:
Expand Down
5 changes: 1 addition & 4 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteC
}

// Get the local and remote build expressions to merge.
exprA, err := script.ToBuildExpression()
if err != nil {
return errs.Wrap(err, "Unable to transform local buildscript into buildexpression")
}
exprA := script.Expr
bp := model.NewBuildPlannerModel(p.auth)
exprB, err := bp.GetBuildExpression(p.project.Owner(), p.project.Name(), remoteCommit.String())
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/runtime/buildexpression/buildexpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ func newValue(path []string, valueInterface interface{}) (*Value, error) {
case float64:
value.Float = ptr.To(v)

case nil:
// An empty value is interpreted as JSON null.
value.Null = &Null{}

default:
logging.Debug("Unknown type: %T at path %s", v, strings.Join(path, "."))
// An empty value is interpreted as JSON null.
Expand Down
228 changes: 0 additions & 228 deletions pkg/platform/runtime/buildscript/buildexpression.go

This file was deleted.

Loading

0 comments on commit 7b0308d

Please sign in to comment.