forked from grafana/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallback_version.go
38 lines (31 loc) · 963 Bytes
/
fallback_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
package main
import (
"bufio"
"bytes"
_ "embed"
"strings"
"github.com/grafana/alloy/internal/build"
)
//go:embed VERSION
var fallbackVersionText []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 fallbackVersionFromText(fallbackVersionText)
}
func fallbackVersionFromText(text []byte) string {
// Find the first line in fallbackVersionText which isn't a blank line or a
// line starting with #.
scanner := bufio.NewScanner(bytes.NewReader(text))
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if len(line) == 0 || strings.HasPrefix(line, "#") {
continue
}
return line + "-devel"
}
// We shouldn't hit this case since we always control the contents of the
// VERSION file, but just in case we'll return the existing version.
return build.Version
}