Skip to content

resolved #91: automatically generate gitea version #101

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

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

Choose a reason for hiding this comment

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

I would set that to var Version = "0.0.0+master"

Copy link
Member

Choose a reason for hiding this comment

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

This should still be const, since it shouldn't be changed at runtime

Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly you can not manipulate const from outside? Need to confirm that.

Copy link
Member Author

Choose a reason for hiding this comment

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

A const can not be set via go build flag.


func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
33 changes: 33 additions & 0 deletions make.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Copyright 2016 The Gitea Authors. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.

version="unknow"

if [ -f VERSION ]; then
version=$(cat VERSION)
go build -ldflags "-w -s -X main.Version=${version}"
exit 0
fi

version=$(git rev-parse --git-dir)
if [ "$version" != ".git" ]; then
echo "no VERSION found and not a git project"
exit 1
fi

version=$(git rev-parse --abbrev-ref HEAD)
tag=$(git describe --tag --always)

if [ "$version" != "HEAD" ]; then
if [ "$version" == "master" ]; then
go build -ldflags "-X main.Version=tip+${tag}"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of tip as a "version"

else
go build -ldflags "-X main.Version=${version}+${tag}"
fi
exit 0
else
go build -ldflags "-X main.Version=${tag}"
fi