-
Notifications
You must be signed in to change notification settings - Fork 537
Expand file tree
/
Copy pathfallback_version.go
More file actions
35 lines (28 loc) · 934 Bytes
/
fallback_version.go
File metadata and controls
35 lines (28 loc) · 934 Bytes
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
package alloy
import (
_ "embed"
"encoding/json"
"github.com/grafana/alloy/internal/build"
)
//go:embed .release-please-manifest.json
var fallbackVersionJSON []byte
// fallbackVersion returns a version string to use for when the version isn't
// explicitly set at build time. The version string will always have -devel
// appended to it.
func FallbackVersion() string {
return fallbackVersionFromJSON(fallbackVersionJSON)
}
func fallbackVersionFromJSON(data []byte) string {
var manifest map[string]string
if err := json.Unmarshal(data, &manifest); err != nil {
// We shouldn't hit this case since we always control the contents of the
// manifest file, but just in case we'll return the existing version.
return build.Version
}
version, ok := manifest["."]
if !ok || version == "" {
return build.Version
}
// The manifest stores versions without the "v" prefix, so add it
return "v" + version + "-devel"
}