chore: versioning with ldflags (#726)

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Henrique Dias 2019-05-12 21:08:43 +01:00 committed by GitHub
parent d649ae6ff7
commit 7fc4899507
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 21 deletions

View File

@ -1,8 +1,17 @@
project_name: filebrowser project_name: filebrowser
env:
- GO111MODULE=on
before:
hooks:
- go mod download
build: build:
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
ldflags:
- -s -w -X github.com/filebrowser/filebrowser/v2/version.Version={{ .Version }} -X github.com/filebrowser/filebrowser/v2/version.CommitSHA={{ .ShortCommit }}
main: main.go main: main.go
binary: filebrowser binary: filebrowser
goos: goos:

View File

@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Print the version number", Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("File Browser Version " + version.Version) fmt.Println("File Browser v" + version.Version + "/" + version.CommitSHA)
}, },
} }

View File

@ -1,6 +1,8 @@
package version package version
const ( var (
// Version is the current File Browser version. // Version is the current File Browser version.
Version = "(untracked)" Version = "(untracked)"
// CommitSHA is the commmit sha.
CommitSHA = "(unknown)"
) )

View File

@ -16,14 +16,6 @@ debugInfo () {
echo "Release: $RELEASE" echo "Release: $RELEASE"
} }
updateVersion () {
from=$1
to=$2
echo "🎁 Updating version from \"$from\" to \"$to\""
sed -i.bak "s|$from|$to|g" $REPO/version/version.go
}
buildAssets () { buildAssets () {
cd $REPO cd $REPO
rm -rf frontend/dist rm -rf frontend/dist
@ -50,9 +42,7 @@ buildBinary () {
rice embed-go rice embed-go
cd $REPO cd $REPO
updateVersion $untracked "($COMMIT_SHA)" go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA"
go build -a -o filebrowser
updateVersion "($COMMIT_SHA)" $untracked
} }
release () { release () {
@ -90,18 +80,12 @@ release () {
cd .. cd ..
echo "🐑 Updating submodule ref to $semver" echo "🐑 Creating a new commit for the new release"
updateVersion $untracked $1 git commit --allow-empty -am "chore: version $semver"
git commit -am "chore: version $semver"
git tag "$1" git tag "$1"
git push git push
git push --tags origin git push --tags origin
echo "🐑 Commiting untracked version notice..."
updateVersion $1 $untracked
git commit -am "chore: setting untracked version [ci skip]"
git push
echo "📦 Done! $semver released." echo "📦 Done! $semver released."
} }