mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CI: Fix broken nightly builds (#67705)
Sort objects in a bucket based on the generation timestamp
This commit is contained in:
parent
6570ec7afe
commit
04f1e344b1
@ -366,11 +366,17 @@ func GetLatestMainBuild(ctx context.Context, bucket *storage.BucketHandle, path
|
|||||||
return "", ErrorNilBucket
|
return "", ErrorNilBucket
|
||||||
}
|
}
|
||||||
|
|
||||||
it := bucket.Objects(ctx, &storage.Query{
|
query := &storage.Query{
|
||||||
Prefix: path,
|
Prefix: path,
|
||||||
})
|
}
|
||||||
|
err := query.SetAttrSelection([]string{"Name", "Generation"})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to set attribute selector, err: %q", err)
|
||||||
|
}
|
||||||
|
it := bucket.Objects(ctx, query)
|
||||||
|
|
||||||
var files []string
|
var files []string
|
||||||
|
var oldGeneration int64
|
||||||
for {
|
for {
|
||||||
attrs, err := it.Next()
|
attrs, err := it.Next()
|
||||||
if errors.Is(err, iterator.Done) {
|
if errors.Is(err, iterator.Done) {
|
||||||
@ -379,12 +385,16 @@ func GetLatestMainBuild(ctx context.Context, bucket *storage.BucketHandle, path
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to iterate through bucket, err: %w", err)
|
return "", fmt.Errorf("failed to iterate through bucket, err: %w", err)
|
||||||
}
|
}
|
||||||
|
if attrs.Generation >= oldGeneration {
|
||||||
files = append(files, attrs.Name)
|
files = append([]string{attrs.Name}, files...)
|
||||||
|
oldGeneration = attrs.Generation
|
||||||
|
} else {
|
||||||
|
files = append(files, attrs.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestVersion string
|
var latestVersion string
|
||||||
for i := len(files) - 1; i >= 0; i-- {
|
for i := 0; i < len(files); i++ {
|
||||||
captureVersion := regexp.MustCompile(`(\d+\.\d+\.\d+-\d+pre)`)
|
captureVersion := regexp.MustCompile(`(\d+\.\d+\.\d+-\d+pre)`)
|
||||||
if captureVersion.MatchString(files[i]) {
|
if captureVersion.MatchString(files[i]) {
|
||||||
latestVersion = captureVersion.FindString(files[i])
|
latestVersion = captureVersion.FindString(files[i])
|
||||||
|
Loading…
Reference in New Issue
Block a user