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

[CLI] call nvm use before each npm call on CI #220

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions gbm-cli/cmd/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func NewWorkspace() (Workspace, error) {
console.Info("GBM_NO_WORKSPACE is set, not creating a workspace directory")
w.disabled = true
}

if os.Getenv("CI") == "true" {
console.Info("CI environment detected, not creating a workspace directory")
w.disabled = true
w.dir = "."
}

if err := w.create(); err != nil {
return nil, err
}
Expand Down
13 changes: 12 additions & 1 deletion gbm-cli/pkg/shell/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ func execute(cmd *exec.Cmd, dir string, verbose bool) error {
func NewNpmCmd(cp CmdProps) NpmCmds {
return &client{
cmd: func(cmds ...string) error {
cmd := exec.Command("npm", cmds...)
var cmd *exec.Cmd

// If we are running on a CI and NVM is available we run `nvm use` before each npm command
// to make sure we are using the correct node version
ci := os.Getenv("CI")
if ci == "true" && os.Getenv("NVM_DIR") != "" {
withNvmUse := append([]string{"-l", "-c", "nvm use && npm"}, cmds...)
cmd = exec.Command("bash", withNvmUse...)
} else {
cmd = exec.Command("npm", cmds...)
}

return execute(cmd, cp.Dir, cp.Verbose)
},
cmdInPath: func(path string, cmds ...string) error {
Expand Down
Loading