Skip to content

Commit

Permalink
Update release scripts
Browse files Browse the repository at this point in the history
- Move scripts into _release folder
- Include crosscrompile script
- Minor adjustments
  • Loading branch information
prasmussen committed Jul 18, 2015
1 parent 72cfaf1 commit 2cf9d76
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ignore bin folder and drive binary
bin/
_release/bin
drive

# vim files
Expand Down
19 changes: 8 additions & 11 deletions build-all.sh → _release/build-all.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Usage: $0 <app>"
exit 1
fi

# Load crosscompile environment
source /Users/pii/scripts/golang-crosscompile/crosscompile.bash
source _release/crosscompile.bash

APP_NAME="drive"
PLATFORMS="darwin/386 darwin/amd64 freebsd/386 freebsd/amd64 linux/386 linux/amd64 linux/arm linux/rpi windows/386 windows/amd64"
APP_NAME=$1
BIN_PATH="_release/bin"

# Remove old binaries
rm bin/*
# Initialize bin dir
mkdir -p $BIN_PATH
rm $BIN_PATH/*


# Build binary for each platform in parallel
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
BIN_NAME="${APP_NAME}-$GOOS-$GOARCH"
BIN_NAME="${APP_NAME}-${GOOS/darwin/osx}-${GOARCH/amd64/x64}"

if [ $GOOS == "windows" ]; then
BIN_NAME="${BIN_NAME}.exe"
Expand All @@ -33,7 +30,7 @@ for PLATFORM in $PLATFORMS; do
unset GOARM
fi

BUILD_CMD="go-${GOOS}-${GOARCH} build -ldflags "-w" -o bin/${BIN_NAME} $APP_NAME.go"
BUILD_CMD="go-${GOOS}-${GOARCH} build -ldflags '-w' -o ${BIN_PATH}/${BIN_NAME} $APP_NAME.go"

echo "Building $BIN_NAME"
$BUILD_CMD &
Expand Down
73 changes: 73 additions & 0 deletions _release/crosscompile.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# support functions for go cross compilation

type setopt >/dev/null 2>&1 && setopt shwordsplit
PLATFORMS="darwin/386 darwin/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm windows/386 windows/amd64 openbsd/386 openbsd/amd64"

function go-alias {
GOOS=${1%/*}
GOARCH=${1#*/}
eval "function go-${GOOS}-${GOARCH} { ( GOOS=${GOOS} GOARCH=${GOARCH} go \"\$@\" ) }"
}

function go-crosscompile-build {
GOOS=${1%/*}
GOARCH=${1#*/}
cd $(go env GOROOT)/src ; GOOS=${GOOS} GOARCH=${GOARCH} ./make.bash --no-clean 2>&1
}

function go-crosscompile-build-all {
FAILURES=""
for PLATFORM in $PLATFORMS; do
CMD="go-crosscompile-build ${PLATFORM}"
echo "$CMD"
$CMD || FAILURES="$FAILURES $PLATFORM"
done
if [ "$FAILURES" != "" ]; then
echo "*** go-crosscompile-build-all FAILED on $FAILURES ***"
return 1
fi
}

function go-all {
FAILURES=""
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
CMD="go-${GOOS}-${GOARCH} $@"
echo "$CMD"
$CMD || FAILURES="$FAILURES $PLATFORM"
done
if [ "$FAILURES" != "" ]; then
echo "*** go-all FAILED on $FAILURES ***"
return 1
fi
}

function go-build-all {
FAILURES=""
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
SRCFILENAME=`echo $@ | sed 's/\.go//'`
CURDIRNAME=${PWD##*/}
OUTPUT=${SRCFILENAME:-$CURDIRNAME} # if no src file given, use current dir name
CMD="go-${GOOS}-${GOARCH} build -o $OUTPUT-${GOOS}-${GOARCH} $@"
echo "$CMD"
$CMD || FAILURES="$FAILURES $PLATFORM"
done
if [ "$FAILURES" != "" ]; then
echo "*** go-build-all FAILED on $FAILURES ***"
return 1
fi
}

for PLATFORM in $PLATFORMS; do
go-alias $PLATFORM
done

unset -f go-alias
4 changes: 2 additions & 2 deletions upload.sh → _release/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ HEADER='### Downloads'
ROW_TEMPLATE='- [{{name}}]({{url}})'

# Grab application version
VERSION=$(bin/drive-darwin-amd64 --version | awk '{print $2}' | sed -e 's/v//')
VERSION=$(_release/bin/drive-osx-x64 --version | awk '{print $2}' | sed -e 's/v//')

# Print markdown header
echo "$HEADER"

for bin_path in bin/drive-*; do
for bin_path in _release/bin/drive-*; do
# Upload file
URL=$(drive upload --file $bin_path --share | awk '/https/ {print $9}')

Expand Down

0 comments on commit 2cf9d76

Please sign in to comment.