Skip to content

Commit 6cdeff4

Browse files
aorabdelacabarbaye
andauthored
✨ Improve artefact manager download methods by adding download options (#126)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Proprietary --> ### Description <!-- Please add any detail or context that would be useful to a reviewer. --> ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [ ] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update). --------- Co-authored-by: aorabdel <[email protected]> Co-authored-by: Adrien CABARBAYE <[email protected]>
1 parent 6acffce commit 6cdeff4

File tree

11 files changed

+383
-174
lines changed

11 files changed

+383
-174
lines changed

.goreleaser.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: 2
12
env:
23
- GO111MODULE=on
34
# Commented out because requires Pro features
@@ -19,7 +20,7 @@ archives:
1920
checksum:
2021
name_template: 'checksums.txt'
2122
snapshot:
22-
name_template: "{{ incpatch .Tag }}-dev"
23+
version_template: "{{ incpatch .Tag }}-dev"
2324
changelog:
2425
sort: asc
2526
filters:

changes/20251024142639.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: Improve artefact manager download methods by adding download options

changes/20251024143330.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:bug: Update goreleaser yaml to work with version 2

changes/20251024152328.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:camel: Upgrade dependencies

utils/artefacts/artefacts.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,16 @@ func (m *ArtefactManager[M, D, L, C]) DownloadAllJobArtefacts(ctx context.Contex
332332
}
333333

334334
func (m *ArtefactManager[M, D, L, C]) DownloadAllJobArtefactsWithTree(ctx context.Context, jobName string, maintainTreeStructure bool, outputDirectory string) (err error) {
335+
return m.DownloadAllJobArtefactsWithOptions(ctx, jobName, outputDirectory, WithMaintainStructure(maintainTreeStructure))
336+
}
337+
338+
func (m *ArtefactManager[M, D, L, C]) DownloadAllJobArtefactsWithOptions(ctx context.Context, jobName string, outputDirectory string, opts ...DownloadOption) (err error) {
335339
err = parallelisation.DetermineContextError(ctx)
336340
if err != nil {
337341
return
338342
}
343+
344+
dlOpts := NewDownloadOptions(opts...)
339345
err = filesystem.MkDir(outputDirectory)
340346
if err != nil {
341347
err = commonerrors.WrapErrorf(commonerrors.ErrUnexpected, err, "failed creating the output directory [%v] for job artefacts", outputDirectory)
@@ -347,37 +353,48 @@ func (m *ArtefactManager[M, D, L, C]) DownloadAllJobArtefactsWithTree(ctx contex
347353
}
348354
stop := paginator.Stop()
349355
defer stop()
356+
var collatedDownloadErrors []error
350357
for {
351358
if !paginator.HasNext() {
359+
if len(collatedDownloadErrors) > 0 {
360+
err = commonerrors.Join(collatedDownloadErrors...)
361+
}
352362
return
353363
}
354364
item, subErr := paginator.GetNext()
355365
if subErr != nil {
356366
err = commonerrors.WrapError(commonerrors.ErrUnexpected, subErr, "failed getting information about job artefacts")
357367
return
358368
}
369+
var artefactName string
370+
var downloadErr error
359371
artefactLink, ok := item.(D)
360372
if ok {
361-
subErr = m.DownloadJobArtefactFromLinkWithTree(ctx, jobName, maintainTreeStructure, outputDirectory, artefactLink)
362-
if subErr != nil {
363-
err = subErr
364-
return
365-
}
366-
373+
artefactName = artefactLink.GetName()
374+
downloadErr = m.DownloadJobArtefactFromLinkWithTree(ctx, jobName, dlOpts.MaintainTreeStructure, outputDirectory, artefactLink)
367375
} else {
368-
artefactManager, ok := item.(M)
369-
if ok {
370-
subErr = m.DownloadJobArtefactWithTree(ctx, jobName, maintainTreeStructure, outputDirectory, artefactManager)
371-
if subErr != nil {
372-
err = subErr
373-
return
374-
}
376+
artefactManager, isManager := item.(M)
377+
if isManager {
378+
artefactName = artefactManager.GetName()
379+
downloadErr = m.DownloadJobArtefactWithTree(ctx, jobName, dlOpts.MaintainTreeStructure, outputDirectory, artefactManager)
375380
} else {
376-
err = commonerrors.New(commonerrors.ErrMarshalling, "the type of the response from service cannot be interpreted")
377-
return
381+
downloadErr = commonerrors.New(commonerrors.ErrMarshalling, "the type of the response from service cannot be interpreted")
378382
}
379-
380383
}
381384

385+
if downloadErr != nil {
386+
if dlOpts.StopOnFirstError {
387+
err = downloadErr
388+
return
389+
}
390+
collatedDownloadErrors = append(collatedDownloadErrors, downloadErr)
391+
if dlOpts.Logger != nil {
392+
dlOpts.Logger.LogError(downloadErr)
393+
}
394+
} else if !reflection.IsEmpty(artefactName) {
395+
if dlOpts.Logger != nil {
396+
dlOpts.Logger.Log(fmt.Sprintf("downloading %s", artefactName))
397+
}
398+
}
382399
}
383400
}

0 commit comments

Comments
 (0)