This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.14 by this push:
     new 6de7e2cf7 fix: the dbt plugin change the working directory (#3976)
6de7e2cf7 is described below

commit 6de7e2cf776ad58fbd4ff66bca4716b9c2ccd74e
Author: abeizn <[email protected]>
AuthorDate: Tue Dec 20 17:25:05 2022 +0800

    fix: the dbt plugin change the working directory (#3976)
    
    * fix: the dbt plugin change the working directory
    
    * fix: the dbt plugin change the working directory and use filepath.Join
    
    * fix: the dbt plugin change the working directory and use filepath.Join
---
 plugins/dbt/tasks/convertor.go | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/plugins/dbt/tasks/convertor.go b/plugins/dbt/tasks/convertor.go
index ca5defa80..cd6580256 100644
--- a/plugins/dbt/tasks/convertor.go
+++ b/plugins/dbt/tasks/convertor.go
@@ -24,6 +24,7 @@ import (
        "net/url"
        "os"
        "os/exec"
+       "path/filepath"
        "strconv"
        "strings"
 
@@ -55,11 +56,8 @@ func DbtConverter(taskCtx core.SubTaskContext) errors.Error {
        profilesPath := data.Options.ProfilesPath
        profile := data.Options.Profile
 
-       err := errors.Convert(os.Chdir(projectPath))
-       if err != nil {
-               return err
-       }
-       _, err = errors.Convert01(os.Stat("profiles.yml"))
+       defaultProfilesPath := filepath.Join(projectPath, "profiles.yml")
+       _, err := errors.Convert01(os.Stat(defaultProfilesPath))
        // if profiles.yml not exist, create it manually
        if err != nil {
                dbUrl := taskCtx.GetConfig("DB_URL")
@@ -108,13 +106,14 @@ func DbtConverter(taskCtx core.SubTaskContext) 
errors.Error {
                        
config.Set(projectName+".outputs."+projectTarget+".user", dbUsername)
                        
config.Set(projectName+".outputs."+projectTarget+".dbname", dbDataBase)
                }
-               err = errors.Convert(config.WriteConfigAs("profiles.yml"))
+               err = errors.Convert(config.WriteConfigAs(defaultProfilesPath))
                if err != nil {
                        return err
                }
        }
        // if package.yml exist, install dbt dependencies
-       _, err = errors.Convert01(os.Stat("packages.yml"))
+       defaultPackagesPath := filepath.Join(projectPath, "packages.yml")
+       _, err = errors.Convert01(os.Stat(defaultPackagesPath))
        if err == nil {
                cmd := exec.Command("dbt", "deps")
                err = errors.Convert(cmd.Start())
@@ -172,6 +171,10 @@ func DbtConverter(taskCtx core.SubTaskContext) 
errors.Error {
        if profilesPath != "" {
                dbtExecParams = append(dbtExecParams, "--profiles-dir")
                dbtExecParams = append(dbtExecParams, profilesPath)
+       } else {
+               // default projectPath
+               dbtExecParams = append(dbtExecParams, "--profiles-dir")
+               dbtExecParams = append(dbtExecParams, projectPath)
        }
        if profile != "" {
                dbtExecParams = append(dbtExecParams, "--profile")

Reply via email to