Skip to content

Commit

Permalink
Merge pull request #3347 from ActiveState/mitchell/dx-2665
Browse files Browse the repository at this point in the history
Remove project persistence.
  • Loading branch information
mitchell-as authored Jun 10, 2024
2 parents 5d483b3 + 7742c3a commit f511227
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 311 deletions.
2 changes: 1 addition & 1 deletion activestate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ scripts:
language: bash
description: Runs unit tests (not integration tests)
value: |
ACTIVESTATE_PROJECT="" go test -v `go list ./... | grep -v integration | grep -v automation | grep -v expect | grep -v state-svc | grep -v state-offline` $@
go test -v `go list ./... | grep -v integration | grep -v automation | grep -v expect | grep -v state-svc | grep -v state-offline` $@
standalone: true
- name: integration-tests
language: bash
Expand Down
3 changes: 3 additions & 0 deletions cmd/state/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func run(args []string, isInteractive bool, cfg *config.Instance, out output.Out
projectfile.RegisterMigrator(migrator.NewMigrator(auth, cfg))

// Retrieve project file
if os.Getenv("ACTIVESTATE_PROJECT") != "" {
out.Notice(locale.T("warning_activestate_project_env_var"))
}
pjPath, err := projectfile.GetProjectFilePath()
if err != nil && errs.Matches(err, &projectfile.ErrorNoProjectFromEnv{}) {
// Fail if we are meant to inherit the projectfile from the environment, but the file doesn't exist
Expand Down
3 changes: 0 additions & 3 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ const AutoUpdateTimeoutEnvVarName = "ACTIVESTATE_CLI_UPDATE_TIMEOUT"
// EnvironmentEnvVarName is the name of the environment variable that specifies the current environment (dev, qa, prod, etc.)
const EnvironmentEnvVarName = "ACTIVESTATE_ENVIRONMENT"

// ProjectEnvVarName is the name of the environment variable that specifies the path of the activestate.yaml config file.
const ProjectEnvVarName = "ACTIVESTATE_PROJECT"

// ActivatedStateEnvVarName is the name of the environment variable that is set when in an activated state, its value will be the path of the project
const ActivatedStateEnvVarName = "ACTIVESTATE_ACTIVATED"

Expand Down
3 changes: 3 additions & 0 deletions internal/locale/locales/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,9 @@ err_no_project:
other: To run this command you need to be in an existing project. You can create a new project with [ACTIONABLE]state init[/RESET] or run this command from a directory that is in an existing project. You can also use an existing project by running '[ACTIONABLE]state activate --default[/RESET]' inside your project directory.
err_no_projectfile:
other: No activestate.yaml file exists in the current working directory or its parent directories.
warning_activestate_project_env_var:
other: |
[NOTICE]DEPRECATION WARNING[/RESET] The '[ACTIONABLE]ACTIVESTATE_PROJECT[/RESET]' environment variable is no longer supported. Instead run your command from the directory with your activestate.yaml.
err_project_not_found:
other: Could not find project at [NOTICE]{{.V0}}[/RESET]
err_non_interactive_prompt:
Expand Down
10 changes: 2 additions & 8 deletions internal/runners/activate/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/user"
"path/filepath"
rt "runtime"

"github.com/ActiveState/cli/internal/analytics"
Expand Down Expand Up @@ -152,11 +151,6 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) {
// Have to call this once the project has been set
r.analytics.Event(anaConsts.CatActivationFlow, "start")

err = proj.Source().Persist()
if err != nil {
return errs.Wrap(err, "Unable to persist project")
}

// Yes this is awkward, issue here - https://www.pivotaltracker.com/story/show/175619373
activatedKey := fmt.Sprintf("activated_%s", proj.Namespace().String())
setDefault := params.Default
Expand Down Expand Up @@ -239,8 +233,8 @@ func warningForAdministrator(out output.Outputer) {
}

func parentNamespace() (string, error) {
path := os.Getenv(constants.ProjectEnvVarName)
proj, err := project.FromExactPath(filepath.Dir(path))
path := os.Getenv(constants.ActivatedStateEnvVarName)
proj, err := project.FromExactPath(path)
if err != nil {
return "", locale.WrapError(err, "err_activate_projectpath", "Could not get project from path {{.V0}}", path)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/runners/scripts/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (suite *EditTestSuite) TestNewScriptWatcher() {
suite.Require().NoError(err, "unexpected error creating script watcher")

catcher := outputhelper.NewCatcher()
proj, err := project.Get()
proj, err := project.FromWD()
suite.Require().NoError(err, "unexpected error getting project")
go watcher.run("hello", catcher.Outputer, suite.cfg, proj)

Expand All @@ -129,12 +129,12 @@ func (suite *EditTestSuite) TestUpdateProjectFile() {
suite.scriptFile, err = createScriptFile(replace, false)
suite.Require().NoError(err, "unexpected error creating script file")

proj, err := project.Get()
proj, err := project.FromWD()
suite.Require().NoError(err, "unexpected error getting project")
err = updateProjectFile(suite.cfg, proj, suite.scriptFile, "replace")
suite.Require().NoError(err, "should be able to update script file")

updatedProject, err := project.Get()
updatedProject, err := project.FromWD()
suite.Require().NoError(err, "unexpected error getting project")
v1, err := replace.Value()
suite.Require().NoError(err)
Expand Down
15 changes: 2 additions & 13 deletions internal/scriptrun/test/integration/scriptrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ scripts:
}
err = yaml.Unmarshal([]byte(contents), pjfile)
assert.Nil(t, err, "Unmarshalled YAML")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -103,7 +102,6 @@ func (suite *ScriptRunSuite) TestEnvIsSet() {

pjfile, err := projectfile.Parse(prjPath)
require.NoError(t, err, "parsing pjfile file")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -145,21 +143,20 @@ func (suite *ScriptRunSuite) TestRunNoProjectInheritance() {
project: "https://platform.activestate.com/ActiveState/pjfile"
scripts:
- name: run
value: echo $ACTIVESTATE_PROJECT
value: echo $ACTIVESTATE_ACTIVATED
standalone: true
`)
} else {
contents = strings.TrimSpace(`
project: "https://platform.activestate.com/ActiveState/pjfile"
scripts:
- name: run
value: echo %ACTIVESTATE_PROJECT%
value: echo %ACTIVESTATE_ACTIVATED%
standalone: true
`)
}
err = yaml.Unmarshal([]byte(contents), pjfile)
assert.Nil(t, err, "Unmarshalled YAML")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -193,7 +190,6 @@ scripts:
`)
err = yaml.Unmarshal([]byte(contents), pjfile)
assert.Nil(t, err, "Unmarshalled YAML")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -224,7 +220,6 @@ scripts:
`)
err = yaml.Unmarshal([]byte(contents), pjfile)
assert.Nil(t, err, "Unmarshalled YAML")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -283,7 +278,6 @@ scripts:
}
err = yaml.Unmarshal([]byte(contents), pjfile)
assert.Nil(t, err, "Unmarshalled YAML")
require.NoError(t, pjfile.Persist())

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand All @@ -294,9 +288,6 @@ scripts:
require.NoError(t, err)
err = scriptRun.Run(script, nil)
assert.NoError(t, err, "No error occurred")

// Reset.
projectfile.Reset()
}

func (suite *ScriptRunSuite) TestPathProvidesLang() {
Expand Down Expand Up @@ -376,8 +367,6 @@ func captureExecCommand(t *testing.T, tmplCmdName, cmdName string, cmdArgs []str
require.NoError(t, err)

pjfile := setupProjectWithScriptsExpectingArgs(t, tmplCmdName)
require.NoError(t, pjfile.Persist())
defer projectfile.Reset()

proj, err := project.New(pjfile, nil)
require.NoError(t, err)
Expand Down
10 changes: 2 additions & 8 deletions internal/subshell/subshell.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"runtime"
"strings"

"github.com/thoas/go-funk"

"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/logging"
Expand Down Expand Up @@ -116,11 +113,8 @@ func New(cfg sscommon.Configurable) SubShell {

logging.Debug("Using binary: %s", path)
subs.SetBinary(path)

env := funk.FilterString(os.Environ(), func(s string) bool {
return !strings.HasPrefix(s, constants.ProjectEnvVarName)
})
err := subs.SetEnv(osutils.EnvSliceToMap(env))

err := subs.SetEnv(osutils.EnvSliceToMap(os.Environ()))
if err != nil {
// We cannot error here, but this error will resurface when activating a runtime, so we can
// notify the user at that point.
Expand Down
42 changes: 0 additions & 42 deletions internal/subshell/subshell_lin_mac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,17 @@ package subshell

import (
"errors"
"fmt"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/testhelpers/osutil"
"github.com/ActiveState/cli/pkg/projectfile"
)

func TestRunCommandNoProjectEnv(t *testing.T) {
projectURL := fmt.Sprintf("https://%s/string/string", constants.PlatformURL)
pjfile := projectfile.Project{
Project: projectURL,
}
require.NoError(t, pjfile.Persist())

os.Setenv("SHELL", "bash")
os.Setenv("ACTIVESTATE_PROJECT", "SHOULD NOT BE SET")

cfg, err := config.New()
require.NoError(t, err)
subs := New(cfg)

data := []byte("#!/usr/bin/env bash\necho $ACTIVESTATE_PROJECT")
filename, err := fileutils.WriteTempFileToDir("", "testRunCommand", data, 0700)
require.NoError(t, err)
defer os.Remove(filename)

out, err := osutil.CaptureStdout(func() {
rerr := subs.Run(filename)
require.NoError(t, rerr)
})
require.NoError(t, err)
assert.Empty(t, strings.TrimSpace(out), "Should not echo anything cause the ACTIVESTATE_PROJECT should be undefined by the run command")

projectfile.Reset()
}

func TestRunCommandError(t *testing.T) {
projectURL := fmt.Sprintf("https://%s/string/string", constants.PlatformURL)
pjfile := projectfile.Project{
Project: projectURL,
}
require.NoError(t, pjfile.Persist())

os.Setenv("SHELL", "bash")

cfg, err := config.New()
Expand All @@ -75,6 +35,4 @@ func TestRunCommandError(t *testing.T) {
var eerr interface{ ExitCode() int }
require.True(t, errors.As(err, &eerr), "Error is exec exit error")
assert.Equal(t, eerr.ExitCode(), 2, "Returns exit code 2")

projectfile.Reset()
}
11 changes: 0 additions & 11 deletions internal/subshell/subshell_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package subshell

import (
"fmt"
"os"
"runtime"
"strings"
Expand All @@ -11,19 +10,11 @@ import (
"github.com/stretchr/testify/require"

"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/testhelpers/osutil"
"github.com/ActiveState/cli/pkg/projectfile"
)

func TestRunCommand(t *testing.T) {
projectURL := fmt.Sprintf("https://%s/string/string", constants.PlatformURL)
pjfile := projectfile.Project{
Project: projectURL,
}
require.NoError(t, pjfile.Persist())

data := []byte("echo Hello")
if runtime.GOOS == "windows" {
// Windows supports bash, but for the purpose of this test we only want to test cmd.exe, so ensure
Expand Down Expand Up @@ -51,6 +42,4 @@ func TestRunCommand(t *testing.T) {

trimmed := strings.TrimSpace(out)
assert.Equal(t, "Hello", trimmed[len(trimmed)-len("Hello"):])

projectfile.Reset()
}
45 changes: 0 additions & 45 deletions internal/subshell/subshell_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ package subshell

import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/environment"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/testhelpers/osutil"
"github.com/ActiveState/cli/pkg/projectfile"
)

func setup(t *testing.T) {
Expand Down Expand Up @@ -51,45 +46,7 @@ func TestBashDontEscapeSpace(t *testing.T) {
assert.Equal(t, `C:\Program Files\bash.exe`, subs.Binary())
}

func TestRunCommandNoProjectEnv(t *testing.T) {
projectURL := fmt.Sprintf("https://%s/string/string", constants.PlatformURL)
pjfile := projectfile.Project{
Project: projectURL,
}
err := pjfile.Persist()
require.NoError(t, err)
os.Setenv("ComSpec", "C:\\WINDOWS\\system32\\cmd.exe")
os.Setenv("ACTIVESTATE_PROJECT", "SHOULD NOT BE SET")
os.Unsetenv("SHELL")

cfg, err := config.New()
require.NoError(t, err)
subs := New(cfg)

data := []byte("echo --EMPTY-- %ACTIVESTATE_PROJECT% --EMPTY--")
filename, err := fileutils.WriteTempFileToDir("", "test*.bat", data, 0700)
require.NoError(t, err)
defer os.Remove(filename)

out, err := osutil.CaptureStdout(func() {
rerr := subs.Run(filename)
require.NoError(t, rerr)
})
require.NoError(t, err)
assert.Contains(t, out, "--EMPTY-- --EMPTY--", strings.TrimSpace(out),
"Should not echo anything cause the ACTIVESTATE_PROJECT should be undefined by the run command")

projectfile.Reset()
}

func TestRunCommandError(t *testing.T) {
projectURL := fmt.Sprintf("https://%s/string/string", constants.PlatformURL)
pjfile := projectfile.Project{
Project: projectURL,
}
err := pjfile.Persist()
require.NoError(t, err)

os.Unsetenv("SHELL")

cfg, err := config.New()
Expand All @@ -108,6 +65,4 @@ func TestRunCommandError(t *testing.T) {
var eerr interface{ ExitCode() int }
require.True(t, errors.As(err, &eerr), "Error is exec exit error")
assert.Equal(t, eerr.ExitCode(), 2, "Returns exit code 2")

projectfile.Reset()
}
2 changes: 1 addition & 1 deletion internal/testhelpers/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEn
constants.ConfigEnvVarName + "=" + dirs.Config,
constants.CacheEnvVarName + "=" + dirs.Cache,
constants.DisableRuntime + "=true",
constants.ProjectEnvVarName + "=",
constants.ActivatedStateEnvVarName + "=",
constants.E2ETestEnvVarName + "=true",
constants.DisableUpdates + "=true",
constants.OptinUnstableEnvVarName + "=true",
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/api/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func getProjectHost(service Service) *string {
return &testingPlatform
}

pj, err := projectfile.GetOnce()
pj, err := projectfile.FromEnv()
if err != nil {
return nil
}
Expand Down
Loading

0 comments on commit f511227

Please sign in to comment.