Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 15 additions & 23 deletions artifactory/commands/python/twine.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,11 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
if err != nil {
return err
}

defer func() {
if buildInfo != nil && err != nil {
err = errors.Join(err, buildInfo.Clean())
}
}()

var pythonModule *build.PythonModule
pythonModule, err = buildInfo.AddPythonModule("", pythonutils.Twine)
if err != nil {
Expand All @@ -170,7 +168,6 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
if tc.buildConfiguration.GetModule() != "" {
pythonModule.SetName(tc.buildConfiguration.GetModule())
}

artifacts, err := pythonModule.TwineUploadWithLogParsing(tc.args)
if err != nil {
return err
Expand All @@ -181,7 +178,6 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
if err = pythonModule.AddArtifacts(artifacts); err != nil {
return err
}

buildName, err := tc.buildConfiguration.GetBuildName()
if err != nil {
return err
Expand All @@ -190,45 +186,41 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
if err != nil {
return err
}

var fileInitials string
var filesSha256 []string
for _, arg := range artifacts {
if strings.HasSuffix(arg.Name, ".tar.gz") {
fileInitials = arg.Name
if arg.Sha256 != "" {
filesSha256 = append(filesSha256, arg.Sha256)
}
}

if len(filesSha256) == 0 {
return errors.New("could not find any files to upload")
}
searchParams := services.SearchParams{
CommonParams: &servicesUtils.CommonParams{
Aql: servicesUtils.Aql{
ItemsFind: CreateAqlQueryForSearch(tc.targetRepo, fileInitials),
ItemsFind: CreateAqlQueryForSearchBySHA256(tc.targetRepo, filesSha256),
},
},
}

servicesManager, err := rtUtils.CreateServiceManager(tc.serverDetails, -1, 0, false)
if err != nil {
return err
}

searchReader, err := servicesManager.SearchFiles(searchParams)
if err != nil {
log.Error("Failed to get uploaded twine package: ", err.Error())
return err
}

timestamp := strconv.FormatInt(buildInfo.GetBuildTimestamp().UnixNano()/int64(time.Millisecond), 10)
propsParams := services.PropsParams{
Reader: searchReader,
Props: fmt.Sprintf("build.name=%s;build.number=%s;build.timestamp=%s", buildName, buildNumber, timestamp),
}

_, err = servicesManager.SetProps(propsParams)
if err != nil {
log.Warn("Unable to set build properties: ", err, "\nThis may cause build to not properly link with artifact, please add build name and build number properties on the artifacts manually")
return err
}

log.Debug(fmt.Sprintf("Command finished successfully. %d artifacs were added to build info.", len(artifacts)))
return nil
}
Expand All @@ -248,16 +240,16 @@ func (tc *TwineCommand) getRepoConfigFlagProvidedErr() string {
return "twine command must not be executed with the following flags: " + coreutils.ListToText(twineRepoConfigFlags)
}

func CreateAqlQueryForSearch(repo, fileInitial string) string {
func CreateAqlQueryForSearchBySHA256(repo string, sha256s []string) string {
sha1Conditions := make([]string, len(sha256s))
for i, sha256 := range sha256s {
sha1Conditions[i] = fmt.Sprintf(`{"sha256": "%s"}`, sha256)
}
sha256Condition := strings.Join(sha1Conditions, ",")
itemsPart :=
`{` +
`"repo": "%s",` +
`"$or": [{` +
`"$and":[{` +
`"path": {"$match": "*"},` +
`"name": {"$match": "%s*"}` +
`}]` +
`}]` +
`"$or": [%s]` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we using the or and not and logical expression?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it can more than one files to search.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense, it's not logical operator in aql, can we try and compare response for and vs or

`}`
return fmt.Sprintf(itemsPart, repo, fileInitial)
return fmt.Sprintf(itemsPart, repo, sha256Condition)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/forPelevin/gomoji v1.4.1
github.com/google/go-containerregistry v0.20.7
github.com/jedib0t/go-pretty/v6 v6.7.5
github.com/jfrog/build-info-go v1.13.0
github.com/jfrog/build-info-go v1.13.1-0.20251230063402-e9f0a3564df1
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251
github.com/jfrog/jfrog-client-go v1.55.1-0.20251230061734-d954605bdb23
Expand Down Expand Up @@ -123,6 +123,6 @@ require (
sigs.k8s.io/yaml v1.6.0 // indirect
)

//replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20251223092904-9e9460642431
replace github.com/jfrog/build-info-go => github.com/naveenku-jfrog/build-info-go v1.12.1-0.20251229102022-065f0cbe8e9d

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251026182600-8a8c0428f538
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ github.com/jedib0t/go-pretty/v6 v6.7.5 h1:9dJSWTJnsXJVVAbvxIFxeHf/JxoJd7GUl5o3Uz
github.com/jedib0t/go-pretty/v6 v6.7.5/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.13.0 h1:bHedp1Gl+a8eR71xxP5JvkqwDj2X3r6e5NiIwNcIwRM=
github.com/jfrog/build-info-go v1.13.0/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
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-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251 h1:WTyDOaYJUwY6zQujZuL9JQ9Q9+QWj9p31tLb4bJnu4U=
Expand Down Expand Up @@ -215,6 +213,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/naveenku-jfrog/build-info-go v1.12.1-0.20251229102022-065f0cbe8e9d h1:gcZZJLZ+B9vQUluCI/qFjHi6XZhwFueaPIlgcdqFaaE=
github.com/naveenku-jfrog/build-info-go v1.12.1-0.20251229102022-065f0cbe8e9d/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
Expand Down