Skip to content

Commit

Permalink
Merge pull request #248 from bzz/fix-release-247
Browse files Browse the repository at this point in the history
HotFix build date parsing
  • Loading branch information
bzz authored Feb 7, 2019
2 parents 2e8884b + 10c779a commit 1c851f1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ifneq ($(origin TRAVIS_TAG), undefined)
endif

# Build
LDFLAGS = -X main.version=$(VERSION) -X main.build="$(BUILD)"
LDFLAGS = -X main.version=$(VERSION) -X main.build=$(BUILD)

# Docker
DOCKER_CMD = docker
Expand Down Expand Up @@ -176,7 +176,7 @@ $(COMMANDS):
echo ; \
echo "$${os} - $@"; \
GOOS=$${os} GOARCH=$${arch} $(GO_BUILD) $$([ $${os} = "linux" ] && echo -tags ostree) \
--ldflags '$(LDFLAGS)' \
--ldflags "$(LDFLAGS)" \
-o "$(BUILD_PATH)/$@_$${os}_$${arch}/$@" \
$(CMD_PATH)/$@/main.go; \
cd $(BUILD_PATH); \
Expand Down
19 changes: 15 additions & 4 deletions cmd/bblfshd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import (
"gopkg.in/bblfsh/sdk.v2/driver/manifest/discovery"
)

const (
defaultBuild = "undefined"
buildDateFormat = "2006-01-02T15:04:05-0700"
)

var (
version = "undefined"
build = "undefined"
build = defaultBuild

network *string
address *string
Expand Down Expand Up @@ -115,10 +120,16 @@ func main() {
os.Exit(1)
}

parsedBuild, err := time.Parse("2006-01-02T15:04:05-0700", build)
parsedBuild, err := time.Parse(buildDateFormat, build)
if err != nil {
logrus.Errorf("wrong date format for build: %s", err)
os.Exit(1)
if build == defaultBuild {
parsedBuild = time.Now()
logrus.Infof("using start time instead in this dev build: %s",
parsedBuild.Format(buildDateFormat))
} else {
logrus.Errorf("wrong date format for this build: %s", err)
os.Exit(1)
}
}
d := daemon.NewDaemon(version, parsedBuild, r, grpcOpts...)
if args := cmd.Args(); len(args) == 2 && args[0] == "install" && args[1] == "recommended" {
Expand Down
8 changes: 5 additions & 3 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/bblfsh/bblfshd/runtime"
)

// actual date format used in bblfshd is different
const testBuildDate = "2019-01-28T16:49:06+01:00"

func TestDaemonState(t *testing.T) {
require := require.New(t)

Expand Down Expand Up @@ -121,9 +124,8 @@ func buildMockedDaemon(t *testing.T, images ...runtime.DriverImage) (*Daemon, st
}
}

bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00")
require.NoError(err)
d := NewDaemon("foo", bdate, r)
parsedBuild, err := time.Parse(time.RFC3339, testBuildDate)
d := NewDaemon("foo", parsedBuild, r)

dp := NewDriverPool(func() (Driver, error) {
return newEchoDriver(), nil
Expand Down
2 changes: 1 addition & 1 deletion daemon/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestServiceVersion(t *testing.T) {
require.Len(resp.Errors, 0)
require.Equal(resp.Version, "foo")

bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00")
bdate, err := time.Parse(time.RFC3339, testBuildDate)
require.NoError(err)
require.Equal(resp.Build, bdate)
}
Expand Down

0 comments on commit 1c851f1

Please sign in to comment.