Skip to content

Commit

Permalink
cli: Improve version reporting. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Oct 6, 2022
1 parent 507db31 commit f7b38f0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ jobs:
sha256sum: true
project_path: cmd
binary_name: scip
ldflags: "-X 'main.Reproducible=true'"
asset_name: scip-${{ matrix.goos }}-${{ matrix.goarch }}
extra_files: LICENSE
34 changes: 33 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import (
_ "embed"
"fmt"
"log"
"os"
"runtime/debug"
"strings"

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

//go:embed version.txt
var version string

var Reproducible = "" // set by ldflags in CI

func gitSuffix() string {
if Reproducible != "" {
return ""
}
var rev, timestamp string
clean := "true"
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, kv := range buildInfo.Settings {
switch kv.Key {
case "vcs.revision":
rev = kv.Value
case "vcs.time":
timestamp = kv.Value
case "vcs.modified":
if kv.Value == "true" {
clean = "false"
}
}
}
}
return fmt.Sprintf("-dev\nSHA: %s\ntimestamp: %s\nclean: %s", rev, timestamp, clean)
}

func scipApp() *cli.App {
app := &cli.App{
Name: "scip",
Version: "v0.2.1-git",
Version: fmt.Sprintf("v%s%s", strings.TrimSpace(version), gitSuffix()),
Usage: "SCIP Code Intelligence Protocol CLI",
Description: "For more details, see the project README at:\n\n\thttps://github.com/sourcegraph/scip",
Commands: commands(),
Expand Down
4 changes: 4 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/sourcegraph/scip/cmd/tests/reprolang/bindings/go/repro"
)

func TestMain(m *testing.M) {
Reproducible = "true"
}

func TestCLIReferenceInSync(t *testing.T) {
app := scipApp()
readmeBytes, err := os.ReadFile(filepath.Join("..", "docs", "CLI.md"))
Expand Down
1 change: 1 addition & 0 deletions cmd/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2.1

0 comments on commit f7b38f0

Please sign in to comment.