Skip to content

Commit f7b38f0

Browse files
cli: Improve version reporting. (#103)
1 parent 507db31 commit f7b38f0

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ jobs:
2323
sha256sum: true
2424
project_path: cmd
2525
binary_name: scip
26+
ldflags: "-X 'main.Reproducible=true'"
2627
asset_name: scip-${{ matrix.goos }}-${{ matrix.goarch }}
2728
extra_files: LICENSE

cmd/main.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package main
22

33
import (
4+
_ "embed"
5+
"fmt"
46
"log"
57
"os"
8+
"runtime/debug"
9+
"strings"
610

711
"github.com/urfave/cli/v2"
812
)
@@ -23,10 +27,38 @@ func commands() []*cli.Command {
2327
return []*cli.Command{&convert, &lint, &print, &snapshot, &stats}
2428
}
2529

30+
//go:embed version.txt
31+
var version string
32+
33+
var Reproducible = "" // set by ldflags in CI
34+
35+
func gitSuffix() string {
36+
if Reproducible != "" {
37+
return ""
38+
}
39+
var rev, timestamp string
40+
clean := "true"
41+
if buildInfo, ok := debug.ReadBuildInfo(); ok {
42+
for _, kv := range buildInfo.Settings {
43+
switch kv.Key {
44+
case "vcs.revision":
45+
rev = kv.Value
46+
case "vcs.time":
47+
timestamp = kv.Value
48+
case "vcs.modified":
49+
if kv.Value == "true" {
50+
clean = "false"
51+
}
52+
}
53+
}
54+
}
55+
return fmt.Sprintf("-dev\nSHA: %s\ntimestamp: %s\nclean: %s", rev, timestamp, clean)
56+
}
57+
2658
func scipApp() *cli.App {
2759
app := &cli.App{
2860
Name: "scip",
29-
Version: "v0.2.1-git",
61+
Version: fmt.Sprintf("v%s%s", strings.TrimSpace(version), gitSuffix()),
3062
Usage: "SCIP Code Intelligence Protocol CLI",
3163
Description: "For more details, see the project README at:\n\n\thttps://github.com/sourcegraph/scip",
3264
Commands: commands(),

cmd/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
"github.com/sourcegraph/scip/cmd/tests/reprolang/bindings/go/repro"
2020
)
2121

22+
func TestMain(m *testing.M) {
23+
Reproducible = "true"
24+
}
25+
2226
func TestCLIReferenceInSync(t *testing.T) {
2327
app := scipApp()
2428
readmeBytes, err := os.ReadFile(filepath.Join("..", "docs", "CLI.md"))

cmd/version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.2.1

0 commit comments

Comments
 (0)