-
Notifications
You must be signed in to change notification settings - Fork 444
/
find_latest_enterprise_version.go
76 lines (68 loc) · 2.03 KB
/
find_latest_enterprise_version.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
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"log"
"math"
"os"
errors "github.com/rotisserie/eris"
"github.com/solo-io/gloo/pkg/version"
"github.com/solo-io/go-utils/changelogutils"
"github.com/solo-io/go-utils/versionutils"
"github.com/solo-io/go-utils/vfsutils"
)
func main() {
ctx := context.Background()
repoRootPath := "."
owner := "solo-io"
repo := "gloo"
changelogDirPath := changelogutils.ChangelogDirectory
localVersion, err := getLargestLocalChangelogVersion(ctx, repoRootPath, owner, repo, changelogDirPath)
if err != nil {
log.Fatal(err)
}
// only version constraints we care about come from Gloo major/minor version
maxGlooEVersion := &versionutils.Version{
Major: localVersion.Major,
Minor: localVersion.Minor,
Patch: math.MaxInt32,
}
os.Mkdir("./_output", 0755)
f, err := os.Create("./_output/gloo-enterprise-version")
if err != nil {
log.Fatal(err)
}
defer f.Close()
enterpriseVersion, err := version.GetLatestHelmChartVersionWithMaxVersion(version.EnterpriseHelmRepoIndex, version.GlooEE, true, maxGlooEVersion)
if err != nil {
log.Fatal(err)
}
f.WriteString(enterpriseVersion)
f.Sync()
}
func getLargestLocalChangelogVersion(ctx context.Context, repoRootPath, owner, repo, changelogDirPath string) (*versionutils.Version, error) {
mountedRepo, err := vfsutils.NewLocalMountedRepoForFs(repoRootPath, owner, repo)
if err != nil {
return nil, changelogutils.MountLocalDirectoryError(err)
}
files, err := mountedRepo.ListFiles(ctx, changelogDirPath)
if err != nil {
return nil, changelogutils.ReadChangelogDirError(err)
}
zero := versionutils.Zero()
largestVersion := &zero
for _, file := range files {
if file.IsDir() {
curVersion, err := versionutils.ParseVersion(file.Name())
if err != nil {
continue
}
if curVersion.MustIsGreaterThan(*largestVersion) {
largestVersion = curVersion
}
}
}
if largestVersion == &zero {
return nil, errors.Errorf("unable to find any versions at repo root %v with changelog dir %v", repoRootPath, changelogDirPath)
}
return largestVersion, nil
}