forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.go
78 lines (69 loc) · 2.4 KB
/
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
77
78
package github_action_utils
import (
"context"
"math"
"os"
"github.com/pkg/errors"
"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"
)
// GetLatestEnterpriseVersion computes the latest Gloo Enterprise version.
// It is intended to be used by the Makefile.docs, ostensibly as a variable for
// filling out correctly-referenced enterprise docs
func GetLatestEnterpriseVersion(repoRootPath string, repo string, owner string) error {
ctx := context.Background()
localVersion, err := getLargestLocalChangelogVersion(ctx, repoRootPath, owner, repo, changelogutils.ChangelogDirectory)
if err != nil {
return 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 {
return err
}
defer f.Close()
// get the latest version from the helm repo, include unstable versions so it works from the main branches
// for LTS branches, unstable versions will be filtered out by the version constraints
enterpriseVersion, err := version.GetLatestHelmChartVersionWithMaxVersion(version.EnterpriseHelmRepoIndex, version.GlooEE, false, maxGlooEVersion)
if err != nil {
return err
}
f.WriteString(enterpriseVersion)
f.Sync()
return nil
}
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
}