Skip to content

Commit

Permalink
Merge branch 'version/0-42-0-RC1' into v43-merge-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Oct 31, 2023
2 parents 6b70818 + c3faef4 commit e0e00f1
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 263 deletions.
6 changes: 0 additions & 6 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ const PlatformSignupURL = "https://platform.activestate.com" + "/create-account"
// DocumentationURL is the url for the state tool documentation
const DocumentationURL = "http://docs.activestate.com/platform/state/"

// DocumentationURLHeadless is the documentation URL for headless state docs
const DocumentationURLHeadless = DocumentationURL + "advanced-topics/detached/"

// DocumentationURLGetStarted is the documentation URL for creating projects
const DocumentationURLGetStarted = DocumentationURL + "create-project/?utm_source=platform-application-gui&utm_medium=activestate-desktop&utm_content=drop-down&utm_campaign=maru"

Expand All @@ -315,9 +312,6 @@ const ActiveStateSupportURL = "https://www.activestate.com/support/?utm_source=p
// ActiveStateDashboardURL is the URL for the ActiveState account preferences page
const ActiveStateDashboardURL = "https://platform.activestate.com/?utm_source=platform-application-gui&utm_medium=activestate-desktop&utm_content=drop-down&utm_campaign=maru"

// DashboardCommitURL is the URL used to inspect commits
const DashboardCommitURL = "https://platform.activestate.com/commit/"

// BugTrackerURL is the URL of our bug tracker
const BugTrackerURL = "https://github.com/ActiveState/state-tool/issues"

Expand Down
18 changes: 3 additions & 15 deletions internal/locale/locales/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ err_output_flag_value_invalid:
other: Could not recognize output type
info_deactivated:
other: "[DISABLED]Deactivated {{.Owner}}/{{.Name}}[/RESET]"
info_deactivated_by_commit:
other: "[DISABLED]Deactivated[/RESET]"
venv_installer_is_nil:
other: Provided installer should not be nil
error_unsupported_language:
Expand Down Expand Up @@ -784,8 +782,6 @@ build_status_unknown:
other: "Build status could not be retrieved, please view the project at: [NOTICE]{{.V0}}[/RESET] for more information"
build_status_in_progress:
other: "Your changes are currently being built remotely on the ActiveState Platform. Please visit [NOTICE]{{.V0}}[/RESET] to see the progress."
build_status_in_progress_headless:
other: "Your changes are currently being built remotely on the ActiveState Platform. Please visit [NOTICE]{{.V0}}[/RESET] to see the progress (you may have to first convert your runtime to a project)."
build_status_unknown_error:
other: "Build reported an unknown error: {{.V0}}; Please view the project at: [ACTIONABLE]{{.V1}}[/RESET] for more information"
build_status_failed:
Expand Down Expand Up @@ -1152,12 +1148,6 @@ bundle_updated:
other: "Bundle updated: [NOTICE]{{.V0}}[/RESET]"
bundle_version_updated:
other: "Bundle updated: [NOTICE]{{.V0}}@{{.V1}}[/RESET]"
package_headless_added:
other: "Package added: [NOTICE]{{.V0}}[/RESET]"
package_headless_updated:
other: "Package updated: [NOTICE]{{.V0}}[/RESET]"
package_headless_removed:
other: "Package uninstalled: [NOTICE]{{.V0}}[/RESET]"
err_package_removed:
other: Failed to remove package
err_bundle_removed:
Expand Down Expand Up @@ -1233,8 +1223,6 @@ init_description:
other: Initialize a new project
push_description:
other: Push your latest changes to the platform
push_first_new_project:
other: 'Since this is your first time running "push" you''ll need to create a new project on the ActiveState Platform.'
push_prompt_owner:
other: "Who would you like the owner of this project to be?"
push_prompt_not_authorized:
Expand Down Expand Up @@ -1725,8 +1713,10 @@ err_tip_push_outdated:
other: Run '[ACTIONABLE]state pull[/RESET]'.
err_push_not_authenticated:
other: In order to update your project you need to be authenticated, please run '[ACTIONABLE]state auth[/RESET]' to authenticate.
err_push_headless:
err_push_no_project:
other: No project found, you may need to create one first.
err_push_headless:
other: Cannot push a headless project. To convert your project please visit {{.V0}}
push_push_tip_headless_init:
other: Run '[ACTIONABLE]state init[/RESET]' to create a project with the State Tool.
push_push_tip_headless_cwd:
Expand Down Expand Up @@ -1831,8 +1821,6 @@ package_ingredient_alternatives_nolang:
No results found for search term "[NOTICE]{{.V0}}[/RESET]".
This may be because you have not installed a language for your project. Install a language by running "[ACTIONABLE]state languages install <language-name>[/RESET]".
progress_project:
other: " • Initializing Project"
progress_search:
other: " • Searching for [ACTIONABLE]{{.V0}}[/RESET] in the ActiveState Catalog"
setup_runtime:
Expand Down
67 changes: 17 additions & 50 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package requirements

import (
"errors"
"fmt"
"os"
"strconv"
"strings"

Expand All @@ -21,16 +19,15 @@ import (
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/runbits"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/pkg/localcommit"
bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model"
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/artifact"
"github.com/ActiveState/cli/pkg/platform/runtime/buildscript"
"github.com/ActiveState/cli/pkg/platform/runtime/target"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/cli/pkg/projectfile"
"github.com/thoas/go-funk"
)

Expand Down Expand Up @@ -104,32 +101,18 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
}()

var err error
pj := r.Project
if pj == nil {
pg = output.StartSpinner(out, locale.Tl("progress_project", "", requirementName), constants.TerminalAnimationInterval)
pj, err = initializeProject()
if err != nil {
return locale.WrapError(err, "err_package_get_project", "Could not get project from path")
}
pg.Stop(locale.T("progress_success"))
pg = nil // The defer above will redundantly call pg.Stop on success if we don't set this to nil

defer func() {
if rerr != nil && !errors.Is(err, artifact.CamelRuntimeBuilding) {
if err := os.Remove(pj.Source().Path()); err != nil {
multilog.Error("could not remove temporary project file: %s", errs.JoinMessage(err))
}
}
}()
if r.Project == nil {
return rationalize.ErrNoProject
}
out.Notice(locale.Tl("operating_message", "", pj.NamespaceString(), pj.Dir()))
out.Notice(locale.Tl("operating_message", "", r.Project.NamespaceString(), r.Project.Dir()))

switch nsType {
case model.NamespacePackage, model.NamespaceBundle:
commitID, err := localcommit.Get(pj.Dir())
commitID, err := localcommit.Get(r.Project.Dir())
if err != nil && !localcommit.IsFileDoesNotExistError(err) {
return errs.Wrap(err, "Unable to get local commit")
}

language, err := model.LanguageByCommit(commitID)
if err == nil {
langName = language.Name
Expand Down Expand Up @@ -183,16 +166,19 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
if err != nil {
return locale.WrapError(err, "package_err_cannot_obtain_search_results")
}

if len(packages) == 0 {
suggestions, err := getSuggestions(ns, requirementName)
if err != nil {
multilog.Error("Failed to retrieve suggestions: %v", err)
}

if len(suggestions) == 0 {
return &ErrNoMatches{
locale.WrapInputError(err, "package_ingredient_alternatives_nosuggest", "", requirementName),
requirementName, nil}
}

return &ErrNoMatches{
locale.WrapInputError(err, "package_ingredient_alternatives", "", requirementName, strings.Join(suggestions, "\n")),
requirementName, ptr.To(strings.Join(suggestions, "\n"))}
Expand All @@ -204,7 +190,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
pg = nil
}

parentCommitID, err := localcommit.Get(pj.Dir())
parentCommitID, err := localcommit.Get(r.Project.Dir())
if err != nil && !localcommit.IsFileDoesNotExistError(err) {
return errs.Wrap(err, "Unable to get local commit")
}
Expand Down Expand Up @@ -251,8 +237,8 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
}

params := model.StageCommitParams{
Owner: pj.Owner(),
Project: pj.Name(),
Owner: r.Project.Owner(),
Project: r.Project.Name(),
ParentCommit: string(parentCommitID),
Description: commitMessage(operation, name, version, ns, requirementBitWidth),
RequirementName: name,
Expand Down Expand Up @@ -283,29 +269,29 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
return errs.Wrap(err, "Unsupported namespace type: %s", ns.Type().String())
}

expr, err := bp.GetBuildExpression(pj.Owner(), pj.Name(), commitID.String())
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 := localcommit.Set(pj.Dir(), commitID.String()); err != nil {
if err := localcommit.Set(r.Project.Dir(), commitID.String()); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

// Note: a commit ID file needs to exist at this point.
err = buildscript.Update(pj, expr, r.Auth)
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, pj, commitID, true, trigger, r.SvcModel)
err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, r.Project, commitID, true, trigger, r.SvcModel)
if err != nil {
return err
}

if !hasParentCommit {
out.Notice(locale.Tr("install_initial_success", pj.Source().Path()))
out.Notice(locale.Tr("install_initial_success", r.Project.Source().Path()))
}

// Print the result
Expand Down Expand Up @@ -413,25 +399,6 @@ func getSuggestions(ns model.Namespace, name string) ([]string, error) {
return suggestions, nil
}

func initializeProject() (*project.Project, error) {
target, err := os.Getwd()
if err != nil {
return nil, locale.WrapError(err, "err_add_get_wd", "Could not get working directory for new project")
}

createParams := &projectfile.CreateParams{
ProjectURL: constants.DashboardCommitURL,
Directory: target,
}

_, err = projectfile.Create(createParams)
if err != nil {
return nil, locale.WrapError(err, "err_add_create_projectfile", "Could not create new projectfile")
}

return project.FromPath(target)
}

func commitMessage(op bpModel.Operation, name, version string, namespace model.Namespace, word int) string {
switch namespace.Type() {
case model.NamespaceLanguage:
Expand Down
22 changes: 6 additions & 16 deletions internal/runners/activate/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,12 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
}
}

if proj != nil && params.Branch != "" {
if proj.IsHeadless() {
return locale.NewInputError(
"err_conflicting_branch_while_headless",
"Cannot activate branch [NOTICE]{{.V0}}[/RESET] while in a headless state. Please visit {{.V1}} to create your project.",
params.Branch, proj.URL(),
)
}
if proj != nil && proj.IsHeadless() {
return locale.NewInputError("err_activate_headless", "Cannot activate a headless project. Please visit {{.V0}} to create your project.", proj.URL())
}

if params.Branch != proj.BranchName() {
return locale.NewInputError("err_conflicting_branch_while_checkedout", "", params.Branch, proj.BranchName())
}
if proj != nil && params.Branch != "" && params.Branch != proj.BranchName() {
return locale.NewInputError("err_conflicting_branch_while_checkedout", "", params.Branch, proj.BranchName())
}

// Have to call this once the project has been set
Expand Down Expand Up @@ -208,11 +202,7 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
return locale.WrapError(err, "err_activate_wait", "Could not activate runtime environment.")
}

if proj.IsHeadless() {
r.out.Notice(locale.T("info_deactivated_by_commit"))
} else {
r.out.Notice(locale.T("info_deactivated", proj))
}
r.out.Notice(locale.T("info_deactivated", proj))

return nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/runners/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func (d *Deploy) Run(params *Params) error {
return locale.WrapError(err, "err_deploy_commitid", "Could not grab commit ID for project: {{.V0}}.", params.Namespace.String())
}

// Headless argument is simply false here as you cannot deploy a headless project
rtTarget := target.NewCustomTarget(params.Namespace.Owner, params.Namespace.Project, commitID, params.Path, target.TriggerDeploy, false) /* TODO: handle empty path */
rtTarget := target.NewCustomTarget(params.Namespace.Owner, params.Namespace.Project, commitID, params.Path, target.TriggerDeploy) /* TODO: handle empty path */

logging.Debug("runSteps: %s", d.step.String())

Expand Down
8 changes: 2 additions & 6 deletions internal/runners/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ func (s *Exec) Run(params *Params, args ...string) (rerr error) {
projectDir = projectFromRuntimeDir(s.cfg, params.Path)
proj, err = project.FromPath(projectDir)
if err != nil {
logging.Warning("Could not get project dir from path: %s", errs.JoinMessage(err))
// We do not know if the project is headless at this point so we default to true
// as there is no head
rtTarget = target.NewCustomTarget("", "", "", params.Path, trigger, true)
} else {
rtTarget = target.NewProjectTarget(proj, nil, trigger)
return locale.WrapInputError(err, "exec_no_project_at_path", "Could not find project file at {{.V0}}", projectDir)
}
rtTarget = target.NewProjectTarget(proj, nil, trigger)
projectNamespace = proj.NamespaceString()
} else {
proj = s.proj
Expand Down
21 changes: 11 additions & 10 deletions internal/runners/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ func (h *History) Run(params *HistoryParams) error {
return errs.Wrap(err, "Unable to get local commit")
}

var latestRemoteID *strfmt.UUID
if !h.project.IsHeadless() {
remoteBranch, err := model.BranchForProjectNameByName(h.project.Owner(), h.project.Name(), h.project.BranchName())
if err != nil {
return locale.WrapError(err, "err_history_remote_branch", "Could not get branch by local branch name")
}
if h.project.IsHeadless() {
return locale.NewInputError("err_history_headless", "Cannot get history for headless project. Please visit {{.V0}} to convert your project and try again.", h.project.URL())
}

latestRemoteID, err = model.CommonParent(remoteBranch.CommitID, &localCommitID)
if err != nil {
return locale.WrapError(err, "err_history_common_parent", "Could not determine common parent commit")
}
remoteBranch, err := model.BranchForProjectNameByName(h.project.Owner(), h.project.Name(), h.project.BranchName())
if err != nil {
return locale.WrapError(err, "err_history_remote_branch", "Could not get branch by local branch name")
}

latestRemoteID, err := model.CommonParent(remoteBranch.CommitID, &localCommitID)
if err != nil {
return locale.WrapError(err, "err_history_common_parent", "Could not determine common parent commit")
}

commits, err := model.CommitHistoryFromID(localCommitID)
Expand Down
2 changes: 1 addition & 1 deletion internal/runners/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *Prepare) resetExecutors() error {
return errs.Wrap(err, "Unable to get local commit")
}

run, err := rt.New(target.NewCustomTarget(proj.Owner(), proj.Name(), commitID, defaultTargetDir, target.TriggerResetExec, proj.IsHeadless()), r.analytics, r.svcModel, nil)
run, err := rt.New(target.NewCustomTarget(proj.Owner(), proj.Name(), commitID, defaultTargetDir, target.TriggerResetExec), r.analytics, r.svcModel, nil)
if err != nil {
if rt.IsNeedsUpdateError(err) {
return nil // project was never set up, so no executors to reset
Expand Down
4 changes: 2 additions & 2 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func (p *Pull) Run(params *PullParams) error {
}
p.out.Notice(locale.Tl("operating_message", "", p.project.NamespaceString(), p.project.Dir()))

if p.project.IsHeadless() && params.SetProject == "" {
if p.project.IsHeadless() {
return locale.NewInputError("err_pull_headless", "You must first create a project. Please visit {{.V0}} to create your project.", p.project.URL())
}

if !p.project.IsHeadless() && p.project.BranchName() == "" {
if p.project.BranchName() == "" {
return locale.NewError("err_pull_branch", "Your [NOTICE]activestate.yaml[/RESET] project field does not contain a branch. Please ensure you are using the latest version of the State Tool by running [ACTIONABLE]`state update`[/RESET] and then trying again.")
}

Expand Down
Loading

0 comments on commit e0e00f1

Please sign in to comment.