/
versions.go
65 lines (55 loc) · 1.08 KB
/
versions.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
/*
Library for parsing versions.yaml file.
*/
package versions
import (
"fmt"
"io/ioutil"
"log"
yaml "gopkg.in/yaml.v2"
)
type Package struct {
Version string
Major string
Gpg string
Sha1 string
Sha256 string
Md5 string
}
type Version struct {
Dir string
Repo string
Tags []string
From string
Cmd string
Packages map[string]Package
ExcludeTests []string `yaml:"excludeTests"`
}
type Spec struct {
Versions []Version
}
func LoadVersions(path string) Spec {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("error: %v", err)
}
spec := Spec{}
err = yaml.Unmarshal([]byte(data), &spec)
if err != nil {
log.Fatalf("error: %v", err)
}
validateUniqueTags(spec)
return spec
}
func validateUniqueTags(spec Spec) {
repoTags := make(map[string]bool)
for _, version := range spec.Versions {
for _, tag := range version.Tags {
repoTag := fmt.Sprintf("%s:%s", version.Repo, tag)
if repoTags[repoTag] {
log.Fatalf("error: duplicate repo tag %v", repoTag)
}
repoTags[repoTag] = true
}
}
}