Skip to content

Commit

Permalink
feat(make-release): use gox
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneM committed Jul 22, 2022
1 parent 5a48e33 commit b473787
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### To be Released

* feat(make-release): use gox [#747](https://github.com/Scalingo/cli/pull/747)
* feat(logs): possibility to get the addon logs by using its type (e.g. Redis) [#745](https://github.com/Scalingo/cli/pull/745)
* fix(error): interpret raw newline [#744](https://github.com/Scalingo/cli/pull/744)
* fix(stats): display memory as IEC size [#742](https://github.com/Scalingo/cli/pull/742)
Expand Down
123 changes: 63 additions & 60 deletions dists/make-release.sh
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

0 comments on commit b473787

Please sign in to comment.