Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autogenerate Version on build #190

Merged
merged 11 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ BINDATA := $(shell find conf | sed 's/ /\\ /g')
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
JAVASCRIPTS :=

LDFLAGS += -X "code.gitea.io/gitea/modules/setting.BuildTime=$(DATE)"
LDFLAGS += -X "code.gitea.io/gitea/modules/setting.BuildGitHash=$(SHA)"
VERSION = $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking, you should be able to group the sed calls: sed 's/^v//;s/-/+/'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strk that depends entirely on the version of sed unfortunately... FreeBSD for example doesn't handle that 😒

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep it like it is. The v replacement can even be done with plain bash ;)


LDFLAGS += -X "main.Version=$(VERSION)"

TARGETS ?= linux/*,darwin/*,windows/*
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
Expand Down Expand Up @@ -84,11 +85,15 @@ install: $(wildcard *.go)
go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'

.PHONY: build
build: $(EXECUTABLE)
build: $(EXECUTABLE) templates/.VERSION

$(EXECUTABLE): $(wildcard *.go)
go build -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@

.PHONY: templates/.VERSION
templates/.VERSION:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should drop this version file. People that build from source should update the templates on their own.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was leaving that to your PR (#74) so you wouldn't get conflicts 😛

echo -n $(VERSION) > $@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should change this to echo $(VERSION) > $@?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it should be without \n, otherwise the version-check fails...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run make build on MacOS 10.12.1

code.gitea.io/gitea/cmd
code.gitea.io/gitea
echo -n 0.9.99+418-g399b0f7 > templates/.VERSION
➜  gitea git:(91-auto-build-version) ✗ more templates/.VERSION
-n 0.9.99+418-g399b0f7
➜  gitea git:(91-auto-build-version) ✗

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should anyway trim the result within the version check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the HELL apple, stop fucking around with my flags! 😆

I'll trim it instead... maybe I should drop it? I think that @tboerger PR for removing it is merged no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can drop it and wait until he's PR merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkcsoft, just drop it. I think this could be merged.


.PHONY: release
release: release-build release-copy release-check

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// Version holds the current Gitea version
const Version = "0.9.99.0915"
var Version = "1.0.0+dev"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Var Version = "0.9.0+dev" is better. So that if user go get then the version is shown it's a dev version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can either generate it, OR set it, otherwise generating it is pointless

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I do in other projects is always set the target version for each branch (ie: <next version>-alpha) and then separately and optionally append a changeset identifier which is generated on "make". As Go doesn't let us autogenerate things such setup would result in <next version>-alpha resulting in go obtained builds and <next version>-alpha+<metadata> resulting from builds via make.


func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
9 changes: 0 additions & 9 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ const (

// settings
var (
// BuildTime information should only be set by -ldflags.
BuildTime string
BuildGitHash string

// AppVer settings
AppVer string
AppName string
Expand Down Expand Up @@ -642,11 +638,6 @@ var logLevels = map[string]string{
func newLogService() {
log.Info("%s %s", AppName, AppVer)

if len(BuildTime) > 0 {
log.Info("Build Time: %s", BuildTime)
log.Info("Build Git Hash: %s", BuildGitHash)
}

// Get and check log mode.
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
LogConfigs = make([]string, len(LogModes))
Expand Down
2 changes: 1 addition & 1 deletion templates/.VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.99.0915
1.0.0+dev