-
Notifications
You must be signed in to change notification settings - Fork 443
/
check.go
63 lines (55 loc) · 2.09 KB
/
check.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
package version
import (
errors "github.com/rotisserie/eris"
"github.com/solo-io/go-utils/log"
"github.com/solo-io/go-utils/versionutils"
"github.com/solo-io/go-utils/versionutils/dep"
gitutils "github.com/solo-io/go-utils/versionutils/git"
)
const SoloKitPkg = "github.com/solo-io/solo-kit"
var attributeTypes = map[dep.VersionType]string{
dep.Version: "version",
dep.Branch: "branch",
dep.Revision: "revision",
}
func CheckVersions() error {
tomlTree, err := versionutils.ParseFullToml()
if err != nil {
return err
}
log.Printf("Checking expected solo kit version...")
expectedVersion, err := versionutils.GetDependencyVersionInfo(SoloKitPkg, tomlTree)
if err != nil {
return err
}
log.Printf("Expecting solo-kit with %s [%s]", attributeTypes[expectedVersion.Type], expectedVersion.Version)
log.Printf("Checking repo versions...")
actualVersion, err := gitutils.GetGitRefInfo("../solo-kit")
if err != nil {
return err
}
log.Printf("Found solo-kit ref. Tag [%s], Branch [%s], Commit [%s]",
actualVersion.Tag, actualVersion.Branch, actualVersion.Hash)
switch expectedVersion.Type {
case dep.Version:
expectedTaggedVersion := gitutils.AppendTagPrefix(expectedVersion.Version)
if actualVersion.Tag != expectedTaggedVersion {
return errors.Errorf("Expected solo kit tag [%s], found solo kit tag [%s] in repo. "+
"Run 'make pin-repos' or fix manually.", expectedTaggedVersion, actualVersion.Tag)
}
case dep.Branch:
if actualVersion.Branch != expectedVersion.Version {
return errors.Errorf("Expected solo kit branch [%s], found solo kit branch [%s] in repo. "+
"Run 'make pin-repos' or fix manually.", expectedVersion.Version, actualVersion.Branch)
}
case dep.Revision:
if actualVersion.Hash != expectedVersion.Version {
return errors.Errorf("Expected solo kit revision [%s], found solo kit commit [%s] in repo. "+
"Run 'make pin-repos' or fix manually.", expectedVersion.Version, actualVersion.Hash)
}
default:
return errors.Errorf("Unexpected dep version attribute type: [%d]", expectedVersion.Type)
}
log.Printf("Versions are pinned correctly.")
return nil
}