Skip to content

Commit

Permalink
Merge pull request #3 from ktock/version
Browse files Browse the repository at this point in the history
Add version command
  • Loading branch information
ktock committed May 9, 2022
2 parents 0128528 + f35a4cf commit d97d86d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ CMD_DESTDIR ?= /usr/local
PREFIX ?= $(CURDIR)/out/
CMD=buildg

PKG=github.com/ktock/buildg
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
GO_LD_FLAGS=-ldflags '-s -w -X $(PKG)/pkg/version.Version=$(VERSION) -X $(PKG)/pkg/version.Revision=$(REVISION) $(GO_EXTRA_LDFLAGS)'

all: build

build: buildg

buildg:
go build -o $(PREFIX)/buildg -v .
go build -o $(PREFIX)/buildg $(GO_LD_FLAGS) -v .

install:
install -D -m 755 $(PREFIX)/buildg $(CMD_DESTDIR)/bin
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ USAGE:

COMMANDS:
debug Debug a build
version Version info
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
Expand All @@ -166,7 +167,7 @@ GLOBAL OPTIONS:

### buildg debug

```
```console
$ buildg debug --help
NAME:
buildg debug - Debug a build
Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/pkg/userns"
"github.com/containerd/containerd/snapshots/native"
"github.com/ktock/buildg/pkg/version"
"github.com/moby/buildkit/cache/remotecache"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/cmd/buildctl/build"
Expand Down Expand Up @@ -51,6 +52,7 @@ func main() {
}
app.Commands = []cli.Command{
newDebugCommand(),
newVersionCommand(),
}
app.Before = func(context *cli.Context) error {
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
Expand All @@ -65,6 +67,17 @@ func main() {
}
}

func newVersionCommand() cli.Command {
return cli.Command{
Name: "version",
Usage: "Version info",
Action: func(clicontext *cli.Context) error {
fmt.Println("buildg", version.Version, version.Revision)
return nil
},
}
}

func newDebugCommand() cli.Command {
var flags []cli.Flag
if userns.RunningInUserNS() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package version

var (
// Version is the version number. Filled in at linking time (via Makefile).
Version = "<unknown>"

// Revision is the VCS (e.g. git) revision. Filled in at linking time (via Makefile).
Revision = "<unknown>"
)

0 comments on commit d97d86d

Please sign in to comment.