Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
set the GOPATH correctly for test, compile steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Sep 12, 2019
1 parent eecdb2b commit 04835db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 13 additions & 6 deletions pkg/engine/engine_golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (g *engineGolang) CompileStep() error {

if terr := g.ExecuteCmdList("engine_cmd_compile",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Compile command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -161,7 +161,7 @@ func (g *engineGolang) TestStep() error {
//run lint command
if terr := g.ExecuteCmdList("engine_cmd_lint",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Lint command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -172,7 +172,7 @@ func (g *engineGolang) TestStep() error {
//code formatter
if terr := g.ExecuteCmdList("engine_cmd_fmt",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Format command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -184,7 +184,7 @@ func (g *engineGolang) TestStep() error {
//run test command
if terr := g.ExecuteCmdList("engine_cmd_test",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Test command (%s) failed. Check log for more details.",
); terr != nil {
Expand All @@ -196,7 +196,7 @@ func (g *engineGolang) TestStep() error {
//run security check command
if terr := g.ExecuteCmdList("engine_cmd_security_check",
g.PipelineData.GitLocalPath,
nil,
g.customGopathEnv(),
"",
"Dependency vulnerability check command (%s) failed. Check log for more details.",
); terr != nil {
Expand Down Expand Up @@ -229,10 +229,17 @@ func (g *engineGolang) customGopathEnv() []string {
updatedEnv := []string{fmt.Sprintf("GOPATH=%s", g.PipelineData.GolangGoPath)}

for i := range currentEnv {
if !strings.HasPrefix(currentEnv[i], "GOPATH=") { //add all environmental variables that are not GOPATH
if strings.HasPrefix(currentEnv[i], "GOPATH="){
//skip
continue
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", g.PipelineData.GolangGoPath, currentEnv[i]))
} else {
//add all environmental variables that are not GOPATH
updatedEnv = append(updatedEnv, currentEnv[i])
}
}

return updatedEnv
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/mgr/mgr_golang_dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ func (m *mgrGolangDep) MgrDependenciesStep(currentMetadata interface{}, nextMeta
if strings.HasPrefix(currentEnv[i], "GOPATH="){
//skip
continue
} else if (strings.HasPrefix(currentEnv[i], "PATH=")) {
} else if strings.HasPrefix(currentEnv[i], "PATH=") {
updatedEnv = append(updatedEnv, fmt.Sprintf("PATH=%s/bin:%s", m.PipelineData.GolangGoPath, currentEnv[i]))
} else {
//add all environmental variables that are not GOPATH
updatedEnv = append(updatedEnv, currentEnv[i])
}
}

print(updatedEnv)

if cerr := utils.BashCmdExec("dep ensure -v", m.PipelineData.GitLocalPath, updatedEnv, ""); cerr != nil {
return errors.EngineTestDependenciesError("dep ensure failed. Check dep dependencies")
}
Expand Down

0 comments on commit 04835db

Please sign in to comment.