github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/cnbutils/project/resolve_path.go (about) 1 package project 2 3 import ( 4 "path/filepath" 5 6 "github.com/SAP/jenkins-library/pkg/cnbutils" 7 "github.com/SAP/jenkins-library/pkg/log" 8 ) 9 10 // 1. If "path" is a directory, check for "${path}/${descriptor}" 11 // 2. If "path" is a file, check for "${PWD}/${descriptor}" 12 func ResolvePath(descriptor, path string, utils cnbutils.BuildUtils) (string, error) { 13 isDir, err := utils.DirExists(path) 14 if err != nil { 15 return "", err 16 } 17 18 if isDir { 19 return getFilename(path, descriptor, utils) 20 } 21 22 pwd, err := utils.Getwd() 23 if err != nil { 24 return "", err 25 } 26 return getFilename(pwd, descriptor, utils) 27 } 28 29 func getFilename(folder, filename string, utils cnbutils.BuildUtils) (string, error) { 30 descPath := filepath.Join(folder, filename) 31 exists, err := utils.FileExists(descPath) 32 if err != nil { 33 return "", err 34 } 35 36 if exists { 37 return descPath, nil 38 } 39 40 log.Entry().Infof("Project descriptor with the path '%s' was not found", descPath) 41 return "", nil 42 }