Skip to content

Commit

Permalink
chore: versioning with ldflags (filebrowser#726)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <[email protected]>
  • Loading branch information
hacdias committed May 12, 2019
1 parent d649ae6 commit 7fc4899
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
9 changes: 9 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
4 changes: 3 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package version

const (
var (
// Version is the current File Browser version.
Version = "(untracked)"
// CommitSHA is the commmit sha.
CommitSHA = "(unknown)"
)
22 changes: 3 additions & 19 deletions wizard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () {
Expand Down Expand Up @@ -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."
}

Expand Down

0 comments on commit 7fc4899

Please sign in to comment.