Skip to content

Commit 049e011

Browse files
Fix/rteco 562 jf twine incorrectly applies build properties to similar named files (#331)
1 parent a3f96d1 commit 049e011

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

artifactory/commands/python/twine.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,11 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
155155
if err != nil {
156156
return err
157157
}
158-
159158
defer func() {
160159
if buildInfo != nil && err != nil {
161160
err = errors.Join(err, buildInfo.Clean())
162161
}
163162
}()
164-
165163
var pythonModule *build.PythonModule
166164
pythonModule, err = buildInfo.AddPythonModule("", pythonutils.Twine)
167165
if err != nil {
@@ -170,7 +168,6 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
170168
if tc.buildConfiguration.GetModule() != "" {
171169
pythonModule.SetName(tc.buildConfiguration.GetModule())
172170
}
173-
174171
artifacts, err := pythonModule.TwineUploadWithLogParsing(tc.args)
175172
if err != nil {
176173
return err
@@ -181,7 +178,6 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
181178
if err = pythonModule.AddArtifacts(artifacts); err != nil {
182179
return err
183180
}
184-
185181
buildName, err := tc.buildConfiguration.GetBuildName()
186182
if err != nil {
187183
return err
@@ -190,45 +186,41 @@ func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
190186
if err != nil {
191187
return err
192188
}
193-
194-
var fileInitials string
189+
var filesSha256 []string
195190
for _, arg := range artifacts {
196-
if strings.HasSuffix(arg.Name, ".tar.gz") {
197-
fileInitials = arg.Name
191+
if arg.Sha256 != "" {
192+
filesSha256 = append(filesSha256, arg.Sha256)
198193
}
199194
}
200-
195+
if len(filesSha256) == 0 {
196+
return errors.New("could not find any files to upload")
197+
}
201198
searchParams := services.SearchParams{
202199
CommonParams: &servicesUtils.CommonParams{
203200
Aql: servicesUtils.Aql{
204-
ItemsFind: CreateAqlQueryForSearch(tc.targetRepo, fileInitials),
201+
ItemsFind: CreateAqlQueryForSearchBySHA256(tc.targetRepo, filesSha256),
205202
},
206203
},
207204
}
208-
209205
servicesManager, err := rtUtils.CreateServiceManager(tc.serverDetails, -1, 0, false)
210206
if err != nil {
211207
return err
212208
}
213-
214209
searchReader, err := servicesManager.SearchFiles(searchParams)
215210
if err != nil {
216211
log.Error("Failed to get uploaded twine package: ", err.Error())
217212
return err
218213
}
219-
220214
timestamp := strconv.FormatInt(buildInfo.GetBuildTimestamp().UnixNano()/int64(time.Millisecond), 10)
221215
propsParams := services.PropsParams{
222216
Reader: searchReader,
223217
Props: fmt.Sprintf("build.name=%s;build.number=%s;build.timestamp=%s", buildName, buildNumber, timestamp),
224218
}
225-
226219
_, err = servicesManager.SetProps(propsParams)
227220
if err != nil {
228221
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")
229222
return err
230223
}
231-
232224
log.Debug(fmt.Sprintf("Command finished successfully. %d artifacs were added to build info.", len(artifacts)))
233225
return nil
234226
}
@@ -248,16 +240,16 @@ func (tc *TwineCommand) getRepoConfigFlagProvidedErr() string {
248240
return "twine command must not be executed with the following flags: " + coreutils.ListToText(twineRepoConfigFlags)
249241
}
250242

251-
func CreateAqlQueryForSearch(repo, fileInitial string) string {
243+
func CreateAqlQueryForSearchBySHA256(repo string, sha256s []string) string {
244+
sha1Conditions := make([]string, len(sha256s))
245+
for i, sha256 := range sha256s {
246+
sha1Conditions[i] = fmt.Sprintf(`{"sha256": "%s"}`, sha256)
247+
}
248+
sha256Condition := strings.Join(sha1Conditions, ",")
252249
itemsPart :=
253250
`{` +
254251
`"repo": "%s",` +
255-
`"$or": [{` +
256-
`"$and":[{` +
257-
`"path": {"$match": "*"},` +
258-
`"name": {"$match": "%s*"}` +
259-
`}]` +
260-
`}]` +
252+
`"$or": [%s]` +
261253
`}`
262-
return fmt.Sprintf(itemsPart, repo, fileInitial)
254+
return fmt.Sprintf(itemsPart, repo, sha256Condition)
263255
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/forPelevin/gomoji v1.4.1
88
github.com/google/go-containerregistry v0.20.7
99
github.com/jedib0t/go-pretty/v6 v6.7.5
10-
github.com/jfrog/build-info-go v1.13.0
10+
github.com/jfrog/build-info-go v1.13.1-0.20251230063402-e9f0a3564df1
1111
github.com/jfrog/gofrog v1.7.6
1212
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251
1313
github.com/jfrog/jfrog-client-go v1.55.1-0.20251230061734-d954605bdb23
@@ -123,6 +123,6 @@ require (
123123
sigs.k8s.io/yaml v1.6.0 // indirect
124124
)
125125

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

128128
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251026182600-8a8c0428f538

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ github.com/jedib0t/go-pretty/v6 v6.7.5 h1:9dJSWTJnsXJVVAbvxIFxeHf/JxoJd7GUl5o3Uz
162162
github.com/jedib0t/go-pretty/v6 v6.7.5/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
163163
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
164164
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
165-
github.com/jfrog/build-info-go v1.13.0 h1:bHedp1Gl+a8eR71xxP5JvkqwDj2X3r6e5NiIwNcIwRM=
166-
github.com/jfrog/build-info-go v1.13.0/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
167165
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
168166
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
169167
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251 h1:WTyDOaYJUwY6zQujZuL9JQ9Q9+QWj9p31tLb4bJnu4U=
@@ -215,6 +213,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
215213
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
216214
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
217215
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
216+
github.com/naveenku-jfrog/build-info-go v1.12.1-0.20251229102022-065f0cbe8e9d h1:gcZZJLZ+B9vQUluCI/qFjHi6XZhwFueaPIlgcdqFaaE=
217+
github.com/naveenku-jfrog/build-info-go v1.12.1-0.20251229102022-065f0cbe8e9d/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
218218
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
219219
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
220220
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=

0 commit comments

Comments
 (0)