Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ Use any of the following for a pain-free installation:
```
The benefit of this method is that re-running the command will always update to the latest version.
* You can download a pre-built binary from the [releases] page.
* If you have the [`gh`][gh] command available, you can install the latest release
of `dependabot` using the following command ([gist source](https://gist.github.com/mattt/e09e1ecd76d5573e0517a7622009f06f)):
```shell
gh gist view --raw e09e1ecd76d5573e0517a7622009f06f | bash
```
* On Mac, you can run `brew install dependabot`

## Requirements

Expand Down
32 changes: 7 additions & 25 deletions cmd/dependabot/internal/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
package cmd

import (
"fmt"
"regexp"
"log"
"runtime/debug"
)

// ldflags inserts the version here on release
var version string

var timestampRegex = regexp.MustCompile("[^a-zA-Z0-9]+")

func Version() string {
if version == "" {
version = "0.0.0-dev"
commit := ""
timestamp := ""
modified := false

info, _ := debug.ReadBuildInfo()
for _, entry := range info.Settings {
if entry.Key == "vcs.revision" && len(entry.Value) >= 7 {
commit = entry.Value[:7] // short ref
}

if entry.Key == "vcs.modified" {
modified = entry.Value == "true"
}

if entry.Key == "vcs.time" {
timestamp = timestampRegex.ReplaceAllString(entry.Value, "")
}
info, ok := debug.ReadBuildInfo()
if !ok {
log.Println("debug.ReadBuildInfo failed")
return version
}

if modified && timestamp != "" {
return fmt.Sprintf("%s+%s", version, timestamp)
} else if commit != "" {
return fmt.Sprintf("%s+%s", version, commit)
if info.Main.Version != "" {
version = info.Main.Version
}
}

Expand Down
Loading