Skip to content

Commit c149fb5

Browse files
authored
use new build version feature (#397)
* use new build version feature * add a version test * fix path issue * there is no path issue, output go version * show me the output! * fix detached head state? * more debugging * more debugging * make it work in CI * make it work in CI
1 parent c6d4783 commit c149fb5

File tree

5 files changed

+16
-33
lines changed

5 files changed

+16
-33
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
go-version-file: go.mod
1919

2020
- name: Build
21-
run: go build -v ./...
21+
run: go version && go build -v ./...
2222

2323
- name: Test
2424
# -count=2 ensures that test fixtures cleanup after themselves

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/dependabot_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestDependabot(t *testing.T) {
15-
err := exec.Command("go", "build", "dependabot.go").Run()
15+
err := exec.Command("go", "build", ".").Run()
1616
if err != nil {
1717
t.Fatal("failed to build dependabot")
1818
}
@@ -24,7 +24,7 @@ func TestDependabot(t *testing.T) {
2424
engine := &script.Engine{
2525
Conds: scripttest.DefaultConds(),
2626
Cmds: Commands(),
27-
Quiet: !testing.Verbose(),
27+
Quiet: false,
2828
}
2929
env := []string{
3030
"PATH=" + os.Getenv("PATH"),

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

testdata/scripts/version.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Run the dependabot command
2+
dependabot --version
3+
4+
# example: dependabot version v1.57.1-0.20250218140044-2f3fdc69ebfd
5+
stdout 'dependabot version v\d+.\d+.\d+-(\d+\.)?\d{14}-[a-f0-9]{12}'

0 commit comments

Comments
 (0)