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. #3037

Merged
merged 4 commits into from
Jan 22, 2024
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: 1 addition & 1 deletion cmd/state/internal/cmdtree/cmdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func New(prime *primer.Values, args ...string) *CmdTree {
refreshCmd,
newSwitchCommand(prime),
newTestCommand(prime),
//newCommitCommand(prime), // re-enable in DX-2307
newCommitCommand(prime),
newPublish(prime),
)

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
50 changes: 26 additions & 24 deletions internal/runbits/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ 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/osutils"
"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 @@ -58,11 +60,13 @@ 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 := true
if fileutils.DirExists(path) {
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 @@ -140,13 +144,12 @@ 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 {
if osutils.IsAccessDeniedError(err) {
Expand All @@ -156,18 +159,17 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath
}
}

// 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 @@ -25,11 +26,10 @@ func RefreshRuntime(
svcm *model.SvcModel,
cfg model.Configurable,
) (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, resolveCommitID(proj, &commitID), trigger)
isCached := true
rt, err := runtime.New(target, an, svcm, auth, cfg)
Expand Down
35 changes: 17 additions & 18 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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/go-openapi/strfmt"
Expand Down Expand Up @@ -281,19 +282,13 @@ func (r *RequirementOperation) ExecuteRequirementOperation(
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")
//}

// refresh or install runtime
err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, r.Project, commitID, true, trigger, r.SvcModel, r.Config)
if err != nil {
return handleRefreshError(err, r.Project, parentCommitID)
return r.handleRefreshError(err, parentCommitID)
}

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

Expand Down Expand Up @@ -331,28 +326,32 @@ func (r *RequirementOperation) ExecuteRequirementOperation(
return nil
}

func handleRefreshError(err error, project *project.Project, parentCommitID strfmt.UUID) error {
func (r *RequirementOperation) handleRefreshError(err error, parentCommitID strfmt.UUID) error {
// If the error is a build error then return, if not update the commit ID then return
if !runbits.IsBuildError(err) {
if err := updateCommitID(project, parentCommitID); err != nil {
if err := r.updateCommitID(parentCommitID); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}
}
return err
}

func updateCommitID(project *project.Project, commitID strfmt.UUID) error {
if err := commitmediator.Set(project, commitID.String()); err != nil {
func (r *RequirementOperation) updateCommitID(commitID strfmt.UUID) error {
if err := commitmediator.Set(r.Project, commitID.String()); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

bp := model.NewBuildPlannerModel(r.Auth)
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")
}

// Note: a commit ID file needs to exist at this point.
// Re-enable in DX-2307.
// Will have to pass the buildscript as an argument to this function.
//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")
}

return nil
}
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 @@ -21,6 +21,7 @@ import (
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/internal/runbits/commitmediator"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"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 @@ -161,11 +162,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 @@ -247,14 +247,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, r.config)
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 @@ -21,7 +22,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 @@ -180,11 +180,10 @@ func (p *Pull) Run(params *PullParams) (rerr error) {
}

func (p *Pull) performMerge(remoteCommit, localCommit strfmt.UUID, namespace *project.Namespaced, branchName string, strategy bpModel.MergeStrategy) (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 @@ -218,9 +217,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 @@ -235,6 +233,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 @@ -41,7 +41,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 @@ -320,11 +319,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 @@ -120,8 +120,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
Loading
Loading