From 7fc4899507de546c4200c70977572186ca44de88 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 12 May 2019 21:08:43 +0100 Subject: [PATCH] chore: versioning with ldflags (#726) License: MIT Signed-off-by: Henrique Dias --- .goreleaser.yml | 9 +++++++++ cmd/version.go | 2 +- version/version.go | 4 +++- wizard.sh | 22 +++------------------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 59b82638..18b70feb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,8 +1,17 @@ project_name: filebrowser +env: + - GO111MODULE=on + +before: + hooks: + - go mod download + build: env: - 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 binary: filebrowser goos: diff --git a/cmd/version.go b/cmd/version.go index b23b928f..cec5a415 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("File Browser Version " + version.Version) + fmt.Println("File Browser v" + version.Version + "/" + version.CommitSHA) }, } diff --git a/version/version.go b/version/version.go index e9ae924e..0564cd57 100644 --- a/version/version.go +++ b/version/version.go @@ -1,6 +1,8 @@ package version -const ( +var ( // Version is the current File Browser version. Version = "(untracked)" + // CommitSHA is the commmit sha. + CommitSHA = "(unknown)" ) diff --git a/wizard.sh b/wizard.sh index 2558dfac..393d914b 100755 --- a/wizard.sh +++ b/wizard.sh @@ -16,14 +16,6 @@ debugInfo () { 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 () { cd $REPO rm -rf frontend/dist @@ -50,9 +42,7 @@ buildBinary () { rice embed-go cd $REPO - updateVersion $untracked "($COMMIT_SHA)" - go build -a -o filebrowser - updateVersion "($COMMIT_SHA)" $untracked + go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA" } release () { @@ -90,18 +80,12 @@ release () { cd .. - echo "🐑 Updating submodule ref to $semver" - updateVersion $untracked $1 - git commit -am "chore: version $semver" + echo "🐑 Creating a new commit for the new release" + git commit --allow-empty -am "chore: version $semver" git tag "$1" git push 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." }