Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Re-enable localcommits and buildscripts. #2897

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 1 deletion cmd/state/internal/cmdtree/cmdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func New(prime *primer.Values, args ...string) *CmdTree {
refreshCmd,
newSwitchCommand(prime),
newTestCommand(prime),
//newCommitCommand(prime), // re-enable in DX-2307
newCommitCommand(prime),
)

return &CmdTree{
Expand Down
1 change: 0 additions & 1 deletion internal/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ type projectable interface {
Dir() string
URL() string
LegacyCommitID() string // for commitmediator.Get
LegacySetCommit(string) error // for commitmediator.Set; remove in DX-2307
}

func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName string) *Conditional {
Expand Down
47 changes: 23 additions & 24 deletions internal/runbits/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/language"
"github.com/ActiveState/cli/internal/multilog"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/runbits/git"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
Expand Down Expand Up @@ -57,11 +59,10 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath
return "", errs.Wrap(err, "Could not get absolute path")
}

// Re-enable in DX-2307.
//emptyDir, err := fileutils.IsEmptyDir(path)
//if err != nil {
// multilog.Error("Unable to check if directory is empty: %v", err)
//}
emptyDir, err := fileutils.IsEmptyDir(path)
if err != nil {
multilog.Error("Unable to check if directory is empty: %v", err)
}

// If project does not exist at path then we must checkout
// the project and create the project file
Expand Down Expand Up @@ -126,31 +127,29 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath
configFile := filepath.Join(path, constants.ConfigFileName)
if !fileutils.FileExists(configFile) {
_, err = projectfile.Create(&projectfile.CreateParams{
Owner: owner,
Project: pj.Name, // match case on the Platform
BranchName: branchName,
Directory: path,
Language: language.String(),
Cache: cachePath,
LegacyCommitID: commitID.String(), // remove in DX-2307
Owner: owner,
Project: pj.Name, // match case on the Platform
BranchName: branchName,
Directory: path,
Language: language.String(),
Cache: cachePath,
})
if err != nil {
return "", errs.Wrap(err, "Could not create projectfile")
}
}

// Re-enable in DX-2307.
//err = localcommit.Set(path, commitID.String())
//if err != nil {
// return "", errs.Wrap(err, "Could not create local commit file")
//}
//if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
// err = localcommit.AddToGitIgnore(path)
// if err != nil {
// r.Outputer.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
// multilog.Error("Unable to add local commit file to .gitignore: %v", err)
// }
//}
err = localcommit.Set(path, commitID.String())
if err != nil {
return "", errs.Wrap(err, "Could not create local commit file")
}
if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
err = localcommit.AddToGitIgnore(path)
if err != nil {
r.Outputer.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
multilog.Error("Unable to add local commit file to .gitignore: %v", err)
}
}

return path, nil
}
Expand Down
34 changes: 17 additions & 17 deletions internal/runbits/commitmediator/commitmediator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ package commitmediator

import (
"github.com/go-openapi/strfmt"

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/runbits/legacy/projectmigration"
"github.com/ActiveState/cli/pkg/localcommit"
)

type projecter interface {
Dir() string
URL() string
Path() string
LegacyCommitID() string
LegacySetCommit(string) error // remove this in DX-2307
}

// Get returns the given project's commit ID in either the new format (commit file), or the old
// format (activestate.yaml).
// If you require the commit file, use localcommit.Get().
func Get(proj projecter) (strfmt.UUID, error) {
// Re-enable the contents of this function in DX-2307
//if commitID, err := localcommit.Get(proj.Dir()); err == nil {
// return commitID, nil
//} else if localcommit.IsFileDoesNotExistError(err) {
//if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated {
// return localcommit.Get(proj.Dir())
//} else if err != nil {
// return "", errs.Wrap(err, "Could not prompt and/or migrate project")
//}
return strfmt.UUID(proj.LegacyCommitID()), nil
//} else {
// return "", errs.Wrap(err, "Could not get local commit")
//}
if commitID, err := localcommit.Get(proj.Dir()); err == nil {
return commitID, nil
} else if localcommit.IsFileDoesNotExistError(err) {
if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated {
return localcommit.Get(proj.Dir())
} else if err != nil {
return "", errs.Wrap(err, "Could not prompt and/or migrate project")
}
return strfmt.UUID(proj.LegacyCommitID()), nil
} else {
return "", errs.Wrap(err, "Could not get local commit")
}
}

func Set(proj projecter, commitID string) error {
// Replace all calls to this function with localcommit.Set() in DX-2307.
// Also, consider changing localcommit.Set() to accept a projecter interface with Dir().
return proj.LegacySetCommit(commitID)
return localcommit.Set(proj.Dir(), commitID)
}
10 changes: 5 additions & 5 deletions internal/runbits/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/rtutils"
"github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime"
Expand All @@ -24,11 +25,10 @@ func RefreshRuntime(
trigger target.Trigger,
svcm *model.SvcModel,
) (rerr error) {
// Re-enable in DX-2307.
//_, err := buildscript.Sync(proj, &commitID, out, auth)
//if err != nil {
// return locale.WrapError(err, "err_update_build_script")
//}
_, err := buildscript.Sync(proj, &commitID, out, auth)
if err != nil {
return locale.WrapError(err, "err_update_build_script")
}
target := target.NewProjectTarget(proj, nil, trigger)
isCached := true
rt, err := runtime.New(target, an, svcm, auth)
Expand Down
19 changes: 9 additions & 10 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/ActiveState/cli/pkg/platform/runtime/target"
"github.com/ActiveState/cli/pkg/project"
"github.com/thoas/go-funk"
Expand Down Expand Up @@ -271,22 +272,20 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
return errs.Wrap(err, "Unsupported namespace type: %s", ns.Type().String())
}

// Re-enable in DX-2307.
//expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String())
//if err != nil {
// return errs.Wrap(err, "Could not get remote build expr")
//}
expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String())
if err != nil {
return errs.Wrap(err, "Could not get remote build expr")
}

if err := commitmediator.Set(r.Project, commitID.String()); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

// Note: a commit ID file needs to exist at this point.
// Re-enable in DX-2307.
//err = buildscript.Update(r.Project, expr, r.Auth)
//if err != nil {
// return locale.WrapError(err, "err_update_build_script")
//}
err = buildscript.Update(r.Project, expr, r.Auth)
if err != nil {
return locale.WrapError(err, "err_update_build_script")
}

// refresh or install runtime
err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, r.Project, commitID, true, trigger, r.SvcModel)
Expand Down
25 changes: 12 additions & 13 deletions internal/runners/initialize/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/pkg/localcommit"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime/setup"
Expand Down Expand Up @@ -156,11 +157,10 @@ func (r *Initialize) Run(params *RunParams) (rerr error) {
}
}

// Re-enable in DX-2307.
//emptyDir, err := fileutils.IsEmptyDir(path)
//if err != nil {
// multilog.Error("Unable to check if directory is empty: %v", err)
//}
emptyDir, err := fileutils.IsEmptyDir(path)
if err != nil {
multilog.Error("Unable to check if directory is empty: %v", err)
}

// Match the case of the organization.
// Otherwise the incorrect case will be written to the project file.
Expand Down Expand Up @@ -250,14 +250,13 @@ func (r *Initialize) Run(params *RunParams) (rerr error) {
if err := commitmediator.Set(proj, commitID.String()); err != nil {
return errs.Wrap(err, "Unable to create local commit file")
}
// Re-enable in DX-2307.
//if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
// err := localcommit.AddToGitIgnore(path)
// if err != nil {
// r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
// multilog.Error("Unable to add local commit file to .gitignore: %v", err)
// }
//}
if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {
err := localcommit.AddToGitIgnore(path)
if err != nil {
r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName))
multilog.Error("Unable to add local commit file to .gitignore: %v", err)
}
}

err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, proj, commitID, true, target.TriggerInit, r.svcModel)
if err != nil {
Expand Down
24 changes: 15 additions & 9 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pull

import (
"errors"
"path/filepath"
"strings"

Expand All @@ -18,7 +19,6 @@ import (
"github.com/ActiveState/cli/internal/runbits/commit"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model"
"github.com/ActiveState/cli/pkg/platform/api/mono/mono_models"
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/platform/runtime/buildexpression/merge"
Expand Down Expand Up @@ -194,11 +194,10 @@ func (p *Pull) Run(params *PullParams) (rerr error) {
}

func (p *Pull) performMerge(remoteCommit, localCommit strfmt.UUID, namespace *project.Namespaced, branchName string) (strfmt.UUID, error) {
// Re-enable in DX-2307.
//err := p.mergeBuildScript(strategies, remoteCommit)
//if err != nil {
// return "", errs.Wrap(err, "Could not merge local build script with remote changes")
//}
err := p.mergeBuildScript(remoteCommit, localCommit)
if err != nil {
return "", errs.Wrap(err, "Could not merge local build script with remote changes")
}

p.out.Notice(output.Title(locale.Tl("pull_diverged", "Merging history")))
p.out.Notice(locale.Tr(
Expand Down Expand Up @@ -232,9 +231,8 @@ func (p *Pull) performMerge(remoteCommit, localCommit strfmt.UUID, namespace *pr
return resultCommit, nil
}

// mergeBuildScript merges the local build script with the remote buildexpression (not script) for a
// given UUID, performing the given merge strategy (e.g. from model.MergeCommit).
func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteCommit strfmt.UUID) error {
// mergeBuildScript merges the local build script with the remote buildexpression (not script).
func (p *Pull) mergeBuildScript(remoteCommit, localCommit strfmt.UUID) error {
// Get the build script to merge.
script, err := buildscript.NewScriptFromProject(p.project, p.auth)
if err != nil {
Expand All @@ -249,6 +247,14 @@ func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteC
return errs.Wrap(err, "Unable to get buildexpression for remote commit")
}

// Compute the merge strategy.
strategies, err := model.MergeCommit(remoteCommit, localCommit)
if err != nil {
if !errors.Is(err, model.ErrMergeCommitInHistory) {
return locale.WrapError(err, "err_mergecommit", "Could not detect if merge is necessary.")
}
}

// Attempt the merge.
mergedExpr, err := merge.Merge(exprA, exprB, strategies)
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/cli/pkg/projectfile" // remove in DX-2307
)

// Session represents an end-to-end testing session during which several console process can be spawned and tested
Expand Down Expand Up @@ -382,11 +381,7 @@ func (s *Session) PrepareActiveStateYAML(contents string) {
}

func (s *Session) PrepareCommitIdFile(commitID string) {
// Replace the contents of this function with the line below in DX-2307.
//require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, constants.ProjectConfigDirName, constants.CommitIdFileName), []byte(commitID)))
pjfile, err := projectfile.Parse(filepath.Join(s.Dirs.Work, constants.ConfigFileName))
require.NoError(s.t, err)
require.NoError(s.t, pjfile.LegacySetCommit(commitID))
require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, constants.ProjectConfigDirName, constants.CommitIdFileName), []byte(commitID)))
}

// PrepareProject creates a very simple activestate.yaml file for the given org/project and, if a
Expand Down
2 changes: 0 additions & 2 deletions pkg/platform/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ func (r *Runtime) validateCache() error {
return nil
}

return nil // remove in DX-2307 to re-enable buildscripts below

// Check if local build script has changes that should be committed.
script, err := buildscript.NewScriptFromProject(r.target, r.auth)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ActiveState/cli/pkg/platform/runtime/artifact"
"github.com/ActiveState/cli/pkg/platform/runtime/artifactcache"
"github.com/ActiveState/cli/pkg/platform/runtime/buildplan"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/ActiveState/cli/pkg/platform/runtime/envdef"
"github.com/ActiveState/cli/pkg/platform/runtime/executors"
"github.com/ActiveState/cli/pkg/platform/runtime/setup/buildlog"
Expand Down Expand Up @@ -601,10 +602,9 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
}

if s.target.ProjectDir() != "" {
// Re-enable in DX-2307
//if err := buildscript.Update(s.target, buildResult.BuildExpression, s.auth); err != nil {
// return nil, nil, errs.Wrap(err, "Could not save build script.")
//}
if err := buildscript.Update(s.target, buildResult.BuildExpression, s.auth); err != nil {
return nil, nil, errs.Wrap(err, "Could not save build script.")
}
}

artifacts := buildResult.OrderedArtifacts()
Expand Down
6 changes: 0 additions & 6 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ func (p *Project) LegacyCommitID() string {
return p.projectfile.LegacyCommitID()
}

// LegacySetCommit is for use by commitmediator.Set() ONLY.
// Remove in DX-2307.
func (p *Project) LegacySetCommit(commitID string) error {
return p.projectfile.LegacySetCommit(commitID)
}

func (p *Project) IsHeadless() bool {
match := projectfile.CommitURLRe.FindStringSubmatch(p.URL())
return len(match) > 1
Expand Down
1 change: 0 additions & 1 deletion pkg/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (suite *ProjectTestSuite) TestGetSafe() {

func (suite *ProjectTestSuite) TestProject() {
projectLine := "https://platform.activestate.com/ActiveState/project?branch=main"
projectLine += "&commitID=00010001-0001-0001-0001-000100010001" // remove in DX-2307
suite.Equal(projectLine, suite.project.URL(), "Values should match")
suite.Equal("project", suite.project.Name(), "Values should match")
commitID, err := commitmediator.Get(suite.project)
Expand Down
2 changes: 1 addition & 1 deletion pkg/project/testdata/activestate.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project: https://platform.activestate.com/ActiveState/project?branch=main&commitID=00010001-0001-0001-0001-000100010001
project: https://platform.activestate.com/ActiveState/project?branch=main
environments: "something"
lock: "[email protected]"
namespace: "my/name/space"
Expand Down
Loading
Loading