From ba0a6c0908ded133f34f430aeadaa62f3eb395fd Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Thu, 8 Aug 2024 06:50:13 +0000 Subject: [PATCH] Add bash debug --- .github/workflows/run.e2e-tests.yml | 2 +- internal/manager/serverless/native.go | 32 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/run.e2e-tests.yml b/.github/workflows/run.e2e-tests.yml index 998f4597..2e50f57f 100644 --- a/.github/workflows/run.e2e-tests.yml +++ b/.github/workflows/run.e2e-tests.yml @@ -9,7 +9,7 @@ env: on: workflow_dispatch: - pull_request: +# pull_request: # Re-enable after nvm bug is fixed jobs: build: diff --git a/internal/manager/serverless/native.go b/internal/manager/serverless/native.go index 117913f8..8f7afff3 100644 --- a/internal/manager/serverless/native.go +++ b/internal/manager/serverless/native.go @@ -19,7 +19,7 @@ func (sls *Manager) runNpmInstall(w io.Writer) error { nvmDir = "$HOME/.nvm" } - command := fmt.Sprintf("source %s/nvm.sh && nvm use %s && npm install --save-dev", nvmDir, sls.App.NodeVersion) + command := fmt.Sprintf("source --debug %s/nvm.sh && nvm use %s && npm install --save-dev", nvmDir, sls.App.NodeVersion) if sls.App.UseYarn { command = npmToYarn(command) @@ -46,6 +46,16 @@ func (sls *Manager) nvm(w io.Writer, command string) error { nvmDir = "$HOME/.nvm" } + // Check if nvm.sh exists in the nvmDir + nvmShPath := filepath.Join(nvmDir, "nvm.sh") + if _, err := os.Stat(nvmShPath); os.IsNotExist(err) { + logrus.Debugf("nvm.sh does not exist in the directory:", nvmDir) + return err + } else if err != nil { + logrus.Debugf("Error checking nvm.sh:", err) + return err + } + // TODO: If nvm.sh doesn't exist in the nvmDir, we should install it // curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash @@ -54,9 +64,9 @@ func (sls *Manager) nvm(w io.Writer, command string) error { return err } - logrus.Debugf("Running: bash -c source %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, command) - cmd := exec.Command("bash", "-c", - fmt.Sprintf("source %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, command), + logrus.Debugf("Running: bash -c source --debug %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, command) + cmd := exec.Command("bash", "-xv", "-c", + fmt.Sprintf("source --debug %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, command), ) // Capture stderr in a buffer @@ -105,7 +115,7 @@ func (sls *Manager) runNvm(w io.Writer) error { return err } - command := fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion) + command := fmt.Sprintf("source --debug %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion) logrus.SetOutput(w) logrus.Debugf("command: %s", command) @@ -143,7 +153,7 @@ func (sls *Manager) runDeploy(w io.Writer) error { // SLS v3 has breaking changes in syntax if sls.App.ServerlessVersion == "3" { command = fmt.Sprintf( - `source %s/nvm.sh && + `source --debug %s/nvm.sh && nvm use %s && npx serverless deploy \ --config=%s \ @@ -157,7 +167,7 @@ func (sls *Manager) runDeploy(w io.Writer) error { sls.App.AwsProfile, sls.Project.Env) } else { command = fmt.Sprintf( - `source %s/nvm.sh && + `source --debug %s/nvm.sh && nvm use %s && npx serverless deploy \ --config %s \ @@ -218,7 +228,7 @@ func (sls *Manager) runRemove(w io.Writer) error { // SLS v3 has breaking changes in syntax if sls.App.ServerlessVersion == "3" { command = fmt.Sprintf( - `source %s/nvm.sh && \ + `source --debug %s/nvm.sh && \ nvm use %s && \ npx serverless remove \ --config=%s \ @@ -232,7 +242,7 @@ func (sls *Manager) runRemove(w io.Writer) error { sls.App.AwsProfile, sls.Project.Env) } else { command = fmt.Sprintf( - `source %s/nvm.sh && \ + `source --debug %s/nvm.sh && \ nvm use %s && \ npx serverless remove \ --config %s \ @@ -283,7 +293,7 @@ func (sls *Manager) runCreateDomain(w io.Writer) error { } command := fmt.Sprintf( - `source %s/nvm.sh && \ + `source --debug %s/nvm.sh && \ nvm use %s && \ npx serverless create_domain \ --verbose \ @@ -330,7 +340,7 @@ func (sls *Manager) runRemoveDomain(w io.Writer) error { } command := fmt.Sprintf( - `source %s/nvm.sh && \ + `source --debug %s/nvm.sh && \ nvm use %s && \ npx serverless delete_domain \ --verbose \