-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbump.go
59 lines (52 loc) · 1.36 KB
/
bump.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"github.com/binxio/fromage/tag"
"github.com/google/go-containerregistry/pkg/name"
)
type Bumper struct {
bumpReferences map[string]string
bumpOrder []string
dryRun bool
}
func (b *Bumper) orderDepth(ref string) int {
if v, ok := b.bumpReferences[ref]; ok && v != ref {
return b.orderDepth(v) + 1
} else {
return 0
}
}
func (b *Bumper) DetermineBumpOrder() {
var highest = 0
var ordered = make(map[int][]string, len(b.bumpReferences))
for ref, _ := range b.bumpReferences {
depth := b.orderDepth(ref)
if depth > highest {
highest = depth
}
if v, ok := ordered[depth]; ok {
ordered[depth] = append(v, ref)
} else {
ordered[depth] = []string{ref}
}
}
for depth := 1; depth <= highest; depth = depth + 1 {
if v, ok := ordered[depth]; ok {
b.bumpOrder = append(b.bumpOrder, v...)
}
}
}
func MakeBumper(references []name.Reference, pin *tag.Level, latest bool) Bumper {
var result = Bumper{make(map[string]string, len(references)),
make([]string, 0, len(references)), false}
for _, r := range references {
if tagRef, ok := r.(name.Tag); ok {
if nextTag, err := tag.GetNextVersion(tagRef, pin, latest); err == nil {
result.bumpReferences[r.String()] = nextTag.String()
} else {
// skip references which do not have a next version
}
}
}
result.DetermineBumpOrder()
return result
}