-
Notifications
You must be signed in to change notification settings - Fork 11
/
generate.go
74 lines (63 loc) · 2.36 KB
/
generate.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
package main
import (
"context"
"go.uber.org/zap"
"github.com/solo-io/go-utils/contextutils"
"github.com/solo-io/go-utils/errors"
version "github.com/solo-io/go-utils/versionutils"
"github.com/solo-io/solo-kit/pkg/code-generator/cmd"
"github.com/solo-io/solo-kit/pkg/code-generator/docgen/options"
)
//go:generate go run generate.go
func getInitialContext() context.Context {
loggingContext := []interface{}{"build script", "code generation"}
ctx := contextutils.WithLogger(context.Background(), "code generation")
return contextutils.WithLoggerValues(ctx, loggingContext...)
}
func main() {
ctx := getInitialContext()
if err := checkVersions(ctx); err != nil {
contextutils.LoggerFrom(ctx).Fatalw("generate failed", zap.Error(err))
}
contextutils.LoggerFrom(ctx).Infow("starting generate")
docsOpts := cmd.DocsOptions{
Output: options.Hugo,
}
if err := cmd.Run(".", true, &docsOpts, []string{"../supergloo"}, nil); err != nil {
contextutils.LoggerFrom(ctx).Fatalw("generate failed", zap.Error(err))
}
}
func checkVersions(ctx context.Context) error {
contextutils.LoggerFrom(ctx).Infow("Checking expected solo kit and gloo versions...")
tomlTree, err := version.ParseToml()
if err != nil {
return err
}
expectedGlooVersion, err := version.GetVersion(version.GlooPkg, tomlTree)
if err != nil {
return err
}
expectedSoloKitVersion, err := version.GetVersion(version.SoloKitPkg, tomlTree)
if err != nil {
return err
}
contextutils.LoggerFrom(ctx).Infow("Checking repo versions...")
actualGlooVersion, err := version.GetGitVersion("../gloo")
if err != nil {
return err
}
expectedTaggedGlooVersion := version.GetTag(expectedGlooVersion)
if expectedTaggedGlooVersion != actualGlooVersion {
return errors.Errorf("Expected gloo version %s, found gloo version %s in repo. Run 'make pin-repos' or fix manually.", expectedTaggedGlooVersion, actualGlooVersion)
}
actualSoloKitVersion, err := version.GetGitVersion("../solo-kit")
if err != nil {
return err
}
expectedTaggedSoloKitVersion := version.GetTag(expectedSoloKitVersion)
if expectedTaggedSoloKitVersion != actualSoloKitVersion {
return errors.Errorf("Expected solo kit version %s, found solo kit version %s in repo. Run 'make pin-repos' or fix manually.", expectedTaggedSoloKitVersion, actualSoloKitVersion)
}
contextutils.LoggerFrom(ctx).Infow("Versions are pinned correctly.")
return nil
}