-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.go
52 lines (40 loc) · 864 Bytes
/
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
//go:build ignore
package main
import (
"fmt"
"io/ioutil"
"golang.org/x/mod/modfile"
)
const depVersions = `// Package config - DO NOT EDIT
package config
const (
vaultAPIVersion = "%v"
vaultSDKVersion = "%v"
)
`
func main() {
var f *modfile.File
var fb []byte
var err error
vApi, vSdk := "", ""
if fb, err = ioutil.ReadFile("go.mod"); err != nil {
panic(err)
}
if f, err = modfile.Parse("go.mod", fb, nil); err != nil {
panic(err)
}
for _, mod := range f.Require {
if mod.Indirect {
continue
}
switch mod.Mod.Path {
case "github.com/hashicorp/vault/api":
vApi = mod.Mod.Version
case "github.com/hashicorp/vault/sdk":
vSdk = mod.Mod.Version
}
}
if err := ioutil.WriteFile("config/versions.go", []byte(fmt.Sprintf(depVersions, vApi, vSdk)), 0o644); err != nil {
panic("failed writing config/versions.go")
}
}