Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common/build/buildutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import (

const (
BuildInfoDetails = "details"
BuildTempPath = "jfrog/builds/"
ProjectConfigBuildNameKey = "name"
)

func CreateBuildInfoService() *build.BuildInfoService {
buildInfoService := build.NewBuildInfoService()
buildInfoService.SetTempDirPath(filepath.Join(coreutils.GetCliPersistentTempDirPath(), BuildTempPath))
buildInfoService.SetTempDirPath(filepath.Join(coreutils.GetCliPersistentTempDirPath(), buildInfoService.GetUserSpecificBuildDirName()))
buildInfoService.SetLogger(log.Logger)
return buildInfoService
}
Expand Down Expand Up @@ -66,7 +65,8 @@ func PrepareBuildPrerequisites(buildConfiguration *BuildConfiguration) (build *b

func GetBuildDir(buildName, buildNumber, projectKey string) (string, error) {
hash := sha256.Sum256([]byte(buildName + "_" + buildNumber + "_" + projectKey))
buildsDir := filepath.Join(coreutils.GetCliPersistentTempDirPath(), BuildTempPath, hex.EncodeToString(hash[:]))
buildsDir := filepath.Join(coreutils.GetCliPersistentTempDirPath(),
build.NewBuildInfoService().GetUserSpecificBuildDirName(), hex.EncodeToString(hash[:]))
err := os.MkdirAll(buildsDir, 0777)
if errorutils.CheckError(err) != nil {
return "", err
Expand Down
106 changes: 105 additions & 1 deletion common/build/buildutils_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package build

import (
biutils "github.com/jfrog/build-info-go/utils"
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
"testing"
"time"

biutils "github.com/jfrog/build-info-go/utils"

"github.com/jfrog/build-info-go/build"
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
artclientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var timestamp = strconv.FormatInt(time.Now().Unix(), 10)
Expand Down Expand Up @@ -245,3 +250,102 @@ func TestIsLoadedFromConfigFile(t *testing.T) {
assert.Equal(t, buildName, buildNameFile)
assert.Equal(t, buildNumber, artclientutils.LatestBuildNumberKey)
}

func TestCreateBuildInfoService(t *testing.T) {
service := CreateBuildInfoService()

// Service should not be nil
require.NotNil(t, service, "CreateBuildInfoService should not return nil")

// Get the user-specific build directory name
userSpecificDir := service.GetUserSpecificBuildDirName()
assert.NotEmpty(t, userSpecificDir, "User-specific build directory should not be empty")

// Should contain "jfrog-" prefix (user-specific path)
assert.True(t, strings.Contains(userSpecificDir, build.BuildsJfrogPath),
"Build directory should contain '%s', got: %s", build.BuildsJfrogPath, userSpecificDir)

// Should contain "builds" directory
assert.True(t, strings.Contains(userSpecificDir, build.BuildsDirPath),
"Build directory should contain '%s', got: %s", build.BuildsDirPath, userSpecificDir)
}

func TestCreateBuildInfoServiceContainsUsername(t *testing.T) {
currentUser, err := user.Current()
require.NoError(t, err, "Failed to get current user")

service := CreateBuildInfoService()
userSpecificDir := service.GetUserSpecificBuildDirName()

// The path should contain the current username
expectedPrefix := build.BuildsJfrogPath + currentUser.Username
assert.True(t, strings.Contains(userSpecificDir, expectedPrefix),
"Build directory should contain '%s', got: %s", expectedPrefix, userSpecificDir)
}

func TestGetBuildDir(t *testing.T) {
const testBuildName = "test-build-dir"
const testBuildNumber = "1"
const testProjectKey = ""

// Get the build directory
buildDir, err := GetBuildDir(testBuildName, testBuildNumber, testProjectKey)
require.NoError(t, err, "GetBuildDir should not return error")

// Cleanup after test
defer func() {
// Remove the created directory
_ = os.RemoveAll(buildDir)
}()

// Directory should be created
assert.DirExists(t, buildDir, "Build directory should be created")

// Path should contain user-specific directory
assert.True(t, strings.Contains(buildDir, build.BuildsJfrogPath),
"Build directory path should contain '%s', got: %s", build.BuildsJfrogPath, buildDir)

// Path should start with CLI persistent temp dir
assert.True(t, strings.HasPrefix(buildDir, coreutils.GetCliPersistentTempDirPath()),
"Build directory should be under CLI temp dir. Got: %s, Expected prefix: %s",
buildDir, coreutils.GetCliPersistentTempDirPath())
}

func TestGetBuildDirUserIsolation(t *testing.T) {
currentUser, err := user.Current()
require.NoError(t, err, "Failed to get current user")

buildDir, err := GetBuildDir("isolation-test", "1", "")
require.NoError(t, err)

// Cleanup after test
defer func() {
_ = os.RemoveAll(buildDir)
}()

// Path should contain user-specific directory with username
expectedUserDir := build.BuildsJfrogPath + currentUser.Username
assert.True(t, strings.Contains(buildDir, expectedUserDir),
"Build directory should contain user-specific path '%s', got: %s", expectedUserDir, buildDir)
}

func TestGetBuildDirDifferentBuildsGetDifferentPaths(t *testing.T) {
// Create two different builds
buildDir1, err := GetBuildDir("build-a", "1", "")
require.NoError(t, err)
defer func() { _ = os.RemoveAll(buildDir1) }()

buildDir2, err := GetBuildDir("build-b", "1", "")
require.NoError(t, err)
defer func() { _ = os.RemoveAll(buildDir2) }()

// Different builds should get different directories (different hash)
assert.NotEqual(t, buildDir1, buildDir2,
"Different builds should have different directories")

// But both should be under the same user-specific parent
parent1 := filepath.Dir(buildDir1)
parent2 := filepath.Dir(buildDir2)
assert.Equal(t, parent1, parent2,
"Different builds should share the same user-specific parent directory")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jfrog/jfrog-cli-core/v2

go 1.25.4
go 1.25.5

require github.com/c-bata/go-prompt v0.2.6 // Should not be updated to 0.2.6 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)

Expand Down Expand Up @@ -94,6 +94,6 @@ require (

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go master

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go dev
replace github.com/jfrog/build-info-go => github.com/fluxxBot/build-info-go v1.10.10-0.20260105064157-73c3f6f22ba2

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fluxxBot/build-info-go v1.10.10-0.20260105064157-73c3f6f22ba2 h1:sl57U4M1Bw/GrcjesOBZszfMOrB2dzsfx9DPyrBreZY=
github.com/fluxxBot/build-info-go v1.10.10-0.20260105064157-73c3f6f22ba2/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
github.com/forPelevin/gomoji v1.4.1 h1:7U+Bl8o6RV/dOQz7coQFWj/jX6Ram6/cWFOuFDEPEUo=
github.com/forPelevin/gomoji v1.4.1/go.mod h1:mM6GtmCgpoQP2usDArc6GjbXrti5+FffolyQfGgPboQ=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down Expand Up @@ -94,8 +96,6 @@ github.com/jedib0t/go-pretty/v6 v6.6.8 h1:JnnzQeRz2bACBobIaa/r+nqjvws4yEhcmaZ4n1
github.com/jedib0t/go-pretty/v6 v6.6.8/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
github.com/jfrog/build-info-go v1.8.9-0.20251223092904-9e9460642431 h1:HyGqdD957CrW6T1Xst0CxTR0XqJ0baIo/uL4I5lhyuo=
github.com/jfrog/build-info-go v1.8.9-0.20251223092904-9e9460642431/go.mod h1:9W4U440fdTHwW1HiB/R0VQvz/5q8ZHsms9MWcq+JrdY=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/jfrog/jfrog-client-go v1.55.1-0.20251223101502-1a13a993b0c7 h1:5JUiqmBV9ikFOZEH+ZgvJLHshT1aAuw08bfdJOLHbzQ=
Expand Down
Loading