forked from lmars/packer-post-processor-vagrant-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.go
67 lines (55 loc) · 1.44 KB
/
manifest.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
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"github.com/blang/semver"
)
const NoVersion = "0.0.0"
type Manifest struct {
Name string `json:"name"`
Versions []*Version `json:"versions"`
}
func (m *Manifest) add(version string, provider *Provider) error {
for _, w := range m.Versions {
if w.Version == version {
for _, p := range w.Providers {
if p.Name == provider.Name {
return fmt.Errorf("%s box already exists in manifest for version %s", p.Name, version)
}
}
w.Providers = append(w.Providers, provider)
return nil
}
}
m.Versions = append(m.Versions, &Version{
Version: version,
Providers: []*Provider{provider},
})
return nil
}
func (m *Manifest) getLatestVersion() string {
latestVersion, _ := semver.Make(NoVersion)
for _, version := range m.Versions {
if currentVersion, err := semver.Make(version.Version); err != nil {
continue
} else if latestVersion.LT(currentVersion) {
latestVersion = currentVersion
}
}
return latestVersion.String()
}
func (m *Manifest) getNextVersion() string {
latestVersion, _ := semver.Make(m.getLatestVersion())
latestVersion.Minor++
latestVersion.Patch = 0
return latestVersion.String()
}
type Version struct {
Version string `json:"version"`
Providers []*Provider `json:"providers"`
}
type Provider struct {
Name string `json:"name"`
Url string `json:"url"`
ChecksumType string `json:"checksum_type"`
Checksum string `json:"checksum"`
}