@@ -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 , "\n This 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}
0 commit comments