-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,84 @@ | ||
#!/bin/bash | ||
|
||
# Override the pushd and popd commands to make them silent | ||
pushd () { | ||
command pushd "$@" > /dev/null | ||
} | ||
|
||
popd () { | ||
command popd "$@" > /dev/null | ||
} | ||
|
||
[ "$DEBUG" = "1" ] && set -x | ||
set -e | ||
|
||
VERSION="" | ||
|
||
while getopts :v:b OPT; do | ||
version="" | ||
parallel_jobs="-1" | ||
while getopts :v:j: OPT; do | ||
case $OPT in | ||
j) | ||
parallel_jobs=$OPTARG | ||
;; | ||
v) | ||
VERSION=$OPTARG | ||
version=$OPTARG | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z $VERSION ] ; then | ||
if [ -z $version ] ; then | ||
echo "Usage: $0 -v <version>" >&2 | ||
exit 1 | ||
fi | ||
|
||
bin_dir="bin/$VERSION" | ||
mkdir -p $bin_dir | ||
# Move to the directory where lie this script | ||
_cur_dir=$(cd $(dirname $0) && pwd) | ||
cd $_cur_dir | ||
|
||
function build_for() { | ||
local os=$1 | ||
local archive_type=$2 | ||
pushd ${_cur_dir}/../scalingo | ||
|
||
for arch in amd64 arm64 386 ; do | ||
if [ "$os" = "darwin" ] && [ "$arch" = "386" ] ; then | ||
continue | ||
fi | ||
echo "Remove previously compiled binaries" | ||
rm -f ${_cur_dir}/../scalingo/scalingo* | ||
|
||
pushd scalingo | ||
bin_dir="${_cur_dir}/../bin/$version" | ||
|
||
[ -e "./scalingo" ] && rm ./scalingo | ||
[ -e "./scalingo.exe" ] && rm ./scalingo.exe | ||
GOOS=$os GOARCH=$arch go build -ldflags " \ | ||
-X main.buildstamp=$(date -u '+%Y-%m-%d_%I:%M:%S%p') \ | ||
echo "Compiling the binaries for all architectures" | ||
operating_systems="linux freebsd openbsd darwin windows" | ||
architectures="amd64 arm64 386" | ||
ignore_osarch="!darwin/386" | ||
gox -parallel $parallel_jobs -os="${operating_systems}" -arch="${architectures}" -osarch="${ignore_osarch}" \ | ||
-ldflags "-X main.buildstamp=$(date -u '+%Y-%m-%d_%I:%M:%S%p') \ | ||
-X main.githash=$(git rev-parse HEAD) \ | ||
-X main.VERSION=$VERSION" | ||
|
||
release_dir="scalingo_${VERSION}_${os}_${arch}" | ||
archive_dir="$bin_dir/$release_dir" | ||
|
||
popd | ||
mkdir -p $archive_dir | ||
|
||
bin="scalingo/scalingo" | ||
if [ "$os" = "windows" ] ; then | ||
bin="scalingo/scalingo.exe" | ||
fi | ||
cp $bin $archive_dir | ||
cp README.md $archive_dir | ||
cp LICENSE $archive_dir | ||
|
||
pushd $bin_dir | ||
if [ "$archive_type" = "tarball" ] ; then | ||
tar czvf "${release_dir}.tar.gz" "$release_dir" | ||
else | ||
zip "${release_dir}.zip" $(find "${release_dir}") | ||
fi | ||
popd | ||
done | ||
} | ||
-X main.version=$version" | ||
|
||
if uname -a | grep -iq Linux ; then | ||
build_for "linux" "tarball" | ||
build_for "freebsd" | ||
build_for "openbsd" | ||
build_for "darwin" | ||
build_for "windows" | ||
fi | ||
if uname -a | grep -iq Darwin ; then | ||
build_for "darwin" | ||
fi | ||
if uname -a | grep -iq Mingw ; then | ||
build_for "windows" | ||
fi | ||
if uname -a | grep -iq Cygwin ; then | ||
build_for windows | ||
fi | ||
echo "" | ||
echo "Binaries compilation finished, archiving them" | ||
|
||
for binary in ./scalingo*; do | ||
echo "--> Create the archive for $(basename $binary)" | ||
|
||
# binary contains a string like "./scalingo_windows_386.exe" | ||
os=$(basename $binary | cut -d "." -f 1 | cut -d "_" -f 2) | ||
arch=$(basename $binary | cut -d "." -f 1 | cut -d "_" -f 3) | ||
release_dir="scalingo_${version}_${os}_${arch}" | ||
archive_dir="$bin_dir/$release_dir" | ||
mkdir -p $archive_dir | ||
|
||
bin="scalingo" | ||
if [ "$os" = "windows" ] ; then | ||
bin="scalingo.exe" | ||
fi | ||
|
||
mv $binary ${archive_dir}/${bin} | ||
cp ${_cur_dir}/../README.md $archive_dir | ||
cp ${_cur_dir}/../LICENSE $archive_dir | ||
|
||
pushd $bin_dir | ||
if [ "$os" = "linux" ] ; then | ||
tar czf "${release_dir}.tar.gz" "$release_dir" | ||
else | ||
zip "${release_dir}.zip" $(find "${release_dir}") > /dev/null | ||
fi | ||
popd | ||
done | ||
|
||
popd |