Skip to content

Commit

Permalink
Merge pull request #35 from hairyhenderson/auto-version
Browse files Browse the repository at this point in the history
Setting the version at build time from the latest tag
  • Loading branch information
hairyhenderson committed Apr 11, 2016
2 parents f1110c3 + 5ed20e4 commit adaf2c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ GO := go
PKG_NAME := gomplate
PREFIX := .

COMMIT_FLAG := -X `go list ./version`.GitCommit=`git rev-parse --short HEAD 2>/dev/null`
VERSION_FLAG := -X `go list ./version`.Version=`git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null | sed 's/v\(.*\)/\1/'`

define gocross
GOOS=$(1) GOARCH=$(2) \
$(GO) build \
Expand All @@ -21,7 +24,7 @@ build-x: $(shell find . -type f -name '*.go')
$(call gocross,windows,386)

$(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(shell find . -type f -name '*.go')
$(GO) build -o $@
$(GO) build -ldflags "$(COMMIT_FLAG) $(VERSION_FLAG)" -o $@

build: $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS))

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,10 @@ _Note:_ it's important for the `if`/`else`/`end` keywords to appear on the same

Right now the release process is semi-automatic.

1. Update the Version `const` in `main.go`
2. Create a release tag: `git tag -a v0.0.9 -m "Releasing v0.9.9"`
3. Build binaries: `make build-x`
4. _(optional)_ compress the binaries with `upx` (may not work for all architectures)
5. Create a release in [github](https://github.com/hairyhenderson/gomplate/releases)!
1. Create a release tag: `git tag -a v0.0.9 -m "Releasing v0.9.9"`
2. Build binaries: `make build-x`
3. _(optional)_ compress the binaries with `upx` (may not work for all architectures)
4. Create a release in [github](https://github.com/hairyhenderson/gomplate/releases)!

## License

Expand Down
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import (
"os"

"github.com/hairyhenderson/gomplate/aws"
"github.com/hairyhenderson/gomplate/version"

"text/template"
)

// version
const Version = "0.2.2"

func init() {
ver := flag.Bool("v", false, "Print version and exit")
flag.Parse()
if *ver {
fmt.Println(Version)
fmt.Println(version.Version)
os.Exit(0)
}
}
Expand Down
8 changes: 8 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package version

var (
// Version will be overwritten automatically by the build
Version = "0.0.0"
// GitCommit will be overwritten automatically by the build
GitCommit = "HEAD"
)

0 comments on commit adaf2c8

Please sign in to comment.