-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from arborchat/version
Create build script to track version numbers
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/sh | ||
#usage: ./build.sh <options for `go build`> | ||
|
||
# find the directory containing this script | ||
script_dir="$(dirname "$(command -v "$0")")" | ||
|
||
# ensure that git commands are run from within this repository | ||
cd "$script_dir" || exit 1 | ||
|
||
commit="$(git rev-parse HEAD)" | ||
suffix="" | ||
version_file="$(pwd)/version.go" | ||
|
||
# check if git is clean. If not, notify user and taint the build | ||
if ! git diff --exit-code > /dev/null 2>&1 ||\ | ||
! git diff --cached --exit-code > /dev/null 2>&1 ; then | ||
suffix="-modified" | ||
echo "Warning: your current working directory contains unstaged or uncommitted changes. | ||
Building a \"modified\" binary | ||
Run 'git diff && git diff --cached' to see your unmodified changes" | ||
fi | ||
|
||
# write the file and format it | ||
echo "package main; const Version = \"$commit$suffix\"" > "$version_file" | ||
gofmt -s -w "$version_file" | ||
|
||
# show the user | ||
echo "Wrote file $version_file" | ||
|
||
# ensure dependencies are clean | ||
dep ensure | ||
|
||
go build "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
const Version = "go-get (unstable, use ./build.sh instead)" |