Skip to content

Commit

Permalink
mk-version-fix: Version and Makefile fixes.
Browse files Browse the repository at this point in the history
* Deleted git hash from version.
* Added `make OUTPUT=. build` target.
  • Loading branch information
Evgeny Khabarov authored and ekhabarov committed Nov 13, 2019
1 parent 8ef4846 commit d8bdfa6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
VERSION=1.0.1-dev
BUILDTIME=$(shell date +"%Y-%m-%dT%T%z")
LDFLAGS= -ldflags '-X github.com/bold-commerce/protoc-gen-struct-transformer/generator.version=$(VERSION) -X github.com/bold-commerce/protoc-gen-struct-transformer/generator.buildTime=$(BUILDTIME)'

.PHONY: re-generate-example
re-generate-example:
protoc \
Expand All @@ -13,8 +17,9 @@ imports:
.PHONY: generate
generate: re-generate-example imports

install: VERSION=1.0.0-dev
install: SHA1=$(shell git rev-parse --short HEAD)
install: BUILDTIME=$(shell date +"%Y-%m-%d_%H:%M:%S")
install:
go install -ldflags '-X github.com/bold-commerce/protoc-gen-struct-transformer/generator.gitHash=$(SHA1) -X github.com/bold-commerce/protoc-gen-struct-transformer/generator.version=$(VERSION) -X github.com/bold-commerce/protoc-gen-struct-transformer/generator.buildTime=$(BUILDTIME)'
go install $(LDFLAGS)

build: OUTPUT=.
build:
go build $(LDFLAGS) -o $(OUTPUT)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/bold-commerce/protoc-gen-struct-transformer?sort=semver)](https://github.com/bold-commerce/protoc-gen-struct-transformer/releases)
[![BSD-3-Clause](https://img.shields.io/github/license/bold-commerce/protoc-gen-struct-transformer)](./LICENSE)

<!-- vim-markdown-toc GitHub -->
<!-- vim-markdown-toc GFM -->

* [Quick presentation](#quick-presentation)
* [Overview](#overview)
Expand Down
7 changes: 3 additions & 4 deletions generator/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import (

var (
// header is a header for each generated files.
header = "// Code generated by protoc-gen-struct-transformer, version: %s.%s. DO NOT EDIT.\n"
header = "// Code generated by protoc-gen-struct-transformer, version: %s. DO NOT EDIT.\n"

// Next three variables are set by "make install" command and are used as
// version information. See Makefile for details.
version = "<dev>"
buildTime = "<build_time>"
gitHash = "sha1"
)

// WriteStringer exposes two methods:
Expand All @@ -35,12 +34,12 @@ type WriteStringer interface {

// Version returns current generator version.
func Version() string {
return fmt.Sprintf("version: %s.%s\nbuild-time: %s\n", version, gitHash, buildTime)
return fmt.Sprintf("version: %s\nbuild-time: %s\n", version, buildTime)
}

// output initializes io.Writer with information about current version.
func output() WriteStringer {
return bytes.NewBufferString(fmt.Sprintf(header, version, gitHash))
return bytes.NewBufferString(fmt.Sprintf(header, version))
}

// fileHeader adds source file/package info into initialized header.
Expand Down
10 changes: 4 additions & 6 deletions generator/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ var _ = Describe("File", func() {
BeforeEach(func() {
version = "v0.0.1"
buildTime = time.Date(2019, time.March, 1, 5, 34, 19, 0, time.UTC).Format(time.RFC3339)
gitHash = "aabbcc"
})

It("returns version header", func() {
v := Version()
Expect(v).To(Equal("version: v0.0.1.aabbcc\nbuild-time: 2019-03-01T05:34:19Z\n"))
Expect(v).To(Equal("version: v0.0.1\nbuild-time: 2019-03-01T05:34:19Z\n"))
})

It("return WriteStringer with header", func() {
o := output()
Expect(o.String()).To(Equal("// Code generated by protoc-gen-struct-transformer, version: v0.0.1.aabbcc. DO NOT EDIT.\n"))
Expect(o.String()).To(Equal("// Code generated by protoc-gen-struct-transformer, version: v0.0.1. DO NOT EDIT.\n"))
})
})
})
Expand Down Expand Up @@ -197,21 +196,20 @@ var _ = Describe("File", func() {

BeforeEach(func() {
version = "v1.0.0"
gitHash = "ddffhh"
})

DescribeTable("check results",
func(f, p, d, expected string) {
ws := fileHeader(f, p, d)
Expect(ws.String()).To(Equal(expected))
},
Entry("case 1", "srcfile", "srcpackage", "dstpackage", `// Code generated by protoc-gen-struct-transformer, version: v1.0.0.ddffhh. DO NOT EDIT.
Entry("case 1", "srcfile", "srcpackage", "dstpackage", `// Code generated by protoc-gen-struct-transformer, version: v1.0.0. DO NOT EDIT.
// source file: srcfile
// source package: srcpackage
package dstpackage
`),
Entry("case 2", "abc", "cde", "fff", `// Code generated by protoc-gen-struct-transformer, version: v1.0.0.ddffhh. DO NOT EDIT.
Entry("case 2", "abc", "cde", "fff", `// Code generated by protoc-gen-struct-transformer, version: v1.0.0. DO NOT EDIT.
// source file: abc
// source package: cde
Expand Down
3 changes: 1 addition & 2 deletions generator/oneof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ var _ = Describe("Oneof", func() {
BeforeEach(func() {
version = "v1.1.1"
buildTime = time.Date(2019, time.March, 1, 5, 34, 19, 0, time.UTC).Format(time.RFC3339)
gitHash = "ccddee"
})

DescribeTable("OptHelpers",
Expand Down Expand Up @@ -173,7 +172,7 @@ func SecondGo2protoToSecondProto2go(s string, dst *dst_pref.SecondProto2go, v st
`

headerOne = `// Code generated by protoc-gen-struct-transformer, version: v1.1.1.ccddee. DO NOT EDIT.
headerOne = `// Code generated by protoc-gen-struct-transformer, version: v1.1.1. DO NOT EDIT.
package one
var version string
Expand Down

0 comments on commit d8bdfa6

Please sign in to comment.