Skip to content

Commit

Permalink
Revert commit "Fix root module name handling in build info collection (
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Jul 30, 2024
1 parent a84d4ae commit 6a26a5e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 77 deletions.
8 changes: 2 additions & 6 deletions artifactory/commands/golang/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,9 @@ func (gc *GoCommand) run() (err error) {
if errorutils.CheckError(err) != nil {
return
}
var moduleName string
moduleName, err = gc.buildConfiguration.ResolveBaseModuleName()
if err != nil {
return
if gc.buildConfiguration.GetModule() != "" {
goModule.SetName(gc.buildConfiguration.GetModule())
}
goModule.SetName(moduleName)

err = errorutils.CheckError(goModule.CalcDependencies())
}

Expand Down
6 changes: 2 additions & 4 deletions artifactory/commands/golang/gopublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ func (gpc *GoPublishCommand) Run() error {
if err != nil {
return errorutils.CheckError(err)
}
moduleName, err := gpc.buildConfiguration.ResolveBaseModuleName()
if err != nil {
return err
if gpc.buildConfiguration.GetModule() != "" {
goModule.SetName(gpc.buildConfiguration.GetModule())
}
goModule.SetName(moduleName)
err = goModule.AddArtifacts(artifacts...)
if err != nil {
return errorutils.CheckError(err)
Expand Down
6 changes: 2 additions & 4 deletions artifactory/commands/npm/npmcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,9 @@ func (nc *NpmCommand) prepareBuildInfoModule() error {
return errorutils.CheckError(err)
}
nc.buildInfoModule.SetCollectBuildInfo(nc.collectBuildInfo)
moduleName, err := nc.buildConfiguration.ResolveBaseModuleName()
if err != nil {
return err
if nc.buildConfiguration.GetModule() != "" {
nc.buildInfoModule.SetName(nc.buildConfiguration.GetModule())
}
nc.buildInfoModule.SetName(moduleName)
return nil
}

Expand Down
8 changes: 2 additions & 6 deletions artifactory/commands/npm/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,9 @@ func (npc *NpmPublishCommand) Run() (err error) {
if err != nil {
return errorutils.CheckError(err)
}

moduleName, err := npc.buildConfiguration.ResolveBaseModuleName()
if err != nil {
return
if npc.buildConfiguration.GetModule() != "" {
npmModule.SetName(npc.buildConfiguration.GetModule())
}
npmModule.SetName(moduleName)

buildArtifacts, err := specutils.ConvertArtifactsDetailsToBuildInfoArtifacts(npc.artifactsDetailsReader)
if err != nil {
return err
Expand Down
6 changes: 2 additions & 4 deletions artifactory/commands/python/poetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ func (pc *PoetryCommand) install(buildConfiguration *buildUtils.BuildConfigurati
if err != nil {
return
}
moduleName, err := buildConfiguration.ResolveBaseModuleName()
if err != nil {
return
if buildConfiguration.GetModule() != "" {
pythonModule.SetName(buildConfiguration.GetModule())
}
pythonModule.SetName(moduleName)
var localDependenciesPath string
localDependenciesPath, err = config.GetJfrogDependenciesPath()
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions artifactory/commands/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ func (pc *PythonCommand) Run() (err error) {
if err != nil {
return
}
var moduleName string
moduleName, err = buildConfiguration.ResolveBaseModuleName()
if err != nil {
return
if buildConfiguration.GetModule() != "" {
pythonModule.SetName(buildConfiguration.GetModule())
}
pythonModule.SetName(moduleName)
var localDependenciesPath string
localDependenciesPath, err = config.GetJfrogDependenciesPath()
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions common/build/buildutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -462,18 +461,6 @@ func (bc *BuildConfiguration) IsLoadedFromConfigFile() bool {
return bc.loadedFromConfigFile
}

// ResolveBaseModuleName returns the module name to publish build info.
// If the module name is not specified, it falls back to the current working directory name.
// If the working directory cannot be retrieved, it defaults to "module".
// Module name is mandatory to publish build info.
func (bc *BuildConfiguration) ResolveBaseModuleName() (string, error) {
if bc.module != "" {
return bc.module, nil
}
wd, err := os.Getwd()
return path.Base(wd), errorutils.CheckError(err)
}

func PopulateBuildArtifactsAsPartials(buildArtifacts []buildInfo.Artifact, buildConfiguration *BuildConfiguration, moduleType buildInfo.ModuleType) error {
populateFunc := func(partial *buildInfo.Partial) {
partial.Artifacts = buildArtifacts
Expand Down
35 changes: 0 additions & 35 deletions common/build/buildutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package build
import (
biutils "github.com/jfrog/build-info-go/utils"
"os"
"path"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -246,37 +245,3 @@ func TestIsLoadedFromConfigFile(t *testing.T) {
assert.Equal(t, buildName, buildNameFile)
assert.Equal(t, buildNumber, artclientutils.LatestBuildNumberKey)
}

func TestBuildConfiguration_ResolveModuleName(t *testing.T) {
testCases := []struct {
name string
module string
}{
{
name: "Module is set",
module: "custom-module",
},
{
name: "Module not set, fallback to base directory name",
module: "",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Setup
bc := BuildConfiguration{module: tc.module}
// Execute
result, err := bc.ResolveBaseModuleName()
assert.NoError(t, err)
// Assert
if tc.module == "" {
wd, err := os.Getwd()
assert.NoError(t, err)
assert.Equal(t, path.Base(wd), result)
} else {
assert.Equal(t, tc.module, result)
}
})
}
}

0 comments on commit 6a26a5e

Please sign in to comment.