Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Added version to app and github release on tag to build script
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Jun 22, 2017
1 parent 09c1edd commit d4c3559
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
4 changes: 4 additions & 0 deletions bookbrowser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var bookdir *string
var tempdir *string
var addr *string

var curversion = "undefined"

func main() {
wd, err := os.Getwd()
if err != nil {
Expand All @@ -44,6 +46,8 @@ func main() {
addr = flag.String("addr", ":8090", "The address to bind to.")
flag.Parse()

log.Printf("BookBrowser %s\n", curversion)

if _, err := os.Stat(*bookdir); err != nil {
if os.IsNotExist(err) {
log.Fatalf("Fatal error: book directory %s does not exist\n", *bookdir)
Expand Down
50 changes: 43 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,52 @@ go get -u -v github.com/nfnt/resize 2>&1 | indent
echo "--> zipfs"
go get -u -v golang.org/x/tools/godoc/vfs/zipfs 2>&1 | indent

echo "--> github-release"
go get -u -v github.com/aktau/github-release 2>&1 | indent

echo
echo "Building"

echo "--> Getting version info"
# Gets current tag, or else previous-tag+commit-hash~dev
APP_VERSION="$(git name-rev --name-only --tags HEAD | sed "s/undefined/$(git describe --abbrev=0 --tags)+$(git rev-parse --short HEAD)-dev/")"
echo "APP_VERSION=$APP_VERSION" | indent
IS_DEV=$(if [[ "$(git name-rev --name-only --tags HEAD)" != "undefine
d" ]];then echo true;else echo false;fi)
echo "IS_DEV=$IS_DEV" | indent

echo "--> Creating build directory"
mkdir -vp build 2>&1 | indent

echo "--> Generating bindata"
go generate

echo "--> Building BookBrowser for Linux 64bit"
env GOOS=linux GOARCH=amd64 go build -o build/BookBrowser-linux-64bit 2>&1 | indent
env GOOS=linux GOARCH=amd64 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-linux-64bit 2>&1 | indent

if [[ "$1" == "all" ]]; then
echo "--> Building BookBrowser for Linux 32bit"
env GOOS=linux GOARCH=386 go build -o build/BookBrowser-linux-32bit 2>&1 | indent
env GOOS=linux GOARCH=386 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-linux-32bit 2>&1 | indent

echo "--> Building BookBrowser for Windows 64bit"
env GOOS=windows GOARCH=amd64 go build -o build/BookBrowser-windows-64bit.exe 2>&1 | indent
env GOOS=windows GOARCH=amd64 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-windows-64bit.exe 2>&1 | indent

echo "--> Building BookBrowser for Windows 32bit"
env GOOS=windows GOARCH=386 go build -o build/BookBrowser-windows-32bit.exe 2>&1 | indent
env GOOS=windows GOARCH=386 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-windows-32bit.exe 2>&1 | indent

echo "--> Building BookBrowser for Darwin 64bit"
env GOOS=darwin GOARCH=amd64 go build -o build/BookBrowser-darwin-64bit 2>&1 | indent
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-darwin-64bit 2>&1 | indent

echo "--> Building BookBrowser for Darwin 32bit"
env GOOS=darwin GOARCH=386 go build -o build/BookBrowser-darwin-32bit 2>&1 | indent
env GOOS=darwin GOARCH=386 go build -ldflags "-X main.curversion=$APP_VERSION" -o build/BookBrowser-$APP_VERSION-darwin-32bit 2>&1 | indent
fi


echo
echo "Generating release notes"

echo "--> Changelog"
echo "## Changes for $(git describe --tags --abbrev=0 HEAD^)" | tee -a build/release-notes.md | indent
echo "## Changes for $APP_VERSION" | tee -a build/release-notes.md | indent
echo "$(git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --oneline)" | tee -a build/release-notes.md | indent
echo "" | tee -a build/release-notes.md | indent
echo "--> Usage"
Expand All @@ -75,6 +86,31 @@ echo "2. Copy it to the directory with your books" | tee -a build/release-notes.
echo "3. Run it" | tee -a build/release-notes.md | indent


if [[ "$IS_DEV" == "false" ]]; then
echo
echo "Publishing GitHub release"

echo "--> Creating release from current tag"
github-release release \
--user geek1011 \
--repo BookBrowser \
--tag $APP_VERSION \
--name "BookBrowser $APP_VERSION" \
--description "$(cat build/release-notes.md)" | indent

echo "--> Uploading files"
for f in build/BookBrowser-*;do
fn="$(basename $f)"
echo "$f > $fn" | indent
github-release upload \
--user geek1011 \
--repo BookBrowser \
--tag $APP_VERSION \
--name "$fn" \
--file "$f" | indent | indent
done
fi

echo

echo "Cleaning up"
Expand Down
3 changes: 2 additions & 1 deletion html.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func pageHTML(title string, content string) string {
html.WriteString(`</div>
<footer class="footer">
<div class="container">
<p class="text-muted"><a href="https://github.com/geek1011/BookBrowser">BookBrowser</a> Copyright 2017 Patrick G</a></p>
<p class="text-muted"><a href="https://github.com/geek1011/BookBrowser">BookBrowser</a> ` + curversion + `</p>
<p class="text-muted">Copyright 2017 <a href="https://geek1011.github.io">Patrick G</a></p>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Expand Down

0 comments on commit d4c3559

Please sign in to comment.