Skip to content

Commit

Permalink
Merge pull request #85 from arborchat/version
Browse files Browse the repository at this point in the history
Create build script to track version numbers
  • Loading branch information
whereswaldon authored Jan 22, 2019
2 parents b975ab0 + 0d78320 commit 10ffa67
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ The best way to install Muscadine is to head over to our [Releases](https://gith

## Build

If you'd like to build Muscadine, make sure you have Go installed. Then run:
If you'd like to build Muscadine, make sure you have [Go](https://golang.org/) and [dep](https://github.com/golang/dep) installed. Clone this repository, then run:

```
go get -u github.com/arborchat/muscadine
cd muscadine
./build.sh
```

## Use
Expand Down
2 changes: 1 addition & 1 deletion build-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for os in darwin linux windows openbsd; do
for arch in ${arch_for_os["$os"]}; do
archive_name="$project-$os-$arch.tar.gz"
echo "Building $project for $os on $arch"
env GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 go build -o "$bin_name" &&\
env GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 ./build.sh -o "$bin_name" &&\
tar czf "$archive_name" "$bin_name" &&\
rm "$bin_name"
echo "Adding $archive_name to release $tag"
Expand Down
33 changes: 33 additions & 0 deletions build.sh
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 "$@"
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"

"log"
"os"
"os/user"
Expand Down Expand Up @@ -70,11 +71,17 @@ func main() {
username string
histfile, logfile string
histfileTemplate = getDefaultHistFileTemplate()
version bool
)
flag.StringVar(&username, "username", "muscadine", "Set your username on the server")
flag.StringVar(&histfile, "histfile", histfileTemplate, "Load/Store history in this file")
flag.StringVar(&logfile, "logfile", getDefaultLogFile(), "Write logs to this file")
flag.BoolVar(&version, "version", false, "Print version number and exit")
flag.Parse()
if version {
fmt.Printf("Muscadine %s\n", Version)
return
}
if len(flag.Args()) < 1 {
log.Fatal("Usage: " + os.Args[0] + " <ip>:<port>")
}
Expand Down
3 changes: 3 additions & 0 deletions version.go
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)"

0 comments on commit 10ffa67

Please sign in to comment.