Skip to content

Commit 2f3fdc6

Browse files
committed
use new build version feature
1 parent e7a1095 commit 2f3fdc6

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ Use any of the following for a pain-free installation:
1818
```
1919
The benefit of this method is that re-running the command will always update to the latest version.
2020
* You can download a pre-built binary from the [releases] page.
21-
* If you have the [`gh`][gh] command available, you can install the latest release
22-
of `dependabot` using the following command ([gist source](https://gist.github.com/mattt/e09e1ecd76d5573e0517a7622009f06f)):
23-
```shell
24-
gh gist view --raw e09e1ecd76d5573e0517a7622009f06f | bash
25-
```
21+
* On Mac, you can run `brew install dependabot`
2622

2723
## Requirements
2824

cmd/dependabot/internal/cmd/version.go

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
"regexp"
4+
"log"
65
"runtime/debug"
76
)
87

98
// ldflags inserts the version here on release
109
var version string
1110

12-
var timestampRegex = regexp.MustCompile("[^a-zA-Z0-9]+")
13-
1411
func Version() string {
1512
if version == "" {
1613
version = "0.0.0-dev"
17-
commit := ""
18-
timestamp := ""
19-
modified := false
20-
21-
info, _ := debug.ReadBuildInfo()
22-
for _, entry := range info.Settings {
23-
if entry.Key == "vcs.revision" && len(entry.Value) >= 7 {
24-
commit = entry.Value[:7] // short ref
25-
}
2614

27-
if entry.Key == "vcs.modified" {
28-
modified = entry.Value == "true"
29-
}
30-
31-
if entry.Key == "vcs.time" {
32-
timestamp = timestampRegex.ReplaceAllString(entry.Value, "")
33-
}
15+
info, ok := debug.ReadBuildInfo()
16+
if !ok {
17+
log.Println("debug.ReadBuildInfo failed")
18+
return version
3419
}
35-
36-
if modified && timestamp != "" {
37-
return fmt.Sprintf("%s+%s", version, timestamp)
38-
} else if commit != "" {
39-
return fmt.Sprintf("%s+%s", version, commit)
20+
if info.Main.Version != "" {
21+
version = info.Main.Version
4022
}
4123
}
4224

0 commit comments

Comments
 (0)